feat(tool_executor): Plug tool executor into bidirectional streaming implementation #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Overview
This PR integrates the complete Strands tool execution system into the bidirectional streaming architecture, replacing manual tool execution with strands tools infrastructure used by unidirectional agents. The implementation ensures consistency across all agent types.
Problem Statement
The original bidirectional streaming implementation bypassed the Strands tool execution system and instead used manual tool execution. This approach had issues including lack of proper validation, no concurrent execution support, missing error handling, code duplication, and inconsistent behavior compared to unidirectional agents. The manual implementation also lacked important features like hooks, streaming tool support, and proper result formatting.
Solution
The new implementation adds the existing Strands tool execution infrastructure by using the same
ToolExecutor._execute(),validate_and_prepare_tools()validation, andToolResultEvent/ToolStreamEventhandling.Both direct tool calling via
agent.tool.tool_name()and conversation-based tool use during streaming now utilize the complete Strands tool executor system. Tools are executed concurrently in background tasks without blocking real-time conversations. Tool results are added in the agent's message history using the same patterns as unidirectional agents, ensuring conversation context is maintained across interactions.Testing and Validation
All changes were tested with both Nova Sonic and OpenAI Realtime API model providers to ensure functionality across the bidirectional streaming model providers. Direct tool calling was validated using
agent.tool.calculator(expression="2+2")and conversation-based tool execution was tested during real-time streaming sessions where models invoked tools during conversations. Both model providers successfully queue tool requests, execute them , and send results back to the model in the ongoing conversation stream without interrupting the real-time flow.Related Issues
strands-agents#217
Documentation PR
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 prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.