-
Notifications
You must be signed in to change notification settings - Fork 321
feat: add support for Bedrock/Anthropic ToolChoice to structured_output #720
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
base: main
Are you sure you want to change the base?
Conversation
@@ -197,7 +199,7 @@ def format_request( | |||
else [] | |||
), | |||
], | |||
"toolChoice": {"auto": {}}, | |||
**({"toolChoice": tool_choice} if tool_choice else {}), |
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.
I think we'd want to preserve the old behavior?
**({"toolChoice": tool_choice} if tool_choice else {}), | |
**({"toolChoice": tool_choice} if tool_choice else {"auto": {}}), |
LMK if I'm missing a reason not to have the old behavior
@@ -171,6 +171,27 @@ def format_request_tool_message(cls, tool_result: ToolResult) -> dict[str, Any]: | |||
"content": [cls.format_request_message_content(content) for content in contents], | |||
} | |||
|
|||
@classmethod | |||
def format_request_tool_choice(cls, tool_choice: ToolChoice) -> Union[str, dict[str, Any]]: |
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.
Let's mark this as internal with an underscore prefix
@@ -290,6 +297,8 @@ async def stream( | |||
messages: List of message objects to be processed by the model. | |||
tool_specs: List of tool specifications to make available to the model. | |||
system_prompt: System prompt to provide context to the model. | |||
tool_choice: Selection strategy for tool invocation. **Note: This parameter is accepted for |
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.
If these are not implemented, if tool_choice is not None, throw instead of just relying on documentation
Description
The structured_output implementation in the Bedrock and Anthropic model provider call the model with a hard coded tool_choice:
auto
. Theauto
option lets the model itself decides whether to use a tool and use which tool. Instead, we want to make sure the tool is used in structured_output function for the sake of performance.Therefore, following changes are made:
auto
;Related Issues
#256
Documentation PR
N/A
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.