ares/agents/mod.rs
1//! AI agent orchestration and management.
2//!
3//! This module provides the agent system for A.R.E.S, including:
4//!
5//! - **Agent Trait** - Base trait that all agents implement
6//! - **ConfigurableAgent** - Dynamic agent created from TOML/TOON configuration
7//! - **AgentRegistry** - Registry for creating and managing agent instances
8//! - **Router** - Routes requests to appropriate specialized agents
9//! - **Orchestrator** - Coordinates multi-step agent workflows
10//!
11//! ## Architecture
12//!
13//! All agents are now created dynamically via `ConfigurableAgent`, which reads
14//! configuration from TOML files. Legacy hardcoded agents have been removed.
15//!
16//! ## Example
17//!
18//! ```rust,ignore
19//! use ares::agents::{Agent, AgentRegistry};
20//!
21//! // Create registry from configuration
22//! let registry = AgentRegistry::from_config(&config, provider_registry, tool_registry);
23//!
24//! // Get an agent instance
25//! let agent = registry.get_agent("product")?;
26//!
27//! // Execute with context
28//! let response = agent.execute("Help me with my order", &context).await?;
29//! ```
30
31pub mod configurable;
32/// External context injection trait (OSS: NoOp, Managed: Eruka/custom).
33pub mod context_provider;
34/// Loop detection for agent outputs — prevents repetitive/stuck agents.
35pub mod loop_detector;
36/// Checkpoint/crash recovery — serialize agent state, restore on restart.
37pub mod checkpoint;
38/// Multi-agent orchestration for complex tasks.
39#[cfg(feature = "postgres")]
40pub mod orchestrator;
41pub mod registry;
42/// Request routing to specialized agents.
43pub mod router;
44/// Per-tenant agent creation from DB-stored configs.
45#[cfg(feature = "postgres")]
46pub mod tenant_agent;
47
48use crate::llm::client::TokenUsage;
49use crate::types::{AgentContext, AgentType, Result};
50use async_trait::async_trait;
51
52// Re-export commonly used types
53pub use configurable::ConfigurableAgent;
54pub use context_provider::{ContextProvider, NoOpContextProvider};
55pub use registry::{AgentRegistry, AgentRegistryBuilder};
56
57/// Response from agent execution, including content and optional token usage
58pub struct AgentResponse {
59 /// The generated text response
60 pub content: String,
61 /// Token usage from the LLM provider (None if unavailable)
62 pub usage: Option<TokenUsage>,
63 /// Metadata about the execution (model, provider, etc.)
64 pub metadata: Option<ExecutionMetadata>,
65}
66
67/// Metadata about the execution of an agent
68pub struct ExecutionMetadata {
69 /// The name of the model used
70 pub model_name: String,
71 /// The name of the provider used
72 pub provider_name: String,
73}
74
75/// Base trait for all agents
76#[async_trait]
77pub trait Agent: Send + Sync {
78 /// Execute the agent with given input and context
79 async fn execute(&self, input: &str, context: &AgentContext) -> Result<AgentResponse>;
80
81 /// Get the agent's system prompt
82 fn system_prompt(&self) -> String;
83
84 /// Get the agent type
85 fn agent_type(&self) -> AgentType;
86}