1use super::SessionOptions;
8use crate::prompts::{PlanningMode, SystemPromptSlots};
9use crate::queue::SessionQueueConfig;
10use crate::subagent::WorkerAgentSpec;
11use a3s_memory::MemoryStore;
12use std::path::PathBuf;
13use std::sync::Arc;
14
15impl std::fmt::Debug for SessionOptions {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 f.debug_struct("SessionOptions")
18 .field("model", &self.model)
19 .field("agent_dirs", &self.agent_dirs)
20 .field("worker_agents", &self.worker_agents.len())
21 .field("skill_dirs", &self.skill_dirs)
22 .field("queue_config", &self.queue_config)
23 .field("security_provider", &self.security_provider.is_some())
24 .field("llm_client", &self.llm_client.is_some())
25 .field("context_providers", &self.context_providers.len())
26 .field("confirmation_manager", &self.confirmation_manager.is_some())
27 .field("permission_checker", &self.permission_checker.is_some())
28 .field("permission_policy", &self.permission_policy.is_some())
29 .field("planning_mode", &self.planning_mode)
30 .field("goal_tracking", &self.goal_tracking)
31 .field(
32 "skill_registry",
33 &self
34 .skill_registry
35 .as_ref()
36 .map(|r| format!("{} skills", r.len())),
37 )
38 .field(
39 "enforce_active_skill_tool_restrictions",
40 &self.enforce_active_skill_tool_restrictions,
41 )
42 .field("memory_store", &self.memory_store.is_some())
43 .field("file_memory_dir", &self.file_memory_dir)
44 .field("session_store", &self.session_store.is_some())
45 .field("file_session_store_dir", &self.file_session_store_dir)
46 .field("session_id", &self.session_id)
47 .field("rl_trajectory", &self.rl_trajectory)
48 .field("llm_logprobs", &self.llm_logprobs)
49 .field("llm_top_logprobs", &self.llm_top_logprobs)
50 .field("auto_save", &self.auto_save)
51 .field("artifact_store_limits", &self.artifact_store_limits)
52 .field("max_parse_retries", &self.max_parse_retries)
53 .field("tool_timeout_ms", &self.tool_timeout_ms)
54 .field("llm_api_timeout_ms", &self.llm_api_timeout_ms)
55 .field("circuit_breaker_threshold", &self.circuit_breaker_threshold)
56 .field(
57 "duplicate_tool_call_threshold",
58 &self.duplicate_tool_call_threshold,
59 )
60 .field("sandbox_handle", &self.sandbox_handle.is_some())
61 .field("workspace_services", &self.workspace_services.is_some())
62 .field("auto_compact", &self.auto_compact)
63 .field("auto_compact_threshold", &self.auto_compact_threshold)
64 .field("max_context_tokens", &self.max_context_tokens)
65 .field("continuation_enabled", &self.continuation_enabled)
66 .field("max_continuation_turns", &self.max_continuation_turns)
67 .field("mcp_manager", &self.mcp_manager.is_some())
68 .field("temperature", &self.temperature)
69 .field("thinking_budget", &self.thinking_budget)
70 .field("max_tool_rounds", &self.max_tool_rounds)
71 .field("max_parallel_tasks", &self.max_parallel_tasks)
72 .field("auto_delegation", &self.auto_delegation)
73 .field("manual_delegation_enabled", &self.manual_delegation_enabled)
74 .field("auto_parallel_delegation", &self.auto_parallel_delegation)
75 .field("prompt_slots", &self.prompt_slots.is_some())
76 .finish()
77 }
78}
79
80impl SessionOptions {
81 pub fn new() -> Self {
82 Self::default()
83 }
84
85 pub fn with_model(mut self, model: impl Into<String>) -> Self {
86 self.model = Some(model.into());
87 self
88 }
89
90 pub fn with_agent_dir(mut self, dir: impl Into<PathBuf>) -> Self {
91 self.agent_dirs.push(dir.into());
92 self
93 }
94
95 pub fn with_worker_agent(mut self, spec: WorkerAgentSpec) -> Self {
97 self.worker_agents.push(spec);
98 self
99 }
100
101 pub fn with_worker_agents<I>(mut self, specs: I) -> Self
103 where
104 I: IntoIterator<Item = WorkerAgentSpec>,
105 {
106 self.worker_agents.extend(specs);
107 self
108 }
109
110 pub fn with_queue_config(mut self, config: SessionQueueConfig) -> Self {
111 self.queue_config = Some(config);
112 self
113 }
114
115 pub fn with_default_security(mut self) -> Self {
117 self.security_provider = Some(Arc::new(crate::security::DefaultSecurityProvider::new()));
118 self
119 }
120
121 pub fn with_security_provider(
123 mut self,
124 provider: Arc<dyn crate::security::SecurityProvider>,
125 ) -> Self {
126 self.security_provider = Some(provider);
127 self
128 }
129
130 pub fn with_llm_client(mut self, client: Arc<dyn crate::llm::LlmClient>) -> Self {
138 self.llm_client = Some(client);
139 self
140 }
141
142 pub fn with_fs_context(mut self, root_path: impl Into<PathBuf>) -> Self {
144 let config = crate::context::FileSystemContextConfig::new(root_path);
145 self.context_providers
146 .push(Arc::new(crate::context::FileSystemContextProvider::new(
147 config,
148 )));
149 self
150 }
151
152 pub fn with_context_provider(
154 mut self,
155 provider: Arc<dyn crate::context::ContextProvider>,
156 ) -> Self {
157 self.context_providers.push(provider);
158 self
159 }
160
161 pub fn with_confirmation_manager(
163 mut self,
164 manager: Arc<dyn crate::hitl::ConfirmationProvider>,
165 ) -> Self {
166 self.confirmation_manager = Some(manager);
167 self
168 }
169
170 pub fn with_confirmation_policy(mut self, policy: crate::hitl::ConfirmationPolicy) -> Self {
175 self.confirmation_policy = Some(policy);
176 self
177 }
178
179 pub fn with_permission_policy(mut self, policy: crate::permissions::PermissionPolicy) -> Self {
181 self.permission_checker = Some(Arc::new(policy.clone()));
182 self.permission_policy = Some(policy);
183 self
184 }
185
186 pub fn with_permission_checker(
188 mut self,
189 checker: Arc<dyn crate::permissions::PermissionChecker>,
190 ) -> Self {
191 self.permission_checker = Some(checker);
192 self
193 }
194
195 pub fn with_planning_mode(mut self, mode: PlanningMode) -> Self {
197 self.planning_mode = mode;
198 self
199 }
200
201 pub fn with_planning(mut self, enabled: bool) -> Self {
203 self.planning_mode = if enabled {
204 PlanningMode::Enabled
205 } else {
206 PlanningMode::Disabled
207 };
208 self
209 }
210
211 pub fn with_goal_tracking(mut self, enabled: bool) -> Self {
213 self.goal_tracking = enabled;
214 self
215 }
216
217 pub fn with_builtin_skills(mut self) -> Self {
223 self.skill_registry = Some(Arc::new(crate::skills::SkillRegistry::with_builtins()));
224 self
225 }
226
227 pub fn with_skill_registry(mut self, registry: Arc<crate::skills::SkillRegistry>) -> Self {
229 self.skill_registry = Some(registry);
230 self
231 }
232
233 pub fn with_active_skill_tool_restrictions(mut self, enabled: bool) -> Self {
238 self.enforce_active_skill_tool_restrictions = Some(enabled);
239 self
240 }
241
242 pub fn with_skill_dirs(mut self, dirs: impl IntoIterator<Item = impl Into<PathBuf>>) -> Self {
245 self.skill_dirs.extend(dirs.into_iter().map(Into::into));
246 self
247 }
248
249 pub fn with_skills_from_dir(mut self, dir: impl AsRef<std::path::Path>) -> Self {
251 let registry = self
252 .skill_registry
253 .unwrap_or_else(|| Arc::new(crate::skills::SkillRegistry::new()));
254 if let Err(e) = registry.load_from_dir(&dir) {
255 tracing::warn!(
256 dir = %dir.as_ref().display(),
257 error = %e,
258 "Failed to load skills from directory — continuing without them"
259 );
260 }
261 self.skill_registry = Some(registry);
262 self
263 }
264
265 pub fn with_memory(mut self, store: Arc<dyn MemoryStore>) -> Self {
269 self.memory_store = Some(store);
270 self.file_memory_dir = None;
271 self
272 }
273
274 pub fn with_file_memory(mut self, dir: impl Into<PathBuf>) -> Self {
280 self.memory_store = None;
281 self.file_memory_dir = Some(dir.into());
282 self
283 }
284
285 pub fn with_session_store(mut self, store: Arc<dyn crate::store::SessionStore>) -> Self {
287 self.session_store = Some(store);
288 self.file_session_store_dir = None;
289 self
290 }
291
292 pub fn with_file_session_store(mut self, dir: impl Into<PathBuf>) -> Self {
297 self.session_store = None;
298 self.file_session_store_dir = Some(dir.into());
299 self
300 }
301
302 pub fn with_session_id(mut self, id: impl Into<String>) -> Self {
304 self.session_id = Some(id.into());
305 self
306 }
307
308 pub fn with_tenant_id(mut self, tenant: impl Into<String>) -> Self {
311 self.tenant_id = Some(tenant.into());
312 self
313 }
314
315 pub fn with_principal(mut self, principal: impl Into<String>) -> Self {
318 self.principal = Some(principal.into());
319 self
320 }
321
322 pub fn with_agent_template_id(mut self, template_id: impl Into<String>) -> Self {
325 self.agent_template_id = Some(template_id.into());
326 self
327 }
328
329 pub fn with_correlation_id(mut self, corr: impl Into<String>) -> Self {
332 self.correlation_id = Some(corr.into());
333 self
334 }
335
336 pub fn with_budget_guard(mut self, guard: Arc<dyn crate::budget::BudgetGuard>) -> Self {
341 self.budget_guard = Some(guard);
342 self
343 }
344
345 pub fn with_host_env(mut self, env: Arc<crate::host_env::HostEnv>) -> Self {
351 self.host_env = Some(env);
352 self
353 }
354
355 pub fn with_retention_limits(
365 mut self,
366 limits: crate::retention::SessionRetentionLimits,
367 ) -> Self {
368 self.retention_limits = Some(limits);
369 self
370 }
371
372 pub fn with_rl_trajectory(mut self, config: crate::rl_trajectory::RlTrajectoryConfig) -> Self {
378 self.rl_trajectory = Some(config);
379 self
380 }
381
382 pub fn with_llm_logprobs(mut self, enabled: bool) -> Self {
384 self.llm_logprobs = Some(enabled);
385 self
386 }
387
388 pub fn with_llm_top_logprobs(mut self, top_logprobs: usize) -> Self {
390 self.llm_logprobs = Some(true);
391 self.llm_top_logprobs = Some(top_logprobs);
392 self
393 }
394
395 pub fn with_auto_save(mut self, enabled: bool) -> Self {
397 self.auto_save = enabled;
398 self
399 }
400
401 pub fn with_artifact_store_limits(mut self, limits: crate::tools::ArtifactStoreLimits) -> Self {
403 self.artifact_store_limits = Some(limits);
404 self
405 }
406
407 pub fn with_parse_retries(mut self, max: u32) -> Self {
413 self.max_parse_retries = Some(max);
414 self
415 }
416
417 pub fn with_tool_timeout(mut self, timeout_ms: u64) -> Self {
423 self.tool_timeout_ms = Some(timeout_ms);
424 self
425 }
426
427 pub fn with_llm_api_timeout(mut self, timeout_ms: u64) -> Self {
433 self.llm_api_timeout_ms = Some(timeout_ms);
434 self
435 }
436
437 pub fn with_circuit_breaker(mut self, threshold: u32) -> Self {
443 self.circuit_breaker_threshold = Some(threshold);
444 self
445 }
446
447 pub fn with_duplicate_tool_call_threshold(mut self, threshold: u32) -> Self {
453 self.duplicate_tool_call_threshold = Some(threshold.max(1));
454 self
455 }
456
457 pub fn with_resilience_defaults(self) -> Self {
463 self.with_parse_retries(2)
464 .with_tool_timeout(120_000)
465 .with_circuit_breaker(3)
466 }
467
468 pub fn with_sandbox_handle(mut self, handle: Arc<dyn crate::sandbox::BashSandbox>) -> Self {
476 self.sandbox_handle = Some(handle);
477 self
478 }
479
480 pub fn with_workspace_backend(
486 mut self,
487 services: Arc<crate::workspace::WorkspaceServices>,
488 ) -> Self {
489 self.workspace_services = Some(services);
490 self
491 }
492
493 pub fn with_auto_compact(mut self, enabled: bool) -> Self {
498 self.auto_compact = enabled;
499 self
500 }
501
502 pub fn with_auto_compact_threshold(mut self, threshold: f32) -> Self {
504 self.auto_compact_threshold = Some(threshold.clamp(0.0, 1.0));
505 self
506 }
507
508 pub fn with_max_context_tokens(mut self, tokens: usize) -> Self {
510 self.max_context_tokens = Some(tokens);
511 self
512 }
513
514 pub fn with_continuation(mut self, enabled: bool) -> Self {
519 self.continuation_enabled = Some(enabled);
520 self
521 }
522
523 pub fn with_max_continuation_turns(mut self, turns: u32) -> Self {
525 self.max_continuation_turns = Some(turns);
526 self
527 }
528
529 pub fn with_mcp(mut self, manager: Arc<crate::mcp::manager::McpManager>) -> Self {
536 self.mcp_manager = Some(manager);
537 self
538 }
539
540 pub fn with_temperature(mut self, temperature: f32) -> Self {
541 self.temperature = Some(temperature);
542 self
543 }
544
545 pub fn with_thinking_budget(mut self, budget: usize) -> Self {
546 self.thinking_budget = Some(budget);
547 self
548 }
549
550 pub fn with_max_tool_rounds(mut self, rounds: usize) -> Self {
555 self.max_tool_rounds = Some(rounds);
556 self
557 }
558
559 pub fn with_max_parallel_tasks(mut self, tasks: usize) -> Self {
561 self.max_parallel_tasks = Some(tasks.max(1));
562 self
563 }
564
565 pub fn with_auto_delegation(mut self, config: crate::config::AutoDelegationConfig) -> Self {
567 self.auto_delegation = Some(config);
568 self
569 }
570
571 pub fn with_auto_delegation_enabled(mut self, enabled: bool) -> Self {
573 let mut config = self.auto_delegation.take().unwrap_or_default();
574 config.enabled = enabled;
575 self.auto_delegation = Some(config);
576 self
577 }
578
579 pub fn with_manual_delegation_enabled(mut self, enabled: bool) -> Self {
586 if let Some(config) = &mut self.auto_delegation {
587 config.allow_manual_delegation = enabled;
588 }
589 self.manual_delegation_enabled = Some(enabled);
590 self
591 }
592
593 pub fn with_auto_parallel_delegation(mut self, enabled: bool) -> Self {
597 if let Some(config) = &mut self.auto_delegation {
598 config.auto_parallel = enabled;
599 }
600 self.auto_parallel_delegation = Some(enabled);
601 self
602 }
603
604 pub fn with_prompt_slots(mut self, slots: SystemPromptSlots) -> Self {
609 self.prompt_slots = Some(slots);
610 self
611 }
612
613 pub fn with_hook_executor(mut self, executor: Arc<dyn crate::hooks::HookExecutor>) -> Self {
618 self.hook_executor = Some(executor);
619 self
620 }
621}