Skip to main content

AgentRunner

Trait AgentRunner 

Source
pub trait AgentRunner: Send + Sync {
    // Required methods
    fn build_command(
        &self,
        model: Option<&str>,
        timeout_cmd: &str,
        sys_file: &str,
        msg_file: &str,
        permissions: &PermissionRules,
    ) -> String;
    fn parse_response(&self, raw: &str) -> Result<ParsedResponse, AgentError>;
    fn stream_events(&self, event: &Value) -> Vec<StreamEvent>;
    fn classify_error(
        &self,
        exit_code: i32,
        stdout: &str,
        stderr: &str,
    ) -> AgentError;
    fn router_command(
        &self,
        prompt: &str,
        model: Option<&str>,
    ) -> Result<Command>;

    // Provided methods
    fn extract_text(&self, raw: &str) -> Result<String, AgentError> { ... }
    fn classify_error_with_elapsed(
        &self,
        exit_code: i32,
        stdout: &str,
        stderr: &str,
        elapsed_secs: Option<u64>,
    ) -> AgentError { ... }
    fn available_models(&self) -> Vec<String> { ... }
    fn free_models(&self) -> Vec<String> { ... }
    fn router_transcript(&self) -> RouterTranscript { ... }
}
Expand description

Per-agent runner trait.

Each agent implements this to handle its specific CLI invocation, output parsing, and error classification.

Required Methods§

Source

fn build_command( &self, model: Option<&str>, timeout_cmd: &str, sys_file: &str, msg_file: &str, permissions: &PermissionRules, ) -> String

Build the CLI command string for the legacy tmux runner.

The returned string is embedded into a shell command that captures output in the tmux session. The permissions struct carries unified rules that each agent translates to its own CLI flags.

Source

fn parse_response(&self, raw: &str) -> Result<ParsedResponse, AgentError>

Parse raw stdout into a ParsedResponse.

Returns Ok(ParsedResponse) on success, Err(AgentError) if the output indicates an error or cannot be parsed.

Source

fn stream_events(&self, event: &Value) -> Vec<StreamEvent>

Transcript steps for one parsed line of this agent’s NDJSON output

Source

fn classify_error( &self, exit_code: i32, stdout: &str, stderr: &str, ) -> AgentError

Classify an error from exit code + stdout + stderr into an AgentError.

Called when the agent process exits with a non-zero code, or when parse_response fails to find a valid result.

Source

fn router_command(&self, prompt: &str, model: Option<&str>) -> Result<Command>

Build a minimal CLI command for LLM-based routing.

The command should run the agent with prompt as the sole task and return structured (JSON or NDJSON) output on stdout. Used by the router to classify tasks without launching a full agent session.

Provided Methods§

Source

fn extract_text(&self, raw: &str) -> Result<String, AgentError>

Extract the raw inner text from an agent output envelope, without attempting to parse it as an AgentResponse.

Use this in the review pipeline so that a ReviewResponse JSON can be recovered even when the text doesn’t match the task AgentResponse schema.

  • For Claude/Kimi/MiniMax: strips the --output-format stream-json NDJSON wrapper and returns the "result" field of the final "type":"result" line.
  • For Codex: returns the text of the last agent_message item.
  • For OpenCode: concatenates all text events.
  • Default: returns raw unchanged (safe fallback for unknown agents).

Returns Err(AgentError) only for terminal errors (rate limit, auth, etc.) that should abort the review pipeline entirely.

Source

fn classify_error_with_elapsed( &self, exit_code: i32, stdout: &str, stderr: &str, elapsed_secs: Option<u64>, ) -> AgentError

Classify error with elapsed session time (for accurate timeout reporting).

Source

fn available_models(&self) -> Vec<String>

Models available for this agent (for intra-agent failover).

Source

fn free_models(&self) -> Vec<String>

Free/fallback models for last-resort failover.

Source

fn router_transcript(&self) -> RouterTranscript

Router stdout shape. The router matches on this instead of agent names

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§