Open
Description
Problem Statement
The structured_output
implementation in the Bedrock and Anthropic model provider call the model with a hard coded tool_choice: auto
: https://github.com/strands-agents/sdk-python/blob/main/src/strands/models/bedrock.py#L206
Proposed Solution
To help get better results out of the model, we should be able to configure this ToolChoice to specify the newly added structure output tool: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_SpecificToolChoice.html
This can be done by creating a private class variable at initialization for toolChoice, and in this function we temporarily override it:
__init__(...):
self._tool_choice = {"auto": {}}
...
# https://github.com/strands-agents/sdk-python/blob/main/src/strands/models/bedrock.py#L191
"toolChoice": self._tool_choice,
...
temp_tool_choice = self._tool_choice
self._tool_choice = {"tool" : {"name" : tool_spec["name"]}}
response = self.converse(messages=prompt, tool_specs=[tool_spec])
self._tool_choice = temp_tool_choice
Use Case
Get better result of the specified pydantic model being output by the LLM as a tool use
Alternatives Solutions
N/A
Additional Context
N/A