Skip to main content

causa_runtime/
config.rs

1//! Per-run choices for the minimal runner.
2
3use crate::RunObserver;
4use causa_kernel::{CacheDirective, ContextPreparer, GenerationOptions, ModelRef, ProcessorData};
5use std::sync::Arc;
6
7/// Numeric limits for one execution.
8#[derive(Debug, Clone, Copy)]
9#[non_exhaustive]
10pub struct TurnLimits {
11    /// Maximum number of logical model invocations, including the first.
12    pub max_model_rounds: u32,
13    /// Maximum cumulative number of model tool declarations.
14    pub max_tool_calls: u32,
15}
16impl TurnLimits {
17    /// Limits on model rounds and on tool calls for one run.
18    pub fn new(max_model_rounds: u32, max_tool_calls: u32) -> Self {
19        Self {
20            max_model_rounds,
21            max_tool_calls,
22        }
23    }
24}
25impl Default for TurnLimits {
26    fn default() -> Self {
27        Self {
28            max_model_rounds: 10,
29            max_tool_calls: 64,
30        }
31    }
32}
33
34/// Choices fixed for one run; the model must be supplied explicitly.
35#[derive(Clone)]
36#[non_exhaustive]
37pub struct TurnRunOptions {
38    /// Model used by every logical invocation.
39    pub model: ModelRef,
40    /// Generation parameters used by every logical invocation.
41    pub generation: GenerationOptions,
42    /// Provider cache instruction.
43    pub cache: CacheDirective,
44    /// Execution limits.
45    pub limits: TurnLimits,
46    /// Optional exclusive material preparation before each invocation.
47    pub preparer: Option<Arc<dyn ContextPreparer>>,
48    /// Optional synchronous borrowed observation callback.
49    pub observer: Option<Arc<RunObserver>>,
50    /// Optional host data handed to every tool processor of the run, through
51    /// [`causa_kernel::ProcessorContext::data`]. Passed through unchanged:
52    /// state that changes during the run belongs in a shared handle.
53    pub processor_data: Option<ProcessorData>,
54}
55impl TurnRunOptions {
56    /// Select a model with default generation, limits and no preparation,
57    /// observer or processor data.
58    pub fn new(model: ModelRef) -> Self {
59        Self {
60            model,
61            generation: GenerationOptions::default(),
62            cache: CacheDirective::None,
63            limits: TurnLimits::default(),
64            preparer: None,
65            observer: None,
66            processor_data: None,
67        }
68    }
69
70    /// Replaces the generation parameters used by every invocation.
71    pub fn with_generation(mut self, generation: GenerationOptions) -> Self {
72        self.generation = generation;
73        self
74    }
75
76    /// Replaces the provider cache instruction.
77    pub fn with_cache(mut self, cache: CacheDirective) -> Self {
78        self.cache = cache;
79        self
80    }
81
82    /// Replaces the execution limits.
83    pub fn with_limits(mut self, limits: TurnLimits) -> Self {
84        self.limits = limits;
85        self
86    }
87
88    /// Sets the exclusive material preparation before each invocation.
89    pub fn with_preparer(mut self, preparer: Arc<dyn ContextPreparer>) -> Self {
90        self.preparer = Some(preparer);
91        self
92    }
93
94    /// Sets the synchronous borrowed observation callback.
95    pub fn with_observer(mut self, observer: Arc<RunObserver>) -> Self {
96        self.observer = Some(observer);
97        self
98    }
99
100    /// Sets the host data handed to every tool processor of the run.
101    pub fn with_processor_data(mut self, processor_data: ProcessorData) -> Self {
102        self.processor_data = Some(processor_data);
103        self
104    }
105}