alice_runtime/agent_backend/mod.rs
1//! Agent backend abstraction.
2//!
3//! Defines the [`AgentBackend`] trait that decouples the runtime wiring
4//! from the concrete agent implementation (bob-agent, acp-agent, etc.).
5
6use std::sync::Arc;
7
8use bob_runtime::AgentResponse;
9
10/// Per-session agent handle returned by an [`AgentBackend`].
11///
12/// Each session holds its own conversation state and can process messages
13/// independently. Implementations must be `Send + Sync` so sessions can
14/// be held across async task boundaries.
15#[async_trait::async_trait]
16pub trait AgentSession: Send + Sync {
17 /// Process a user message and return the agent's response.
18 ///
19 /// The `context` carries per-request overrides such as system prompt
20 /// augmentation, skill selections, and tool policy adjustments.
21 async fn chat(
22 &self,
23 input: &str,
24 context: bob_core::types::RequestContext,
25 ) -> eyre::Result<AgentResponse>;
26}
27
28/// Factory for creating agent sessions.
29///
30/// An `AgentBackend` is stateless — it holds configuration and shared
31/// resources (LLM client, tool port, etc.) and stamps out independent
32/// [`AgentSession`] instances on demand.
33pub trait AgentBackend: Send + Sync {
34 /// Create a new session with a generated identifier.
35 fn create_session(&self) -> Arc<dyn AgentSession>;
36
37 /// Create a new session with a specific identifier.
38 fn create_session_with_id(&self, session_id: &str) -> Arc<dyn AgentSession>;
39}
40
41pub mod bob_backend;
42
43#[cfg(feature = "acp-agent")]
44pub mod acp_backend;