Skip to main content

ares_agent/
lib.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#![allow(dead_code)]
12#![allow(unused_variables)]
13#![allow(deprecated)]
14#![allow(clippy::too_many_arguments)]
15#![allow(clippy::explicit_counter_loop)]
16
17//! ## Architecture
18//!
19//! All agents are now created dynamically via `ConfigurableAgent`, which reads
20//! configuration from TOML files. Legacy hardcoded agents have been removed.
21//!
22//! ## Example
23//!
24//! ```rust,ignore
25//! use ares::agents::{Agent, AgentRegistry};
26//!
27//! // Create registry from configuration
28//! let registry = AgentRegistry::from_config(config.agents, provider_registry, tools);
29//!
30//! // Get an agent instance
31//! let agent = registry.get_agent("product")?;
32//!
33//! // Execute with context
34//! let response = agent.execute("Help me with my order", &context).await?;
35//! ```
36
37pub mod config;
38pub mod workflows_config;
39pub use config::AgentConfig;
40pub use workflows_config::{SkillsTomlConfig, WorkflowConfig};
41
42/// Live TOON agent lookup used by [`AgentRegistry`] without depending on Overlay.
43pub trait ToonAgents: Send + Sync {
44    /// Agent config by name, already converted from TOON.
45    fn get(&self, name: &str) -> Option<AgentConfig>;
46    /// Names present in the TOON set.
47    fn names(&self) -> Vec<String>;
48}
49
50pub mod configurable;
51/// External context injection trait (OSS: NoOp, Managed: Eruka/custom).
52pub mod context_provider;
53/// Loop detection for agent outputs — prevents repetitive/stuck agents.
54pub mod loop_detector;
55/// Long-running iteration mode — agents that run on a fixed interval.
56pub mod loop_mode;
57/// Checkpoint/crash recovery — serialize agent state, restore on restart.
58pub mod checkpoint;
59/// Multi-agent orchestration for complex tasks.
60pub mod orchestrator;
61pub mod registry;
62/// Request routing to specialized agents.
63pub mod router;
64/// Per-tenant agent creation from DB-stored configs.
65#[cfg(feature = "postgres")]
66pub mod tenant_agent;
67pub mod memory;
68pub mod research;
69#[cfg(feature = "postgres")]
70pub(crate) mod resolver;
71pub mod external_context;
72pub mod execution;
73pub mod plugins;
74pub mod admit;
75pub mod emergency_stop;
76pub use emergency_stop::EmergencyStop;
77#[cfg(feature = "scheduler")]
78pub mod scheduler;
79#[cfg(feature = "pipeline")]
80pub mod pipeline;
81#[cfg(feature = "trigger")]
82pub mod trigger;
83#[cfg(any(feature = "postgres", feature = "skills"))]
84pub mod skills;
85#[cfg(feature = "workflows")]
86pub mod workflows;
87pub use execution::{
88    request_tenant_ctx, request_user_scope, tenant_scope, user_id_from_ctx, AgentRequest,
89    AgentSource, Execute, ExecutionResult, RunTracker,
90};
91pub use admit::admit;
92pub use plugins::register_plugins;
93pub use external_context::ExternalContext;
94
95use ares_llm::client::TokenUsage;
96use ares_types::types::{AgentContext, AgentType, Result};
97use async_trait::async_trait;
98
99// Re-export commonly used types
100pub use configurable::ConfigurableAgent;
101pub use context_provider::{ContextProvider, ContextProviderHandle, NoOpContextProvider};
102pub use registry::{AgentRegistry, AgentRegistryBuilder};
103#[cfg(feature = "postgres")]
104pub use resolver::TenantId;
105
106/// Response from agent execution, including content and optional token usage
107#[derive(Debug, Clone, Default)]
108pub struct AgentResponse {
109    /// The generated text response
110    pub content: String,
111    /// Token usage from the LLM provider (None if unavailable)
112    pub usage: Option<TokenUsage>,
113    /// Metadata about the execution (model, provider, etc.)
114    pub metadata: Option<ExecutionMetadata>,
115}
116
117/// Metadata about the execution of an agent
118#[derive(Debug, Clone, Default)]
119pub struct ExecutionMetadata {
120    /// The name of the model used
121    pub model_name: String,
122    /// The name of the provider used
123    pub provider_name: String,
124}
125
126/// Base trait for all agents
127#[async_trait]
128pub trait Agent: Send + Sync {
129    /// Execute the agent with given input and context
130    async fn execute(&self, input: &str, context: &AgentContext) -> Result<AgentResponse>;
131
132    /// Get the agent's system prompt
133    fn system_prompt(&self) -> String;
134
135    /// Get the agent type
136    fn agent_type(&self) -> AgentType;
137}