Skip to main content

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