-
Notifications
You must be signed in to change notification settings - Fork 371
feat: Use TypedEvent inheritance for callback behavior #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Move away from "callback" nested properties in the dict and explicitly passing invocation_state migrating to behaviors on the TypedEvent: - TypedEvent.is_callback_event for determining if an event should be yielded and or invoked in the callback - TypedEvent.prepare for taking in invocation_state Customers still only get dictionaries, as we decided that this will remain an implementation detail for the time being, but this makes the events typed all the way up until *just* before we yield events back to the caller
d319922
to
9438eb7
Compare
pgrayy
reviewed
Aug 28, 2025
pgrayy
reviewed
Aug 28, 2025
pgrayy
reviewed
Aug 28, 2025
pgrayy
reviewed
Aug 28, 2025
pgrayy
approved these changes
Aug 28, 2025
dbschmigelski
pushed a commit
to dbavro19/sdk-python
that referenced
this pull request
Aug 28, 2025
…s#755) Move away from "callback" nested properties in the dict and explicitly passing invocation_state migrating to behaviors on the TypedEvent: - TypedEvent.is_callback_event for determining if an event should be yielded and or invoked in the callback - TypedEvent.prepare for taking in invocation_state Customers still only get dictionaries, as we decided that this will remain an implementation detail for the time being, but this makes the events typed all the way up until *just* before we yield events back to the caller --------- Co-authored-by: Mackenzie Zastrow <[email protected]>
zastrowm
added a commit
to zastrowm/sdk-python
that referenced
this pull request
Aug 29, 2025
Our current implementation of AgentTool.stream() has a problem that we don't differentiate between intermediate streaming events and the final ToolResult events. Our only contract is that the last event *must be* be the tool result that is passed to the LLM. Our switch to Typed Events (strands-agents#755) pushes us in the right direction but for backwards compatibility we can't update the signature of `AgentTool.stream()` (nor have we exposed externally TypedEvents yet). That means that if we implemented tool-streaming today, then callers would see non-generator functions yielding both a `ToolStreamEvent` and `ToolResultEvent` even though they're not actually streaming responses. To avoid the odd behavior noted above, we'll special-case SDK-defined functions by allowing them to emit `ToolStreamEvent` and `ToolResultEvent` types directly (bypassing our normal wrapping), since they have the knowledge of when tools are actually generators or not. There's no observable difference in behavior to callers (this is all internal behavior), but this means that when we switch the flip for Tool Streaming, non-generator tools will **not** emit ToolStreamEvents - at least for AgentTool implementations that are in the SDK.
7 tasks
Ratish1
pushed a commit
to Ratish1/sdk-python
that referenced
this pull request
Aug 30, 2025
…s#755) Move away from "callback" nested properties in the dict and explicitly passing invocation_state migrating to behaviors on the TypedEvent: - TypedEvent.is_callback_event for determining if an event should be yielded and or invoked in the callback - TypedEvent.prepare for taking in invocation_state Customers still only get dictionaries, as we decided that this will remain an implementation detail for the time being, but this makes the events typed all the way up until *just* before we yield events back to the caller --------- Co-authored-by: Mackenzie Zastrow <[email protected]>
zastrowm
added a commit
that referenced
this pull request
Sep 3, 2025
Our current implementation of AgentTool.stream() has a problem that we don't differentiate between intermediate streaming events and the final ToolResult events. Our only contract is that the last event *must be* be the tool result that is passed to the LLM. Our switch to Typed Events (#755) pushes us in the right direction but for backwards compatibility we can't update the signature of `AgentTool.stream()` (nor have we exposed externally TypedEvents yet). That means that if we implemented tool-streaming today, then callers would see non-generator functions yielding both a `ToolStreamEvent` and `ToolResultEvent` even though they're not actually streaming responses. To avoid the odd behavior noted above, we'll special-case SDK-defined functions by allowing them to emit `ToolStreamEvent` and `ToolResultEvent` types directly (bypassing our normal wrapping), since they have the knowledge of when tools are actually generators or not. There's no observable difference in behavior to callers (this is all internal behavior), but this means that when we switch the flip for Tool Streaming, non-generator tools will **not** emit ToolStreamEvents - at least for AgentTool implementations that are in the SDK. Co-authored-by: Mackenzie Zastrow <[email protected]>
7 tasks
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.
Description
This is step step 2/N of implementing typed-events:
Related PRs:
Migrate "callback" nested properties and explicitly passing invocation_state to behaviors on the TypedEvent:
TypedEvent.is_callback_event
for determining if an event should be yielded and or invoked in the callbackTypedEvent.prepare
for taking in invocation_state (and optionally merging it in)invocation_state
throughout the systemCustomers still only get dictionaries, as we decided that this will remain an implementation detail for the time being, but this makes the events typed all the way up until just before we yield events back to the caller
As part of this refactor, we also now strongly typed
ToolResultEvent
andToolStreamEvent
- neither of these are currently yielded up to the caller - that will be unlocked/opened in a future PR as part of #543Observable changes: There should be none outside of the Agent; internally there are a couple places where we now sorely return
TypedEvent
sRelated Issues
#242
Documentation PR
Will be once we publish typed events
Type of Change
Other (please describe): Internal refactor
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 prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.