ares/
lib.rs

1//! # A.R.E.S - Agentic Retrieval Enhanced Server
2//!
3//! A production-grade agentic chatbot server built in Rust with multi-provider
4//! LLM support, tool calling, RAG, MCP integration, and advanced research capabilities.
5//!
6//! ## Overview
7//!
8//! A.R.E.S can be used in two ways:
9//!
10//! 1. **As a standalone server** - Run the `ares-server` binary
11//! 2. **As a library** - Import components into your own Rust project
12//!
13//! ## Quick Start (Library Usage)
14//!
15//! Add to your `Cargo.toml`:
16//!
17//! ```toml
18//! [dependencies]
19//! ares-server = "0.2"
20//! ```
21//!
22//! ### Basic Example
23//!
24//! ```rust,ignore
25//! use ares::{Provider, LLMClient};
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
29//!     // Create an Ollama provider
30//!     let provider = Provider::Ollama {
31//!         base_url: "http://localhost:11434".to_string(),
32//!         model: "llama3.2:3b".to_string(),
33//!     };
34//!
35//!     // Create a client and generate a response
36//!     let client = provider.create_client().await?;
37//!     let response = client.generate("Hello, world!").await?;
38//!     println!("{}", response);
39//!
40//!     Ok(())
41//! }
42//! ```
43//!
44//! ### Using Tools
45//!
46//! ```rust,ignore
47//! use ares::{ToolRegistry, tools::calculator::Calculator};
48//! use std::sync::Arc;
49//!
50//! let mut registry = ToolRegistry::new();
51//! registry.register(Arc::new(Calculator));
52//!
53//! // Tools can be used with LLM function calling
54//! let tool_definitions = registry.definitions();
55//! ```
56//!
57//! ### Configuration-Driven Setup
58//!
59//! ```rust,ignore
60//! use ares::{AresConfigManager, AgentRegistry, ProviderRegistry, ToolRegistry};
61//! use std::sync::Arc;
62//!
63//! // Load configuration from ares.toml
64//! let config_manager = AresConfigManager::new("ares.toml")?;
65//! let config = config_manager.config();
66//!
67//! // Create registries from configuration
68//! let provider_registry = Arc::new(ProviderRegistry::from_config(&config));
69//! let tool_registry = Arc::new(ToolRegistry::with_config(&config));
70//! let agent_registry = AgentRegistry::from_config(
71//!     &config,
72//!     provider_registry,
73//!     tool_registry,
74//! );
75//! ```
76//!
77//! ## Feature Flags
78//!
79//! | Feature | Description |
80//! |---------|-------------|
81//! | `ollama` | Ollama local inference (default) |
82//! | `openai` | OpenAI API support |
83//! | `llamacpp` | Direct GGUF model loading |
84//! | `local-db` | Local SQLite database (default) |
85//! | `turso` | Remote Turso database |
86//! | `qdrant` | Qdrant vector database |
87//! | `mcp` | Model Context Protocol support |
88//!
89//! ## Modules
90//!
91//! - [`agents`] - Agent framework for multi-agent orchestration
92//! - [`api`] - REST API handlers and routes
93//! - [`auth`] - JWT authentication and middleware
94//! - [`db`] - Database abstraction (SQLite, Turso)
95//! - [`llm`] - LLM client implementations
96//! - [`tools`] - Tool definitions and registry
97//! - [`workflows`] - Declarative workflow engine
98//! - [`types`] - Common types and error handling
99//!
100//! ## Architecture
101//!
102//! A.R.E.S uses a hybrid configuration system:
103//!
104//! - **TOML** (`ares.toml`): Infrastructure config (server, auth, providers)
105//! - **TOON** (`config/*.toon`): Behavioral config (agents, models, tools)
106//!
107//! Both support hot-reloading for zero-downtime configuration changes.
108
109#![cfg_attr(docsrs, feature(doc_cfg))]
110#![warn(missing_docs)]
111#![warn(rustdoc::missing_crate_level_docs)]
112
113/// AI agent orchestration and management.
114pub mod agents;
115/// HTTP API handlers and routes.
116pub mod api;
117/// JWT authentication and middleware.
118pub mod auth;
119/// Command-line interface and scaffolding.
120pub mod cli;
121/// Database clients (Turso/SQLite, Qdrant).
122pub mod db;
123/// LLM provider clients and abstractions.
124pub mod llm;
125/// Model Context Protocol (MCP) server integration.
126#[cfg(feature = "mcp")]
127pub mod mcp;
128/// Conversation memory and context management.
129pub mod memory;
130/// Retrieval Augmented Generation (RAG) components.
131pub mod rag;
132/// Multi-agent research coordination.
133pub mod research;
134/// Built-in tools (calculator, web search).
135pub mod tools;
136/// Core types (requests, responses, errors).
137pub mod types;
138/// Configuration utilities (TOML, TOON).
139pub mod utils;
140/// Workflow engine for agent orchestration.
141pub mod workflows;
142
143// Re-export commonly used types
144pub use agents::{AgentRegistry, AgentRegistryBuilder};
145pub use db::TursoClient;
146pub use llm::client::LLMClientFactoryTrait;
147pub use llm::{
148    ConfigBasedLLMFactory, LLMClient, LLMClientFactory, LLMResponse, Provider, ProviderRegistry,
149};
150pub use tools::registry::ToolRegistry;
151pub use types::{AppError, Result};
152pub use utils::toml_config::{AresConfig, AresConfigManager};
153pub use utils::toon_config::DynamicConfigManager;
154pub use workflows::{WorkflowEngine, WorkflowOutput, WorkflowStep};
155
156use crate::auth::jwt::AuthService;
157use std::sync::Arc;
158
159/// Application state shared across handlers
160#[derive(Clone)]
161pub struct AppState {
162    /// TOML-based infrastructure configuration with hot-reload support
163    pub config_manager: Arc<AresConfigManager>,
164    /// TOON-based dynamic behavioral configuration with hot-reload support
165    pub dynamic_config: Arc<DynamicConfigManager>,
166    /// Database client
167    pub turso: Arc<TursoClient>,
168    /// LLM client factory (config-based)
169    pub llm_factory: Arc<ConfigBasedLLMFactory>,
170    /// Provider registry for model/provider management
171    pub provider_registry: Arc<ProviderRegistry>,
172    /// Agent registry for creating config-driven agents
173    pub agent_registry: Arc<AgentRegistry>,
174    /// Tool registry for agent tools
175    pub tool_registry: Arc<ToolRegistry>,
176    /// Authentication service
177    pub auth_service: Arc<AuthService>,
178}