feat: add graceful stop method to run_async#5559
Open
BowedMars2 wants to merge 18 commits intogoogle:mainfrom
Open
feat: add graceful stop method to run_async#5559BowedMars2 wants to merge 18 commits intogoogle:mainfrom
BowedMars2 wants to merge 18 commits intogoogle:mainfrom
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
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.
Link to Issue or Description of Change
Link to an existing issue (if applicable):
run_async()from outside the agent #4796Problem:
There is currently no graceful way of stopping run_async. The current method is essentially a workaround, and there are multiple issues with it, including the inability to tell it was interrupted.
Solution:
My solution adds an optional stop_signal field to run_async, which can be externally triggered to tell run_async to stop after the next returned Event.
Testing Plan
Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.
Unit Tests:
Please include a summary of passed
pytestresults.Manual End-to-End (E2E) Tests:
To manually test my code, I created a test agent:
I then created another file that asks the agent to write a long story, then stops it after a few seconds. This uses the SSE streaming mode, so that events contain clumps of generated text rather than sending the entire story all at once at the end.
As expected, the agent began generating a story, but was cut off in the middle. Note: during some tests the agent took a while to begin writing the story and I had to adjust the number of seconds it waited before sending the StopSignal.
Checklist