Skip to content

Conversation

@danilop
Copy link

@danilop danilop commented Dec 11, 2025

Description

This PR adds support for server-side tools that are handled within the model invocation. When Bedrock returns tool use and tool response together with a specific (server_tool_use) type, the SDK now correctly:

  • Distinguishes server-side tools (like nova_grounding) from client-side tools
  • Does NOT override stopReason to tool_use for server-side tools
  • Tracks tool results to determine if tools have already been executed

This enables features like Nova Web Grounding to work correctly without triggering infinite loops or unnecessary tool execution attempts.

Changes:

  • Updated streaming handler to track tool types and results
  • Added _has_client_side_tools_to_execute() helper method
  • Updated non-streaming handler to use the new helper
  • Added comprehensive tests for server-side tool handling

Related Issues

Fixes #1154

Documentation PR

N/A

Type of Change

Bug fix / New feature

Testing

Tested with Nova Web Grounding in both streaming and non-streaming modes.

  • 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.

Add support for server-side tools that are handled within the model
invocation. When Bedrock returns tool use and tool response together
with a specific (server_tool_use) type, the SDK now correctly:

- Distinguishes server-side tools (like nova_grounding) from client-side tools
- Does NOT override stopReason to 'tool_use' for server-side tools
- Tracks tool results to determine if tools have already been executed

This enables features like Nova Web Grounding to work correctly without
triggering infinite loops or unnecessary tool execution attempts.

Changes:
- Updated streaming handler to track tool types and results
- Added _has_client_side_tools_to_execute() helper method
- Updated non-streaming handler to use the new helper
- Added comprehensive tests for server-side tool handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for system tool

1 participant