Use this page when you need visibility into the run before the final output is ready.
RunResultStreaming is a live run handle. It lets you:
- read events as they happen
- wait for the final
RunResult - inspect last-response and replay state
- preserve normalized and full replay input
use futures::StreamExt;
use openai_agents::{Agent, run_streamed};
#[tokio::main]
async fn main() -> Result<(), openai_agents::AgentsError> {
let agent = Agent::builder("assistant").build();
let streamed = run_streamed(&agent, "hello").await?;
let events = streamed.stream_events().collect::<Vec<_>>().await;
let result = streamed.wait_for_completion().await?;
println!("events={}", events.len());
println!("{:?}", result.final_output);
Ok(())
}Runnable versions: streamed_run.rs for a minimal stream, stream_text.rs for message text, and stream_items.rs for run-item events around a tool call.
For tool-call arguments, stream_function_call_args.rs shows the RunItem::ToolCall event payload.
For nested agent tools, agents_as_tools_streaming.rs shows AgentAsToolOptions::on_stream.
The stream can include:
- agent lifecycle events
- raw model events
- run item events
- tool lifecycle events
- handoff events
- interruption events
The streamed handle is not just an event feed. It also preserves the state needed to continue or replay the run after completion.
Use:
wait_for_completion()for the durable resultto_input_list()orto_input_list_mode(...)for replay