Skip to main content

Module builder

Module builder 

Source
Expand description

High-level builder API for driving agents programmatically.

Instead of shelling out to the agent CLI binary, Rust programs can use AgentBuilder to configure and execute agent sessions directly.

§Examples

use zag_agent::builder::AgentBuilder;

// Non-interactive exec — returns structured output
let output = AgentBuilder::new()
    .provider("claude")
    .model("sonnet")
    .auto_approve(true)
    .exec("write a hello world program")
    .await?;

println!("{}", output.result.unwrap_or_default());

// Interactive session
AgentBuilder::new()
    .provider("claude")
    .run(Some("initial prompt"))
    .await?;

Structs§

AgentBuilder
Builder for configuring and running agent sessions.
SessionMetadata
Session discovery metadata — mirrors the --name, --description, and --tag flags on the run/exec/spawn CLI commands. Attached to a builder via AgentBuilder::name, AgentBuilder::description, and AgentBuilder::tag.

Enums§

SessionLogMode
Controls whether the builder manages a SessionLogCoordinator for the session it launches.