Skip to content

Conversation

@mehtarac
Copy link
Owner

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, and ToolResultEvent/ToolStreamEvent handling.

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

  • 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 tool result message to conversation history
if tool_results:
from ....hooks import MessageAddedEvent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the hooks import to top? or is there any circular deps?

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