feat(aws-strands): add tool_stream_event_handler hook to ToolBehavior#1634
Draft
malaporte wants to merge 1 commit into
Draft
feat(aws-strands): add tool_stream_event_handler hook to ToolBehavior#1634malaporte wants to merge 1 commit into
malaporte wants to merge 1 commit into
Conversation
Add a new optional ToolStreamEventHandler callback to ToolBehavior that is invoked for every intermediate event yielded by an async-generator tool (tool_stream_event). The handler receives (tool_use_id, stream_data) and may yield zero or more AG-UI events forwarded into the top-level stream. When a handler is registered the default state-snapshot behaviour is suppressed for that tool; the handler is responsible for any state updates it wants to emit. All other tools retain the existing behaviour. This makes it possible to surface sub-agent streaming activity (e.g. specialist-run ActivityMessages) without reimplementing the full event loop in a subclass.
|
@malaporte is attempting to deploy a commit to the CopilotKit Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add a new optional
ToolStreamEventHandlercallback toToolBehaviorthat is invoked for every intermediate event yielded by an async-generator tool (tool_stream_event).Motivation
When an orchestrator agent calls a specialist sub-agent via an async-generator
@tool, Strands wraps each yielded value in atool_stream_event. The existing handler only checks for{"state": ...}payloads and ignores everything else — making it impossible to surface the specialist's streaming activity (text, tool calls, results) to the frontend without reimplementing the entire event loop in a subclass.This hook makes that use case a first-class citizen.
Changes
config.pyToolStreamEventHandler = Callable[[str, Any], AsyncIterator[Any]]type aliastool_stream_event_handler: Optional[ToolStreamEventHandler] = Nonefield toToolBehavioragent.pytool_stream_eventbranch with a dispatch: if aToolBehaviorwithtool_stream_event_handleris registered for the tool, call it and forward its yielded events; otherwise fall through to the existing{"state": ...}snapshot behaviour__init__.pyToolStreamEventHandlerBehaviour
tool_stream_event_handlercontinue to work exactly as before(tool_use_id: str, stream_data: Any)and may yield zero or more AG-UIEventobjects which are forwarded directly into the top-level stream