Closed
Description
Below is the example from the docs. I'm trying to break
out of the result.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.
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.")
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)
if __name__ == "__main__":
asyncio.run(main())