The OpenAI Agents SDK can stream a run: instead of waiting for the final answer, you receive events as the run progresses, including tokens, tool calls and handoffs. Streaming is what makes an agent feel responsive in a user interface, and it is also how you see a run going wrong early enough to stop it. Run the agent in streamed mode, read the events in a loop, and show the user what is happening instead of a blank screen.
What you need
- Python with the openai-agents package installed and an API key
- An agent with at least one tool
- A place to show progress, such as a terminal or a web page
Step 1: Run the agent in streamed mode
Start the run with the streamed runner instead of the blocking one, so the run returns a stream of events rather than a single final result.
Step 2: Read the events in a loop
Loop over the stream and handle the event types you care about: text tokens to display, tool calls to log, and handoffs to note. Ignore event types you do not need.
Step 3: Check the final result still arrives
Confirm that after the stream ends, the final output is still available as a result object, with the same content the stream showed. If the stream ends without a final result, the run was interrupted.
Worked example: synthetic streamed run
The table below is a synthetic example. It shows the expected result of streaming; no run was streamed.
| Event | Shown? | Result |
|---|---|---|
| Text tokens | Yes | Pass |
| Tool call | Yes, logged | Pass |
| Handoff | Yes, noted | Pass |
| Final result arrives | Yes | Pass |
Expected result (UNTESTED). tokens, the tool call and the handoff all appear as they happen, and the final result still arrives at the end. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Streaming shows the run as it happens, but the final result object is still the record of what the run did.
- A streamed run can be interrupted mid-stream, so do not treat partial output as a finished answer.
- Log tool calls from the stream, because a run that looks fine in text may have called a tool you did not expect.
