Python: Relax Agent Invocation Methods to Allow Positional or Keyword Arguments for messages
#12248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This PR relaxes the API signatures of all agent invocation methods (
get_response
,invoke
,invoke_stream
) by changing themessages
parameter from keyword-only to positional-or-keyword. This enhances ergonomics and Pythonic usability by allowing callers to pass messages either positionally or as a keyword argument:With our current use of **kwargs, it is possible to explicitly pass None for messages (like
agent.get_response(messages=None)
). However, this does not feel idiomatic in Python. If a caller wishes to invoke the agent on an existing thread (which already contains all relevant context), it is more natural and Pythonic to simply write:This change makes the API more user-friendly, and removes unnecessary verbosity when no new messages need to be provided.
Impact
Documentation and usage examples will be updated to reflect the improved invocation style.
Description
Relaxes the API signatures of all agent invocation methods.
Contribution Checklist