-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Canceling the stream from result.stream_events() #574
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
Labels
enhancement
New feature or request
Comments
Yeah makes sense, we should add this |
@rm-openai Any way I can help? |
@handrew PR would be great! Should be able to add |
@rm-openai Alrighty I gave it a shot. I'm a bit of a noob to OSS contribution so please bear with me. #579 |
rm-openai
pushed a commit
that referenced
this issue
Apr 23, 2025
Fix for #574 @rm-openai I'm not sure how to add a test within the repo but I have pasted a test script below that seems to work ```python import asyncio from openai.types.responses import ResponseTextDeltaEvent from agents import Agent, Runner async def main(): agent = Agent( name="Joker", instructions="You are a helpful assistant.", ) result = Runner.run_streamed(agent, input="Please tell me 5 jokes.") num_visible_event = 0 async for event in result.stream_events(): if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent): print(event.data.delta, end="", flush=True) num_visible_event += 1 print(num_visible_event) if num_visible_event == 3: result.cancel() if __name__ == "__main__": asyncio.run(main()) ````
Thanks @rm-openai ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Below is the example from the docs. I'm trying to
break
out of theresult.stream_events()
async for. I can break out, but the agent will continue to take actions. It would be great if there was some way for us to stop the events entirely, because the agent will continue wreaking havoc on my things.The text was updated successfully, but these errors were encountered: