Use this page when you want the fastest path from an empty Rust project to a working agent run.
Add the facade crate and Tokio:
[dependencies]
openai-agents = { package = "openai-agents-rs", version = "0.1.2" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }use openai_agents::{run, Agent};
#[tokio::main]
async fn main() -> Result<(), openai_agents::AgentsError> {
let agent = Agent::builder("assistant")
.instructions("Be concise, practical, and structured.")
.build();
let result = run(&agent, "Give me three release checks.").await?;
println!("{}", result.final_output.unwrap_or_default());
Ok(())
}Runnable version: basic_run.rs
| Need | Entry point |
|---|---|
| one-shot async call | run |
| one-shot sync call | run_sync |
| reusable configured runner | Runner |
| session-backed conversations | Runner::run_with_session |
| live streamed events | run_streamed or Runner::run_streamed |
use openai_agents::{Agent, MemorySession, Runner};
#[tokio::main]
async fn main() -> Result<(), openai_agents::AgentsError> {
let agent = Agent::builder("assistant")
.instructions("Track the conversation and answer briefly.")
.build();
let session = MemorySession::new("demo");
let runner = Runner::new();
runner.run_with_session(&agent, "My name is Ada.", &session).await?;
let result = runner
.run_with_session(&agent, "What is my name?", &session)
.await?;
println!("{}", result.final_output.unwrap_or_default());
Ok(())
}Runnable version: memory_session.rs
use futures::StreamExt;
use openai_agents::{Agent, run_streamed};
#[tokio::main]
async fn main() -> Result<(), openai_agents::AgentsError> {
let agent = Agent::builder("assistant")
.instructions("Be concise.")
.build();
let streamed = run_streamed(&agent, "Stream a deployment checklist.").await?;
let events = streamed.stream_events().collect::<Vec<_>>().await;
let result = streamed.wait_for_completion().await?;
println!("events={}", events.len());
println!("{}", result.final_output.unwrap_or_default());
Ok(())
}Runnable version: streamed_run.rs
- agents.md: how to shape an agent beyond name and instructions
- running_agents.md: how runners, options, and resume paths work
- tools.md: how to attach runtime behavior
- sessions/README.md: how state and continuation work