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};
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}
51impl TurnRunOptions {
52    /// Select a model with default generation, limits and no preparation or observer.
53    pub fn new(model: ModelRef) -> Self {
54        Self {
55            model,
56            generation: GenerationOptions::default(),
57            cache: CacheDirective::None,
58            limits: TurnLimits::default(),
59            preparer: None,
60            observer: None,
61        }
62    }
63
64    /// Replaces the generation parameters used by every invocation.
65    pub fn with_generation(mut self, generation: GenerationOptions) -> Self {
66        self.generation = generation;
67        self
68    }
69
70    /// Replaces the provider cache instruction.
71    pub fn with_cache(mut self, cache: CacheDirective) -> Self {
72        self.cache = cache;
73        self
74    }
75
76    /// Replaces the execution limits.
77    pub fn with_limits(mut self, limits: TurnLimits) -> Self {
78        self.limits = limits;
79        self
80    }
81
82    /// Sets the exclusive material preparation before each invocation.
83    pub fn with_preparer(mut self, preparer: Arc<dyn ContextPreparer>) -> Self {
84        self.preparer = Some(preparer);
85        self
86    }
87
88    /// Sets the synchronous borrowed observation callback.
89    pub fn with_observer(mut self, observer: Arc<RunObserver>) -> Self {
90        self.observer = Some(observer);
91        self
92    }
93}