-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: backwards-compatible create_message overloads for SEP-1577 #1713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduce method overloading for create_message to preserve backwards compatibility while supporting the new tools feature from SEP-1577. When called without tools, create_message returns CreateMessageResult with single content (backwards compatible). When called with tools, it returns CreateMessageResultWithTools which allows array content. This allows existing code that doesn't use tools to continue working without any changes, while new code using tools gets the appropriate type that handles array content. Changes: - Add SamplingContent type alias for basic content types (no tool use) - Add CreateMessageResultWithTools for tool-enabled responses - Add @overload signatures to create_message() - Update tests to use appropriate result types - Revert examples to use direct content access (no content_as_list)
|
Also added this to the list of things to clean up for v2: #1253 |
| stop_sequences: list[str] | None = None, | ||
| metadata: dict[str, Any] | None = None, | ||
| model_preferences: types.ModelPreferences | None = None, | ||
| tools: list[types.Tool] | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this confused me (why not leave it out?), but its a kwarg, and is needed to discriminate between the overloads
Verify that: - create_message without tools returns CreateMessageResult with single content - CreateMessageResultWithTools supports content_as_list for array content
eef7d37 to
2579f38
Compare
bhosmer-ant
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for this!
Summary
Introduce method overloading for
create_messageto preserve backwards compatibility while supporting the new tools feature from SEP-1577.tools, returnsCreateMessageResultwith single content (backwards compatible)tools, returnsCreateMessageResultWithToolswhich allows array contentMotivation and Context
SEP-1577 changes
CreateMessageResult.contentfrom single tosingle | list. This would be a breaking change for existing SDK users. To avoid requiring a major version bump (v2.0), this PR uses@overloaddecorators to return different types based on whether tools are provided.Existing code that doesn't use tools continues to work unchanged:
How Has This Been Tested?
CreateMessageResultWithToolsCreateMessageResultBreaking Changes
None for v1.x users. Existing code that doesn't use tools continues to work unchanged.
Note: v2.0 will align
CreateMessageResultwith the schema (array content).Types of changes
Checklist