Skip to main content

Module run

Module run 

Source
Expand description

The driver: an Agent plus a RunAgentInput in, a [Stream] of events out.

The stream owns the agent’s future and polls it itself, so this crate needs no executor of its own — no tokio::spawn, nothing to configure, and the same code runs on wasm. Draining the stream is running the agent.

struct Greeter;

impl Agent for Greeter {
    type State = ();
    async fn run(&self, ctx: &mut RunContext<()>) -> Result<RunOutcome> {
        ctx.say("hello")?;
        Ok(RunOutcome::Success)
    }
}

let events: Vec<Event> = run(Greeter, RunAgentInput::new("thread-1", "run-1"))
    .map(|event| event.expect("the stream should not break"))
    .collect()
    .await;

assert_eq!(events.first().map(Event::event_type), Some(ag_ui::EventType::RunStarted));
assert_eq!(events.last().map(Event::event_type), Some(ag_ui::EventType::RunFinished));

Structs§

Runner
A configured run: the agent, its transformer chain and its cancellation token.

Functions§

run
Runs agent against input with no transformers and a fresh cancellation token.