Skip to main content

tycode_core/agents/
catalog.rs

1use std::sync::Arc;
2
3use crate::agents::agent::Agent;
4
5/// Information about an available agent
6#[derive(Clone, Debug)]
7pub struct AgentInfo {
8    pub name: String,
9    pub description: String,
10}
11
12/// Registry of available agents
13pub struct AgentCatalog {
14    agents: Vec<Arc<dyn Agent>>,
15}
16
17impl AgentCatalog {
18    /// Create a new empty agent catalog
19    pub fn new() -> Self {
20        Self { agents: Vec::new() }
21    }
22
23    /// Register an agent in the catalog
24    pub fn register_agent(&mut self, agent: Arc<dyn Agent>) {
25        self.agents.push(agent);
26    }
27
28    /// Get all registered agents
29    fn agents(&self) -> &[Arc<dyn Agent>] {
30        &self.agents
31    }
32
33    /// Get all available agents with their descriptions - names derived from trait
34    pub fn list_agents(&self) -> Vec<AgentInfo> {
35        self.agents()
36            .iter()
37            .map(|agent| AgentInfo {
38                name: agent.name().to_string(),
39                description: agent.description().to_string(),
40            })
41            .collect()
42    }
43
44    /// Create an agent instance by name
45    pub fn create_agent(&self, name: &str) -> Option<Arc<dyn Agent>> {
46        self.agents()
47            .iter()
48            .find(|agent| agent.name() == name)
49            .cloned()
50    }
51
52    /// Get agent descriptions as a formatted string for tool schemas
53    pub fn get_agent_descriptions(&self) -> String {
54        let agents = self.list_agents();
55        agents
56            .iter()
57            .map(|a| format!("'{}': {}", a.name, a.description))
58            .collect::<Vec<_>>()
59            .join(", ")
60    }
61
62    /// Get valid agent names for enum schema
63    pub fn get_agent_names(&self) -> Vec<String> {
64        self.list_agents().iter().map(|a| a.name.clone()).collect()
65    }
66}