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    /// Request-level model parameters applied to each LLM call.
68    pub request_parameters: Parameters,
69}
70
71impl Default for AgentConfig {
72    fn default() -> Self {
73        Self {
74            max_iterations: 10_000,
75            context: ContextStrategy::default(),
76            system_prompt: None,
77            persona_prompt: None,
78            agent_kind: AgentKind::default(),
79            transcript_path: None,
80            context_assembler: ContextAssemblerConfig::default(),
81            request_parameters: Parameters::default(),
82        }
83    }
84}
85
86impl AgentConfig {
87    /// Creates a new configuration with default values.
88    #[must_use]
89    pub fn new() -> Self {
90        Self::default()
91    }
92
93    /// Sets the maximum number of iterations.
94    #[must_use]
95    pub const fn with_max_iterations(mut self, limit: usize) -> Self {
96        self.max_iterations = limit;
97        self
98    }
99
100    /// Sets the context strategy.
101    #[must_use]
102    pub const fn with_context(mut self, strategy: ContextStrategy) -> Self {
103        self.context = strategy;
104        self
105    }
106
107    /// Sets the system prompt.
108    #[must_use]
109    pub fn with_system_prompt(mut self, prompt: impl Into<String>) -> Self {
110        self.system_prompt = Some(prompt.into());
111        self
112    }
113
114    /// Sets the persona prompt.
115    #[must_use]
116    pub fn with_persona_prompt(mut self, prompt: impl Into<String>) -> Self {
117        self.persona_prompt = Some(prompt.into());
118        self
119    }
120
121    /// Sets the agent kind.
122    #[must_use]
123    pub const fn with_agent_kind(mut self, kind: AgentKind) -> Self {
124        self.agent_kind = kind;
125        self
126    }
127
128    /// Sets a transcript path for memory recovery.
129    #[must_use]
130    pub fn with_transcript_path(mut self, path: impl Into<String>) -> Self {
131        self.transcript_path = Some(path.into());
132        self
133    }
134
135    /// Sets the idle gap after which ephemeral context should be reassembled.
136    #[must_use]
137    pub const fn with_idle_reassemble_after(mut self, idle_reassemble_after: Duration) -> Self {
138        self.context_assembler.idle_reassemble_after = idle_reassemble_after;
139        self
140    }
141
142    /// Sets default request-level model parameters for each LLM call.
143    #[must_use]
144    pub fn with_request_parameters(mut self, parameters: Parameters) -> Self {
145        self.request_parameters = parameters;
146        self
147    }
148}