Skip to main content

rs_adk/
agent.rs

1//! The core Agent trait.
2
3use async_trait::async_trait;
4use rs_genai::prelude::Tool;
5
6use crate::context::InvocationContext;
7use crate::error::AgentError;
8
9/// The fundamental agent trait. Everything that can process a live session
10/// implements this — LLM agents, function agents, pipelines, routers.
11#[async_trait]
12pub trait Agent: Send + Sync + 'static {
13    /// Human-readable name for routing, logging, and debugging.
14    fn name(&self) -> &str;
15
16    /// Run this agent on a live session. Returns when the agent is done
17    /// (turn complete, transfer, or disconnect).
18    async fn run_live(&self, ctx: &mut InvocationContext) -> Result<(), AgentError>;
19
20    /// Declare tools this agent provides (sent in the setup message).
21    fn tools(&self) -> Vec<Tool> {
22        vec![]
23    }
24
25    /// Sub-agents this agent can transfer control to.
26    fn sub_agents(&self) -> Vec<std::sync::Arc<dyn Agent>> {
27        vec![]
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    // Verify the trait is object-safe
36    fn _assert_object_safe(_: &dyn Agent) {}
37
38    #[test]
39    fn agent_trait_is_object_safe() {
40        // If this compiles, Agent is object-safe
41    }
42}