Skip to main content

AgentAdapter

Trait AgentAdapter 

Source
pub trait AgentAdapter: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn spawn_config(
        &self,
        task_description: &str,
        work_dir: &Path,
    ) -> SpawnConfig;
    fn prompt_patterns(&self) -> PromptPatterns;
    fn format_input(&self, response: &str) -> String;
    fn launch_command(
        &self,
        prompt: &str,
        idle: bool,
        resume: bool,
        session_id: Option<&str>,
    ) -> Result<String>;

    // Provided methods
    fn instruction_candidates(&self) -> &'static [&'static str] { ... }
    fn wrap_launch_prompt(&self, prompt: &str) -> String { ... }
    fn new_session_id(&self) -> Option<String> { ... }
    fn supports_resume(&self) -> bool { ... }
    fn health_check(&self) -> BackendHealth { ... }
}
Expand description

Trait that all agent adapters must implement.

An adapter translates between Batty’s supervisor and a specific agent CLI. It does not own the PTY or process — the supervisor does that. The adapter only provides the configuration and patterns needed to drive the agent.

Required Methods§

Source

fn name(&self) -> &str

Human-readable name of the agent (e.g., “claude-code”, “codex”, “aider”).

Source

fn spawn_config(&self, task_description: &str, work_dir: &Path) -> SpawnConfig

Build the spawn configuration for this agent.

task_description is the task text to pass to the agent. work_dir is the worktree path where the agent should operate.

Source

fn prompt_patterns(&self) -> PromptPatterns

Get the compiled prompt detection patterns for this agent.

Source

fn format_input(&self, response: &str) -> String

Format a response to send to the agent’s stdin.

Some agents need a trailing newline, some don’t. The adapter handles it.

Source

fn launch_command( &self, prompt: &str, idle: bool, resume: bool, session_id: Option<&str>, ) -> Result<String>

Build the shell command to launch this agent.

Returns the exec <agent> ... command string that will be written into the launch script. Each backend encodes its own CLI flags, resume semantics, and idle/prompt handling.

Provided Methods§

Source

fn instruction_candidates(&self) -> &'static [&'static str]

Preferred project-root instruction file candidates for this agent.

The first existing file is used as launch context. Adapters can override this to prefer agent-specific steering docs.

Source

fn wrap_launch_prompt(&self, prompt: &str) -> String

Allow adapters to wrap or transform the composed launch context.

Default behavior is passthrough. Adapters can prepend guardrails or framing tailored to their CLI behavior.

Source

fn new_session_id(&self) -> Option<String>

Generate a new session ID for this backend, if supported.

Backends that support session resume (e.g., Claude Code) return Some(uuid). Backends without session management return None.

Source

fn supports_resume(&self) -> bool

Whether this backend supports resuming a previous session.

Source

fn health_check(&self) -> BackendHealth

Check if this agent’s backend is healthy (binary available, etc.).

Implementors§