a3s_code_core/config/mod.rs
1//! Configuration module for A3S Code
2//!
3//! Provides configuration for:
4//! - LLM providers and models (defaultModel in "provider/model" format, providers)
5//! - Queue configuration (a3s-lane integration)
6//! - Search configuration (a3s-search integration)
7//! - Directories for dynamic skill and agent loading
8//!
9//! Configuration is loaded from ACL-compatible files or strings.
10//! Existing `.acl` config filenames are still accepted for compatibility.
11//! JSON support has been removed.
12
13pub mod agent_dir;
14mod loader;
15mod provider;
16mod search;
17#[cfg(test)]
18mod tests;
19
20pub use agent_dir::{AgentDir, ScheduleSpec, ScriptToolLimits, ScriptToolSpec, ToolSpec};
21pub use provider::{ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
22pub use search::{
23 BrowserBackend, DocumentCacheConfig, DocumentOcrConfig, DocumentParserConfig, HeadlessConfig,
24 SearchConfig, SearchEngineConfig, SearchHealthConfig,
25};
26
27use crate::memory::MemoryConfig;
28use serde::{Deserialize, Serialize};
29use std::path::PathBuf;
30
31// ============================================================================
32// Storage Configuration
33// ============================================================================
34
35/// Session storage backend type
36#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
37#[serde(rename_all = "lowercase")]
38pub enum StorageBackend {
39 /// In-memory storage (no persistence)
40 Memory,
41 /// File-based storage (JSON files)
42 #[default]
43 File,
44 /// Custom external storage (Redis, PostgreSQL, etc.)
45 ///
46 /// Requires a `SessionStore` implementation registered on `AgentSession` options.
47 /// Use `storage_url` in config to pass connection details.
48 Custom,
49}
50
51// ============================================================================
52// Main Configuration
53// ============================================================================
54
55/// Automatic subagent delegation controls.
56#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
57#[serde(default, rename_all = "camelCase")]
58pub struct AutoDelegationConfig {
59 /// Enable runtime-driven automatic child agent delegation.
60 pub enabled: bool,
61 /// Allow automatic delegation to launch multiple child agents in parallel.
62 ///
63 /// Manual `parallel_task` calls remain available when this is false.
64 #[serde(alias = "auto_parallel")]
65 pub auto_parallel: bool,
66 /// Allow model-visible manual `task` and `parallel_task` delegation tools.
67 ///
68 /// Set this to false for cost control or debugging when child-agent tools
69 /// should be absent from the session tool surface. This is not a security
70 /// sandbox: the parent agent may still have other tools such as `bash`,
71 /// MCP tools, or skills.
72 #[serde(alias = "allow_manual_delegation")]
73 pub allow_manual_delegation: bool,
74 /// Minimum local confidence required to auto-delegate a child task.
75 pub min_confidence: f32,
76 /// Maximum number of automatic child tasks per user request.
77 pub max_tasks: usize,
78}
79
80impl Default for AutoDelegationConfig {
81 fn default() -> Self {
82 Self {
83 enabled: false,
84 auto_parallel: true,
85 allow_manual_delegation: true,
86 min_confidence: 0.72,
87 max_tasks: 4,
88 }
89 }
90}
91
92/// Optional A3S OS endpoint used by hosts for account login.
93#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
94#[serde(rename_all = "camelCase")]
95pub struct OsConfig {
96 /// Base address of the user's A3S OS instance.
97 #[serde(alias = "url", alias = "baseUrl", alias = "base_url")]
98 pub address: String,
99}
100
101/// Configuration for A3S Code
102#[derive(Debug, Clone, Serialize, Deserialize, Default)]
103#[serde(rename_all = "camelCase")]
104pub struct CodeConfig {
105 /// Default model in "provider/model" format (e.g., "anthropic/claude-sonnet-4-20250514")
106 #[serde(default, alias = "default_model")]
107 pub default_model: Option<String>,
108
109 /// Provider configurations
110 #[serde(default)]
111 pub providers: Vec<ProviderConfig>,
112
113 /// Session storage backend
114 #[serde(default)]
115 pub storage_backend: StorageBackend,
116
117 /// Sessions directory (for file backend)
118 #[serde(skip_serializing_if = "Option::is_none")]
119 pub sessions_dir: Option<PathBuf>,
120
121 /// Memory directory for the default file-backed memory store.
122 ///
123 /// If unset, sessions use `<workspace>/.a3s/memory` unless the host passes
124 /// an explicit memory store or file memory directory.
125 #[serde(default, alias = "memoryDir", skip_serializing_if = "Option::is_none")]
126 pub memory_dir: Option<PathBuf>,
127
128 /// Connection URL for custom storage backend (e.g., "redis://localhost:6379", "postgres://user:pass@localhost/a3s")
129 #[serde(default, skip_serializing_if = "Option::is_none")]
130 pub storage_url: Option<String>,
131
132 /// Directories to scan for skill files (*.md with tool definitions)
133 #[serde(default, alias = "skill_dirs")]
134 pub skill_dirs: Vec<PathBuf>,
135
136 /// Directories to scan for agent files (*.yaml or *.md)
137 #[serde(default, alias = "agent_dirs")]
138 pub agent_dirs: Vec<PathBuf>,
139
140 /// Maximum tool execution rounds per turn (default: 25)
141 #[serde(default, alias = "max_tool_rounds")]
142 pub max_tool_rounds: Option<usize>,
143
144 /// Maximum sibling branches/tools to run concurrently in bounded parallel fan-out paths.
145 #[serde(default, alias = "max_parallel_tasks")]
146 pub max_parallel_tasks: Option<usize>,
147
148 /// Global automatic child-agent delegation settings.
149 #[serde(default, alias = "auto_delegation")]
150 pub auto_delegation: AutoDelegationConfig,
151
152 /// Convenience global kill switch for automatic parallel child-agent fan-out.
153 ///
154 /// When set, overrides `auto_delegation.auto_parallel`.
155 #[serde(default, alias = "auto_parallel")]
156 pub auto_parallel: Option<bool>,
157
158 /// Thinking/reasoning budget in tokens
159 #[serde(default, alias = "thinking_budget")]
160 pub thinking_budget: Option<usize>,
161
162 /// Per-model API HTTP timeout in milliseconds. Separate from tool execution
163 /// timeouts so provider/network deadlines do not constrain local tools.
164 #[serde(
165 default,
166 alias = "llm_api_timeout_ms",
167 alias = "api_timeout_ms",
168 alias = "model_api_timeout_ms"
169 )]
170 pub llm_api_timeout_ms: Option<u64>,
171
172 /// Memory system configuration
173 #[serde(default, skip_serializing_if = "Option::is_none")]
174 pub memory: Option<MemoryConfig>,
175
176 /// Queue configuration (a3s-lane integration)
177 #[serde(default, skip_serializing_if = "Option::is_none")]
178 pub queue: Option<crate::queue::SessionQueueConfig>,
179
180 /// Search configuration (a3s-search integration)
181 #[serde(default, skip_serializing_if = "Option::is_none")]
182 pub search: Option<SearchConfig>,
183
184 /// Optional A3S OS endpoint. When set, hosts may enable account login.
185 #[serde(default, skip_serializing_if = "Option::is_none")]
186 pub os: Option<OsConfig>,
187
188 /// Built-in document context extraction configuration.
189 #[serde(default, skip_serializing_if = "Option::is_none")]
190 pub document_parser: Option<DocumentParserConfig>,
191
192 /// MCP server configurations
193 #[serde(default, alias = "mcp_servers")]
194 pub mcp_servers: Vec<crate::mcp::McpServerConfig>,
195}