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