feat: emit contextWindowFallback stream event before context reduction#2060
Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Open
feat: emit contextWindowFallback stream event before context reduction#2060Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Conversation
When the agent catches a ContextWindowOverflowException it now yields a contextWindowFallback streaming event before calling reduce_context, giving callers a real-time signal that context compression is starting. Adds ContextWindowFallbackEvent TypedDict to streaming.py, a matching ContextWindowFallbackStreamEvent TypedEvent subclass in _events.py, and wires it into the overflow handler in agent.py. Closes strands-agents#1511
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.
Description
When the agent handles a context window overflow, it calls `reduce_context()` synchronously. This is a blocking operation that can take a noticeable amount of time in long sessions, but callers have no way to know it has started. From outside, the stream just goes quiet until the reduction finishes and the model is called again.
This change adds a `contextWindowFallback` event emitted immediately before `reduce_context()` is called, giving streaming consumers a real-time signal that context compression is starting.
Changes:
The `contextWindowFallback` key is also added to `StreamEvent` so consumers can pattern-match it in the same way as `messageStart`, `messageStop`, and the other stream event types.
Related Issues
Fixes #1511
Documentation PR
N/A
Type of Change
New feature
Testing
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.