Skip to main content

Agent

Trait Agent 

Source
pub trait Agent: Send + Sync {
    // Required method
    fn spawn<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
        &'life0 self,
        repo_path: &'life1 Path,
        allowed_tools: &'life2 [String],
        system_prompt: Option<&'life3 str>,
        resume_session_id: Option<&'life4 str>,
        model: Option<&'life5 str>,
    ) -> Pin<Box<dyn Future<Output = Result<AgentHandle>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             'life5: 'async_trait;
}
Expand description

Trait for agent backends (e.g., Claude Code CLI).

Implementations provide the interface to spawn and communicate with AI coding agents. The agent runs as a subprocess and communicates via stdin/stdout using a stream-json protocol.

§Example

let agent = ClaudeAgent;
let handle = agent.spawn(
    Path::new("/path/to/repo"),
    &["Read", "Write", "Bash"],
    Some("You are a helpful assistant"),
    None,  // New session
    Some("claude-opus-4-6"),
).await?;

// Send a prompt
handle.sender.send("Fix the login bug".to_string()).await?;

// Receive events
while let Some(event) = handle.receiver.recv().await {
    match event {
        AgentEvent::Text(text) => println!("{}", text),
        AgentEvent::TurnComplete { .. } => break,
        _ => {}
    }
}

Required Methods§

Source

fn spawn<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, repo_path: &'life1 Path, allowed_tools: &'life2 [String], system_prompt: Option<&'life3 str>, resume_session_id: Option<&'life4 str>, model: Option<&'life5 str>, ) -> Pin<Box<dyn Future<Output = Result<AgentHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

Spawns a new agent session in the specified repository.

§Arguments
  • repo_path - Working directory for the agent (git repo root)
  • allowed_tools - List of tools the agent can use without asking permission
  • system_prompt - Optional additional system prompt to append
  • resume_session_id - If set, resumes an existing session instead of starting new
  • model - Model to use (e.g., “claude-opus-4-6”). Only used for new sessions.
§Returns

An AgentHandle for communicating with the spawned agent.

§Errors

Returns an error if:

  • The agent binary is not found in PATH
  • The subprocess fails to spawn
  • Required stdio streams cannot be captured

Implementors§