Skip to main content

aither_agent/
config.rs

1//! Agent configuration.
2
3use std::time::Duration;
4
5use aither_core::llm::model::Parameters;
6
7use crate::compression::ContextStrategy;
8
9/// Agent specialization mode.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
11pub enum AgentKind {
12    /// Coding-focused agent (loads workspace facts like AGENT.md/CLAUDE.md).
13    #[default]
14    Coding,
15    /// Generic chat assistant (no coding workspace-fact loading).
16    Chatbot,
17}
18
19/// Prompt-level context assembly settings.
20#[derive(Debug, Clone)]
21pub struct ContextAssemblerConfig {
22    /// Fraction of context reserved for static/system blocks.
23    pub static_budget_fraction: f32,
24    /// Usage threshold to request handoff summary.
25    pub handoff_threshold: f32,
26    /// Reassemble ephemeral context when no LLM request has been sent for this long.
27    pub idle_reassemble_after: Duration,
28    /// Instruction injected near context exhaustion.
29    pub handoff_instruction: String,
30}
31
32impl Default for ContextAssemblerConfig {
33    fn default() -> Self {
34        Self {
35            static_budget_fraction: 0.2,
36            handoff_threshold: 0.9,
37            idle_reassemble_after: Duration::from_secs(300),
38            handoff_instruction: "Your context window is nearly exhausted. Generate a concise handoff summary now, preserving current goals, constraints, file paths, pending tasks, and immediate next actions.".to_string(),
39        }
40    }
41}
42
43/// Configuration for agent behavior.
44#[derive(Debug, Clone)]
45pub struct AgentConfig {
46    /// Maximum number of agent loop iterations.
47    pub max_iterations: usize,
48
49    /// Context management strategy.
50    pub context: ContextStrategy,
51
52    /// Generic system prompt content.
53    pub system_prompt: Option<String>,
54
55    /// Optional persona overlay.
56    pub persona_prompt: Option<String>,
57
58    /// Agent specialization (coding vs chatbot).
59    pub agent_kind: AgentKind,
60
61    /// Optional transcript path for long-memory recovery.
62    pub transcript_path: Option<String>,
63
64    /// Context assembly behavior.
65    pub context_assembler: ContextAssemblerConfig,
66
67    /// Tool turns tolerated before an unmaintained `tasks.md` earns a
68    /// staleness alert.
69    ///
70    /// A turn counts toward the limit when it ran tool calls but left
71    /// `tasks.md` byte-identical — either still holding unchecked items or
72    /// missing entirely. Set to `usize::MAX` to disable the alert.
73    pub tasks_stale_after_turns: usize,
74
75    /// Request-level model parameters applied to each LLM call.
76    pub request_parameters: Parameters,
77}
78
79impl Default for AgentConfig {
80    fn default() -> Self {
81        Self {
82            max_iterations: 10_000,
83            context: ContextStrategy::default(),
84            system_prompt: None,
85            persona_prompt: None,
86            agent_kind: AgentKind::default(),
87            transcript_path: None,
88            context_assembler: ContextAssemblerConfig::default(),
89            tasks_stale_after_turns: 4,
90            request_parameters: Parameters::default(),
91        }
92    }
93}
94
95impl AgentConfig {
96    /// Creates a new configuration with default values.
97    #[must_use]
98    pub fn new() -> Self {
99        Self::default()
100    }
101
102    /// Sets the maximum number of iterations.
103    #[must_use]
104    pub const fn with_max_iterations(mut self, limit: usize) -> Self {
105        self.max_iterations = limit;
106        self
107    }
108
109    /// Sets the context strategy.
110    #[must_use]
111    pub const fn with_context(mut self, strategy: ContextStrategy) -> Self {
112        self.context = strategy;
113        self
114    }
115
116    /// Sets the system prompt.
117    #[must_use]
118    pub fn with_system_prompt(mut self, prompt: impl Into<String>) -> Self {
119        self.system_prompt = Some(prompt.into());
120        self
121    }
122
123    /// Sets the persona prompt.
124    #[must_use]
125    pub fn with_persona_prompt(mut self, prompt: impl Into<String>) -> Self {
126        self.persona_prompt = Some(prompt.into());
127        self
128    }
129
130    /// Sets the agent kind.
131    #[must_use]
132    pub const fn with_agent_kind(mut self, kind: AgentKind) -> Self {
133        self.agent_kind = kind;
134        self
135    }
136
137    /// Sets a transcript path for memory recovery.
138    #[must_use]
139    pub fn with_transcript_path(mut self, path: impl Into<String>) -> Self {
140        self.transcript_path = Some(path.into());
141        self
142    }
143
144    /// Sets the idle gap after which ephemeral context should be reassembled.
145    #[must_use]
146    pub const fn with_idle_reassemble_after(mut self, idle_reassemble_after: Duration) -> Self {
147        self.context_assembler.idle_reassemble_after = idle_reassemble_after;
148        self
149    }
150
151    /// Sets default request-level model parameters for each LLM call.
152    #[must_use]
153    pub fn with_request_parameters(mut self, parameters: Parameters) -> Self {
154        self.request_parameters = parameters;
155        self
156    }
157}