pub struct AgentBuilder { /* private fields */ }Expand description
Builder for configuring and running agent sessions.
Use the builder pattern to set options, then call a terminal method
(exec, run, resume, continue_last) to execute.
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
Sourcepub fn provider(self, provider: &str) -> Self
pub fn provider(self, provider: &str) -> Self
Set the provider (e.g., “claude”, “codex”, “gemini”, “copilot”, “ollama”).
Sourcepub fn model(self, model: &str) -> Self
pub fn model(self, model: &str) -> Self
Set the model (e.g., “sonnet”, “opus”, “small”, “large”).
Sourcepub fn system_prompt(self, prompt: &str) -> Self
pub fn system_prompt(self, prompt: &str) -> Self
Set a system prompt to configure agent behavior.
Sourcepub fn auto_approve(self, approve: bool) -> Self
pub fn auto_approve(self, approve: bool) -> Self
Enable auto-approve mode (skip permission prompts).
Sourcepub fn json_schema(self, schema: Value) -> Self
pub fn json_schema(self, schema: Value) -> Self
Set a JSON schema for structured output validation.
Implies json().
Sourcepub fn json_stream(self) -> Self
pub fn json_stream(self) -> Self
Enable streaming JSON output (NDJSON format).
Sourcepub fn session_id(self, id: &str) -> Self
pub fn session_id(self, id: &str) -> Self
Set a specific session ID (UUID).
Sourcepub fn output_format(self, format: &str) -> Self
pub fn output_format(self, format: &str) -> Self
Set the output format (e.g., “text”, “json”, “json-pretty”, “stream-json”).
Sourcepub fn input_format(self, format: &str) -> Self
pub fn input_format(self, format: &str) -> Self
Set the input format (Claude only, e.g., “text”, “stream-json”).
Sourcepub fn replay_user_messages(self, replay: bool) -> Self
pub fn replay_user_messages(self, replay: bool) -> Self
Re-emit user messages from stdin on stdout (Claude only).
Only works with --input-format stream-json and --output-format stream-json.
Sourcepub fn include_partial_messages(self, include: bool) -> Self
pub fn include_partial_messages(self, include: bool) -> Self
Include partial message chunks in streaming output (Claude only).
Only works with --output-format stream-json.
Sourcepub fn show_usage(self, show: bool) -> Self
pub fn show_usage(self, show: bool) -> Self
Show token usage statistics.
Sourcepub fn on_progress(self, handler: Box<dyn ProgressHandler>) -> Self
pub fn on_progress(self, handler: Box<dyn ProgressHandler>) -> Self
Set a custom progress handler for status reporting.
Sourcepub async fn exec(self, prompt: &str) -> Result<AgentOutput>
pub async fn exec(self, prompt: &str) -> Result<AgentOutput>
Run the agent non-interactively and return structured output.
This is the primary entry point for programmatic use.
Sourcepub async fn exec_streaming(self, prompt: &str) -> Result<StreamingSession>
pub async fn exec_streaming(self, prompt: &str) -> Result<StreamingSession>
Run the agent with streaming input and output (Claude only).
Returns a StreamingSession that allows sending NDJSON messages to
the agent’s stdin and reading events from stdout. Automatically
configures --input-format stream-json and --replay-user-messages.
§Examples
use zag_agent::builder::AgentBuilder;
let mut session = AgentBuilder::new()
.provider("claude")
.exec_streaming("initial prompt")
.await?;
session.send_user_message("do something").await?;
while let Some(event) = session.next_event().await? {
println!("{:?}", event);
}
session.wait().await?;Sourcepub async fn run(self, prompt: Option<&str>) -> Result<()>
pub async fn run(self, prompt: Option<&str>) -> Result<()>
Start an interactive agent session.
This takes over stdin/stdout for the duration of the session.
Sourcepub async fn continue_last(self) -> Result<()>
pub async fn continue_last(self) -> Result<()>
Resume the most recent session.