starweaver_runtime/agent/
overrides.rs1use std::sync::Arc;
4
5use starweaver_context::ToolConfig;
6use starweaver_model::{ModelAdapter, ModelRequestParameters, ModelSettings};
7use starweaver_tools::{DynTool, DynToolset, ToolRegistry};
8
9use starweaver_usage::UsageLimits;
10
11use crate::{
12 agent::{Agent, AgentRuntimePolicy},
13 capability::{AgentCapability, CapabilityBundle},
14 executor::DynAgentExecutor,
15 instructions::DynDynamicInstruction,
16 output::{DynOutputFunction, OutputPolicy, OutputSchema, OutputValidator},
17};
18
19pub struct AgentOverride {
21 agent: Agent,
22}
23
24impl AgentOverride {
25 pub(super) const fn new(agent: Agent) -> Self {
26 Self { agent }
27 }
28
29 #[must_use]
31 pub fn model(mut self, model: Arc<dyn ModelAdapter>) -> Self {
32 self.agent.model = model;
33 self
34 }
35
36 #[must_use]
38 pub fn model_settings(mut self, settings: Option<ModelSettings>) -> Self {
39 self.agent.model_settings = settings;
40 self
41 }
42
43 #[must_use]
45 pub fn request_params(mut self, params: ModelRequestParameters) -> Self {
46 self.agent.request_params = params;
47 self
48 }
49
50 #[must_use]
52 pub fn tool_config(mut self, tool_config: Option<ToolConfig>) -> Self {
53 self.agent.tool_config = tool_config;
54 self
55 }
56
57 #[must_use]
59 pub fn with_tools(mut self, tools: ToolRegistry) -> Self {
60 self.agent.tools = tools;
61 self.agent.toolsets.clear();
62 self
63 }
64
65 #[must_use]
67 pub fn tool(mut self, tool: DynTool) -> Self {
68 self.agent.tools.insert(tool);
69 self
70 }
71
72 #[must_use]
74 pub fn toolset(mut self, toolset: &DynToolset) -> Self {
75 self.agent.toolsets.push(toolset.clone());
76 self
77 }
78
79 #[must_use]
81 pub fn append_tools(mut self, tools: &ToolRegistry) -> Self {
82 self.agent.tools.insert_registry(tools);
83 self
84 }
85
86 #[must_use]
88 pub const fn usage_limits(mut self, limits: Option<UsageLimits>) -> Self {
89 self.agent.usage_limits = limits;
90 self
91 }
92
93 #[must_use]
95 pub fn with_instructions(mut self, instructions: Vec<String>) -> Self {
96 self.agent.instructions = instructions;
97 self
98 }
99
100 #[must_use]
102 pub fn append_instructions(mut self, instructions: impl IntoIterator<Item = String>) -> Self {
103 self.agent.instructions.extend(instructions);
104 self
105 }
106
107 #[must_use]
109 pub fn dynamic_instructions(mut self, instructions: Vec<DynDynamicInstruction>) -> Self {
110 self.agent.dynamic_instructions = instructions;
111 self
112 }
113
114 #[must_use]
116 pub fn output_schema(mut self, schema: Option<OutputSchema>) -> Self {
117 self.agent.output_schema = schema;
118 self
119 }
120
121 #[must_use]
123 pub fn output_policy(mut self, policy: OutputPolicy) -> Self {
124 self.agent = self.agent.with_output_policy(policy);
125 self
126 }
127
128 #[must_use]
130 pub fn output_validators(mut self, validators: Vec<Arc<dyn OutputValidator>>) -> Self {
131 self.agent.output_validators = validators;
132 self
133 }
134
135 #[must_use]
137 pub fn output_functions(mut self, functions: Vec<DynOutputFunction>) -> Self {
138 self.agent.output_functions = functions;
139 self
140 }
141
142 #[must_use]
144 pub fn capabilities(mut self, capabilities: Vec<Arc<dyn AgentCapability>>) -> Self {
145 self.agent.capabilities = capabilities;
146 self
147 }
148
149 #[must_use]
151 pub fn executor(mut self, executor: DynAgentExecutor) -> Self {
152 self.agent.executor = executor;
153 self
154 }
155
156 #[must_use]
158 pub fn capability_bundle(mut self, bundle: &dyn CapabilityBundle) -> Self {
159 self.agent = self.agent.with_capability_bundle(bundle);
160 self
161 }
162
163 #[must_use]
165 pub const fn policy(mut self, policy: AgentRuntimePolicy) -> Self {
166 self.agent.policy = policy;
167 self
168 }
169
170 #[must_use]
172 pub fn build(self) -> Agent {
173 self.agent
174 }
175}