sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

feat(bedrock): Add support for server-side tools (system tools)

Open danilop opened this issue 1 month ago • 0 comments

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.

  • [X] I ran hatch run prepare

Checklist

  • [X] I have read the CONTRIBUTING document
  • [X] I have added any necessary tests that prove my fix is effective or my feature works
  • [ ] I have updated the documentation accordingly
  • [X] 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
  • [X] 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.

danilop avatar Dec 11 '25 14:12 danilop