Skip to content

Conversation

liushang1997
Copy link
Contributor

@liushang1997 liushang1997 commented Aug 22, 2025

Description

Add a new parameter tool_choice to the Model.stream method to allow providers to configure the tool choice. We do not expose this anywhere in the Agent/event_loop, so for now this is just an internal implementation detail, but it does allow/enable providers that use tools for structured_output - specifically Bedrock & Anthropic - to force tool calling to provide structured_output; this should provide better consistency for customers as the LLM is now guaranteed to call that api.

Changes made

  1. Add a new parameter to Model.stream() that takes in the toolChoice, defaulting to auto;
  2. Plumb through various providers:
    • anthropic (needed)
    • bedrock (needed)
    • openai (implemented)
    • litellm (implemented via openai)
  3. Emit warnings for providers that it's not plumbed through:
    • llamaapi
    • mistral
    • ollama
    • sagemaker
    • writer
  4. For providers that use tool calling for structured_output (Bedrock and Anthropic), pass toolChoice=any when calling stream()
  5. Add unit tests
  6. Add conformance test to verify structured_output through relevant providers is forced

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

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

For structured output so that some providers can force tool calls

Co-authored-by: Shang Liu <[email protected]>
@zastrowm zastrowm dismissed their stale review September 10, 2025 15:42

I made changes

@zastrowm zastrowm merged commit 001aa93 into strands-agents:main Sep 10, 2025
11 of 12 checks passed
This was referenced Sep 17, 2025
Unshure pushed a commit to Unshure/sdk-python that referenced this pull request Sep 24, 2025
…ut (strands-agents#720)

For structured output so that some providers can force tool calls

---------

Co-authored-by: Mackenzie Zastrow <[email protected]>
Co-authored-by: Shang Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants