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