Skip to main content

astrid_runtime/runtime/
config.rs

1//! Runtime configuration types and defaults.
2
3use astrid_tools::SparkConfig;
4use astrid_workspace::WorkspaceConfig;
5use std::path::PathBuf;
6
7use crate::subagent_executor::DEFAULT_SUBAGENT_TIMEOUT;
8
9/// Default maximum context tokens (100k).
10pub(super) const DEFAULT_MAX_CONTEXT_TOKENS: usize = 100_000;
11/// Default number of recent messages to keep when summarizing.
12pub(super) const DEFAULT_KEEP_RECENT_COUNT: usize = 10;
13
14/// Default maximum concurrent sub-agents.
15pub(super) const DEFAULT_MAX_CONCURRENT_SUBAGENTS: usize = 4;
16/// Default maximum sub-agent nesting depth.
17pub(super) const DEFAULT_MAX_SUBAGENT_DEPTH: usize = 3;
18
19/// Configuration for the agent runtime.
20#[derive(Debug, Clone)]
21pub struct RuntimeConfig {
22    /// Maximum context tokens.
23    pub max_context_tokens: usize,
24    /// System prompt.
25    pub system_prompt: String,
26    /// Whether to auto-summarize on context overflow.
27    pub auto_summarize: bool,
28    /// Number of recent messages to keep when summarizing.
29    pub keep_recent_count: usize,
30    /// Workspace configuration for operational boundaries.
31    pub workspace: WorkspaceConfig,
32    /// Maximum concurrent sub-agents.
33    pub max_concurrent_subagents: usize,
34    /// Maximum sub-agent nesting depth.
35    pub max_subagent_depth: usize,
36    /// Default sub-agent timeout.
37    pub default_subagent_timeout: std::time::Duration,
38    /// Static spark seed from `[spark]` in config (fallback when spark.toml missing).
39    pub spark_seed: Option<SparkConfig>,
40    /// Path to the living spark file (`~/.astrid/spark.toml`).
41    ///
42    /// **Note:** When a spark identity is configured (either from this file or
43    /// from `spark_seed`), the spark preamble is prepended to the system prompt
44    /// on every LLM call for non-sub-agent sessions. If `system_prompt` is set
45    /// to a custom value, the spark preamble is still prepended. Sub-agent
46    /// sessions skip spark injection to avoid double-identity conflicts.
47    pub spark_file: Option<PathBuf>,
48}
49
50impl Default for RuntimeConfig {
51    fn default() -> Self {
52        let workspace_root = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
53        Self {
54            max_context_tokens: DEFAULT_MAX_CONTEXT_TOKENS,
55            system_prompt: String::new(),
56            auto_summarize: true,
57            keep_recent_count: DEFAULT_KEEP_RECENT_COUNT,
58            workspace: WorkspaceConfig::new(workspace_root),
59            max_concurrent_subagents: DEFAULT_MAX_CONCURRENT_SUBAGENTS,
60            max_subagent_depth: DEFAULT_MAX_SUBAGENT_DEPTH,
61            default_subagent_timeout: DEFAULT_SUBAGENT_TIMEOUT,
62            spark_seed: None,
63            spark_file: None,
64        }
65    }
66}