Skip to content

[BUG] Streaming Tool results are swallowed by Stands #543

@alanmcco-amzn

Description

@alanmcco-amzn

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.1.0

Python Version

3.12

Operating System

macOS

Installation Method

pip

Steps to Reproduce

  1. Create an agent with an AgentTool that yields / stream results prior to the final result of the tool
  2. Call the agent with stream_aysnc
  3. Observe all events from the agent returned in the async stream
  4. The streamed results from the tool are not present in any observable event from agent.stream_async (and I believe they are ALSO not present in any provided callback_handler hook during agent creation).

streaming_tool_fix.md

In addition, only the final result of the tool call is included in the agent context. I believe this is the desired behavior (I also want this), but it is undocumented behavior.

Repeat the steps above, but yield partial results from the agent with the results being returned in a Dict value with the key "callback". Now you will see the results are returned.

Note: I have uploaded a more detailed report in markdown format.

Expected Behavior

I expect to be able to observe streamed tool results (in progress. events etc.) from the stream_async method of the agent. I also expect to be able to observe them in a registered callback handler.

If there are specific formats to ensure a tool result is included, either in agent output, callback handler, or agent context, I expect that to be documented to ensure that I'm not relying on internals of the framework that may be subject to change.

If the framework in the agent logic requires data to be presented in a specific format to avoid being swallowed, I expect the framework to wrap this internally with that structure so that I do not need to read the internals of the framework to ensure my data is returned.

Actual Behavior

If the implementer of a tool doesn't return a very specific format with a key for callback which is undocumented, the framework drops the messages.

Additional Context

No response

Possible Solution

I suggest that tools can yield any dictionary of results and internally Strands should prevent swallowing this data and return it through both 1) stream_aysnc and 2) registered callback_handlers.

In my dive into the Strands code, it appeared that streaming tool results were yielded up several layers of the callstack unchanged before being swallowed. I would suggest that if this format is expected internally, that you find an appropriate place to automatically wrap the tool result in the expected structure {"callback": } if this is required. This would be backwards compatible if anyone had already done this, since if the key already exists it could be skipped.

Related Issues

No response

Metadata

Metadata

Assignees

Labels

area-asyncRelated to asynchronous flows or multi-threadingbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions