Skip to main content

ciab_core/traits/
agent.rs

1use async_trait::async_trait;
2use tokio::sync::mpsc;
3use uuid::Uuid;
4
5use crate::error::CiabResult;
6use crate::types::agent::{
7    AgentCommand, AgentConfig, AgentHealth, InteractiveProtocol, PromptMode, SlashCommand,
8};
9use crate::types::llm_provider::AgentLlmCompatibility;
10use crate::types::session::Message;
11use crate::types::stream::StreamEvent;
12
13#[async_trait]
14pub trait AgentProvider: Send + Sync {
15    /// The name/identifier of this agent provider.
16    fn name(&self) -> &str;
17
18    /// The base container image for sandboxes using this provider.
19    fn base_image(&self) -> &str;
20
21    /// Commands to install the agent CLI inside the sandbox.
22    fn install_commands(&self) -> Vec<String>;
23
24    /// Build the command used to start the agent process in a sandbox.
25    fn build_start_command(&self, config: &AgentConfig) -> AgentCommand;
26
27    /// How prompts should be delivered to the agent process.
28    /// Defaults to StdinJson (Claude Code's protocol).
29    fn prompt_mode(&self) -> PromptMode {
30        PromptMode::StdinJson
31    }
32
33    /// Whether the provider supports interactive stdin control protocol.
34    /// Claude Code supports control_request/control_response; others don't.
35    fn interactive_protocol(&self) -> InteractiveProtocol {
36        InteractiveProtocol::None
37    }
38
39    /// Environment variables required by this provider.
40    fn required_env_vars(&self) -> Vec<String>;
41
42    /// Parse raw output from the agent process into stream events.
43    fn parse_output(&self, sandbox_id: &Uuid, raw: &str) -> Vec<StreamEvent>;
44
45    /// Validate that the given config is appropriate for this provider.
46    fn validate_config(&self, config: &AgentConfig) -> CiabResult<()>;
47
48    /// Send a message to the agent and receive a stream of events.
49    async fn send_message(
50        &self,
51        sandbox_id: &Uuid,
52        session_id: &Uuid,
53        message: &Message,
54        tx: &mpsc::Sender<StreamEvent>,
55    ) -> CiabResult<()>;
56
57    /// Interrupt the agent in the given sandbox.
58    async fn interrupt(&self, sandbox_id: &Uuid) -> CiabResult<()>;
59
60    /// Check the health of the agent in a sandbox.
61    async fn health_check(&self, sandbox_id: &Uuid) -> CiabResult<AgentHealth>;
62
63    /// Returns slash commands available for this provider.
64    fn slash_commands(&self) -> Vec<SlashCommand> {
65        vec![]
66    }
67
68    /// Returns the LLM providers this agent is compatible with.
69    fn supported_llm_providers(&self) -> Vec<AgentLlmCompatibility> {
70        vec![]
71    }
72}