alice_runtime/agent_backend/
bob_backend.rs1use std::sync::Arc;
7
8use bob_core::types::RequestContext;
9use bob_runtime::{Agent, AgentResponse, Session};
10
11use super::{AgentBackend, AgentSession};
12
13#[derive(Debug)]
15pub struct BobAgentSession {
16 session: Session,
17}
18
19#[async_trait::async_trait]
20impl AgentSession for BobAgentSession {
21 async fn chat(&self, input: &str, context: RequestContext) -> eyre::Result<AgentResponse> {
22 let response = self.session.chat_with_context(input, context).await?;
23 Ok(response)
24 }
25}
26
27#[derive(Debug, Clone)]
31pub struct BobAgentBackend {
32 agent: Agent,
33}
34
35impl BobAgentBackend {
36 #[must_use]
38 pub const fn new(agent: Agent) -> Self {
39 Self { agent }
40 }
41}
42
43impl AgentBackend for BobAgentBackend {
44 fn create_session(&self) -> Arc<dyn AgentSession> {
45 let session = self.agent.start_session();
46 Arc::new(BobAgentSession { session })
47 }
48
49 fn create_session_with_id(&self, session_id: &str) -> Arc<dyn AgentSession> {
50 let session = self.agent.start_session_with_id(session_id);
51 Arc::new(BobAgentSession { session })
52 }
53}