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