Skip to main content

strands_harness/
config.rs

1//! Portable harness configuration.
2//!
3//! [`HarnessAgentOptions`](crate::HarnessAgentOptions) is the runtime API and takes live SDK
4//! objects; [`HarnessAgentConfig`] is the JSON form of the same agent definition, shared with the
5//! other Strands harnesses. Live values are module references there, which Rust cannot load yet:
6//! [`harness_agent_options_from_config`] rejects them with a clear error.
7
8mod options;
9mod validate;
10
11use std::fmt;
12use std::str::FromStr;
13use std::sync::LazyLock;
14
15use serde::ser::SerializeMap;
16use serde::{Deserialize, Serialize, Serializer};
17use strands::types::JsonObject;
18
19use crate::defaults::{DEFAULT_BUILTIN_PLUGINS, DEFAULT_BUILTIN_TOOLS, DEFAULT_EFFORT, DEFAULT_MODEL};
20use crate::types::{
21    Effort, ProgrammaticToolCallerConfig, ReadConfig, SessionConfig, Setting, ShellConfig, SubagentConfig,
22    WebFetchTransport, WebSearchSetting, json_string,
23};
24
25pub use options::harness_agent_options_from_config;
26#[cfg(test)]
27pub(crate) use options::harness_agent_options_from_config_with_env;
28pub(crate) use validate::normalize_harness_agent_config;
29
30/// A built-in tool (`BuiltinToolName`).
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33#[non_exhaustive]
34pub enum BuiltinToolName {
35    /// `shell`.
36    Shell,
37    /// `read`.
38    Read,
39    /// `write`.
40    Write,
41    /// `edit`.
42    Edit,
43    /// `web_fetch`.
44    WebFetch,
45    /// `web_search`.
46    WebSearch,
47    /// `programmatic_tool_caller`.
48    ProgrammaticToolCaller,
49    /// `subagent`.
50    Subagent,
51}
52
53/// Every built-in tool, in canonical order (`BUILTIN_TOOL_NAMES`).
54pub const BUILTIN_TOOL_NAMES: &[BuiltinToolName] = &[
55    BuiltinToolName::Shell,
56    BuiltinToolName::Read,
57    BuiltinToolName::Write,
58    BuiltinToolName::Edit,
59    BuiltinToolName::WebFetch,
60    BuiltinToolName::WebSearch,
61    BuiltinToolName::ProgrammaticToolCaller,
62    BuiltinToolName::Subagent,
63];
64
65impl BuiltinToolName {
66    /// The tool name, such as `"web_fetch"`.
67    #[must_use]
68    pub fn as_str(self) -> &'static str {
69        match self {
70            Self::Shell => "shell",
71            Self::Read => "read",
72            Self::Write => "write",
73            Self::Edit => "edit",
74            Self::WebFetch => "web_fetch",
75            Self::WebSearch => "web_search",
76            Self::ProgrammaticToolCaller => "programmatic_tool_caller",
77            Self::Subagent => "subagent",
78        }
79    }
80
81    /// The keys its per-tool config takes (`BUILTIN_TOOL_CONFIG_KEYS`), or `None` for a tool
82    /// that takes only `true` or `false`.
83    #[must_use]
84    pub fn config_keys(self) -> Option<&'static [&'static str]> {
85        BUILTIN_TOOL_CONFIG_KEYS
86            .iter()
87            .find(|(name, _)| *name == self)
88            .map(|(_, keys)| *keys)
89    }
90
91    pub(crate) fn names() -> String {
92        BUILTIN_TOOL_NAMES
93            .iter()
94            .map(|name| name.as_str())
95            .collect::<Vec<_>>()
96            .join(", ")
97    }
98}
99
100impl fmt::Display for BuiltinToolName {
101    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102        f.write_str(self.as_str())
103    }
104}
105
106impl FromStr for BuiltinToolName {
107    type Err = strands::Error;
108
109    /// Parses a tool name; an unknown one fails listing the available tools.
110    fn from_str(value: &str) -> strands::Result<Self> {
111        BUILTIN_TOOL_NAMES
112            .iter()
113            .copied()
114            .find(|name| name.as_str() == value)
115            .ok_or_else(|| {
116                strands::Error::other(format!(
117                    "Unknown built-in tool {}. Available: {}.",
118                    json_string(value),
119                    Self::names()
120                ))
121            })
122    }
123}
124
125/// The config keys each configurable built-in accepts (`BUILTIN_TOOL_CONFIG_KEYS`).
126pub(crate) const BUILTIN_TOOL_CONFIG_KEYS: &[(BuiltinToolName, &[&str])] = &[
127    (BuiltinToolName::Read, &["media"]),
128    (BuiltinToolName::Shell, &["description"]),
129    (BuiltinToolName::WebFetch, &["model", "transport"]),
130    (BuiltinToolName::ProgrammaticToolCaller, &["allowedTools", "timeout"]),
131    (BuiltinToolName::Subagent, &["maxDepth"]),
132];
133
134/// A built-in feature plugin (`BuiltinPluginName`).
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
136#[serde(rename_all = "snake_case")]
137#[non_exhaustive]
138pub enum BuiltinPluginName {
139    /// `environment`: platform, date, working directory and project docs before each user turn.
140    Environment,
141}
142
143/// Every built-in plugin (`BUILTIN_PLUGIN_NAMES`).
144pub const BUILTIN_PLUGIN_NAMES: &[BuiltinPluginName] = &[BuiltinPluginName::Environment];
145
146impl BuiltinPluginName {
147    /// The plugin's option name, such as `"environment"`.
148    #[must_use]
149    pub fn as_str(self) -> &'static str {
150        match self {
151            Self::Environment => "environment",
152        }
153    }
154}
155
156impl fmt::Display for BuiltinPluginName {
157    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161
162impl FromStr for BuiltinPluginName {
163    type Err = strands::Error;
164
165    /// Parses a plugin name; an unknown one fails listing the available plugins.
166    fn from_str(value: &str) -> strands::Result<Self> {
167        BUILTIN_PLUGIN_NAMES
168            .iter()
169            .copied()
170            .find(|name| name.as_str() == value)
171            .ok_or_else(|| {
172                let mut available: Vec<&str> = BUILTIN_PLUGIN_NAMES.iter().map(|name| name.as_str()).collect();
173                available.sort_unstable();
174                strands::Error::other(format!(
175                    "Unknown built-in plugin {}. Available: {}.",
176                    json_string(value),
177                    available.join(", ")
178                ))
179            })
180    }
181}
182
183/// What a module reference provides (`HarnessModuleKind`).
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
185#[serde(rename_all = "kebab-case")]
186#[non_exhaustive]
187pub enum HarnessModuleKind {
188    /// `tool`.
189    Tool,
190    /// `subagent`.
191    Subagent,
192    /// `plugin`.
193    Plugin,
194    /// `sandbox`.
195    Sandbox,
196    /// `memory-store`.
197    MemoryStore,
198    /// `model`.
199    Model,
200    /// `intervention`.
201    Intervention,
202    /// `agent-config`.
203    AgentConfig,
204}
205
206impl HarnessModuleKind {
207    /// The config spelling, such as `"memory-store"`.
208    #[must_use]
209    pub fn as_str(self) -> &'static str {
210        match self {
211            Self::Tool => "tool",
212            Self::Subagent => "subagent",
213            Self::Plugin => "plugin",
214            Self::Sandbox => "sandbox",
215            Self::MemoryStore => "memory-store",
216            Self::Model => "model",
217            Self::Intervention => "intervention",
218            Self::AgentConfig => "agent-config",
219        }
220    }
221}
222
223/// The language a module reference is written in (`HarnessModuleLanguage`).
224#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
225#[serde(rename_all = "lowercase")]
226#[non_exhaustive]
227pub enum HarnessModuleLanguage {
228    /// `typescript`.
229    Typescript,
230    /// `python`.
231    Python,
232}
233
234impl HarnessModuleLanguage {
235    /// The config spelling.
236    #[must_use]
237    pub fn as_str(self) -> &'static str {
238        match self {
239            Self::Typescript => "typescript",
240            Self::Python => "python",
241        }
242    }
243}
244
245/// A reference to a value defined in code (`HarnessModuleReference`). Rust parses and keeps
246/// these so a config round-trips, but cannot load them yet.
247#[derive(Debug, Clone, PartialEq)]
248#[non_exhaustive]
249pub struct HarnessModuleReference {
250    /// What the module provides.
251    pub kind: HarnessModuleKind,
252    /// The module specifier: a path or a package name.
253    pub module: String,
254    /// The export to read; `default` when `None`.
255    pub export: Option<String>,
256    /// The language the module is written in.
257    pub language: Option<HarnessModuleLanguage>,
258    /// Source files the module depends on.
259    pub files: Option<Vec<String>>,
260    /// The package the module comes from.
261    pub dependency: Option<String>,
262    /// Keys the reference carries beyond the known ones, kept as written.
263    pub extra: JsonObject,
264}
265
266impl HarnessModuleReference {
267    /// A reference of `kind` to `module`.
268    pub fn new(kind: HarnessModuleKind, module: impl Into<String>) -> Self {
269        Self {
270            kind,
271            module: module.into(),
272            export: None,
273            language: None,
274            files: None,
275            dependency: None,
276            extra: JsonObject::new(),
277        }
278    }
279
280    /// Sets the export to read.
281    #[must_use]
282    pub fn with_export(mut self, export: impl Into<String>) -> Self {
283        self.export = Some(export.into());
284        self
285    }
286
287    /// Sets the module's language.
288    #[must_use]
289    pub fn with_language(mut self, language: HarnessModuleLanguage) -> Self {
290        self.language = Some(language);
291        self
292    }
293}
294
295impl Serialize for HarnessModuleReference {
296    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
297        let mut map = serializer.serialize_map(None)?;
298        map.serialize_entry("kind", &self.kind)?;
299        map.serialize_entry("module", &self.module)?;
300        if let Some(export) = &self.export {
301            map.serialize_entry("export", export)?;
302        }
303        if let Some(language) = &self.language {
304            map.serialize_entry("language", language)?;
305        }
306        if let Some(files) = &self.files {
307            map.serialize_entry("files", files)?;
308        }
309        if let Some(dependency) = &self.dependency {
310            map.serialize_entry("dependency", dependency)?;
311        }
312        for (key, value) in &self.extra {
313            map.serialize_entry(key, value)?;
314        }
315        map.end()
316    }
317}
318
319/// The summarizer model in a portable `web_fetch` config: a `"provider/name"` string or a model
320/// module reference.
321#[derive(Debug, Clone, PartialEq)]
322#[non_exhaustive]
323pub enum HarnessConfigModel {
324    /// A `"provider/name"` string.
325    Name(String),
326    /// A model module reference.
327    Module(HarnessModuleReference),
328}
329
330impl Serialize for HarnessConfigModel {
331    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
332        match self {
333            Self::Name(name) => serializer.serialize_str(name),
334            Self::Module(reference) => reference.serialize(serializer),
335        }
336    }
337}
338
339/// JSON form of [`WebFetchConfig`](crate::WebFetchConfig) (`HarnessConfigWebFetch`).
340#[derive(Debug, Clone, Default, PartialEq, Serialize, bon::Builder)]
341pub struct HarnessConfigWebFetch {
342    /// The summarizer model.
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub model: Option<HarnessConfigModel>,
345    /// How the request is made.
346    #[serde(skip_serializing_if = "Option::is_none")]
347    pub transport: Option<WebFetchTransport>,
348}
349
350/// JSON form of [`BuiltinToolsConfig`](crate::BuiltinToolsConfig) (`HarnessConfigBuiltinTools`),
351/// with `web_fetch.model` allowed to be a module reference.
352#[derive(Debug, Clone, Default, PartialEq, bon::Builder)]
353pub struct HarnessConfigBuiltinTools {
354    /// The `"*"` key.
355    pub all: Option<bool>,
356    /// `shell`.
357    pub shell: Option<Setting<ShellConfig>>,
358    /// `read`.
359    pub read: Option<Setting<ReadConfig>>,
360    /// `write`.
361    pub write: Option<bool>,
362    /// `edit`.
363    pub edit: Option<bool>,
364    /// `web_fetch`.
365    pub web_fetch: Option<Setting<HarnessConfigWebFetch>>,
366    /// `web_search`.
367    pub web_search: Option<WebSearchSetting>,
368    /// `programmatic_tool_caller`.
369    pub programmatic_tool_caller: Option<Setting<ProgrammaticToolCallerConfig>>,
370    /// `subagent`.
371    pub subagent: Option<Setting<SubagentConfig>>,
372}
373
374impl Serialize for HarnessConfigBuiltinTools {
375    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
376        let mut map = serializer.serialize_map(None)?;
377        if let Some(all) = self.all {
378            map.serialize_entry("*", &all)?;
379        }
380        if let Some(shell) = &self.shell {
381            map.serialize_entry("shell", shell)?;
382        }
383        if let Some(read) = &self.read {
384            map.serialize_entry("read", read)?;
385        }
386        if let Some(write) = self.write {
387            map.serialize_entry("write", &write)?;
388        }
389        if let Some(edit) = self.edit {
390            map.serialize_entry("edit", &edit)?;
391        }
392        if let Some(web_fetch) = &self.web_fetch {
393            map.serialize_entry("web_fetch", web_fetch)?;
394        }
395        if let Some(web_search) = self.web_search {
396            map.serialize_entry("web_search", &web_search)?;
397        }
398        if let Some(caller) = &self.programmatic_tool_caller {
399            map.serialize_entry("programmatic_tool_caller", caller)?;
400        }
401        if let Some(subagent) = &self.subagent {
402            map.serialize_entry("subagent", subagent)?;
403        }
404        map.end()
405    }
406}
407
408/// The portable `builtinTools`: a list of names or a mapping.
409#[derive(Debug, Clone, PartialEq)]
410#[non_exhaustive]
411#[allow(clippy::large_enum_variant, reason = "a config value, built once")]
412pub enum HarnessConfigBuiltinToolsOption {
413    /// Exactly these tools.
414    List(Vec<BuiltinToolName>),
415    /// Edits to the defaults.
416    Mapping(HarnessConfigBuiltinTools),
417}
418
419impl Serialize for HarnessConfigBuiltinToolsOption {
420    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
421        match self {
422            Self::List(names) => names.serialize(serializer),
423            Self::Mapping(mapping) => mapping.serialize(serializer),
424        }
425    }
426}
427
428/// The portable `contextManager` (`HarnessConfigContextManager`: `"auto"`, `"agentic"` or
429/// `false`; JSON also accepts `"off"` for `false`).
430#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
431#[non_exhaustive]
432pub enum HarnessConfigContextManager {
433    /// `'auto'` (the default).
434    #[default]
435    Auto,
436    /// `'agentic'`.
437    Agentic,
438    /// `false`.
439    Off,
440}
441
442impl Serialize for HarnessConfigContextManager {
443    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
444        match self {
445            Self::Auto => serializer.serialize_str("auto"),
446            Self::Agentic => serializer.serialize_str("agentic"),
447            Self::Off => serializer.serialize_bool(false),
448        }
449    }
450}
451
452/// JSON form of [`MemoryConfig`](crate::MemoryConfig) (`HarnessConfigMemory`); stores are
453/// declared separately as `memoryStores` module references.
454#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, bon::Builder)]
455#[builder(on(String, into))]
456pub struct HarnessConfigMemory {
457    /// Directory the default file store's files live in.
458    #[serde(skip_serializing_if = "Option::is_none")]
459    pub dir: Option<String>,
460}
461
462/// The portable `mcpServers`: a path to a JSON file, or the server map itself.
463#[derive(Debug, Clone, PartialEq)]
464#[non_exhaustive]
465pub enum HarnessConfigMcpServers {
466    /// A path to a JSON file, resolved against the project root.
467    Path(String),
468    /// The server map, by name.
469    Servers(JsonObject),
470}
471
472impl Default for HarnessConfigMcpServers {
473    fn default() -> Self {
474        Self::Servers(JsonObject::new())
475    }
476}
477
478impl Serialize for HarnessConfigMcpServers {
479    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
480        match self {
481            Self::Path(path) => serializer.serialize_str(path),
482            Self::Servers(servers) => servers.serialize(serializer),
483        }
484    }
485}
486
487/// The portable `skills`: on or off, one source, or a list of sources.
488#[derive(Debug, Clone, PartialEq, Eq)]
489#[non_exhaustive]
490pub enum HarnessConfigSkills {
491    /// `true` scans the default directory; `false` disables skills.
492    Enabled(bool),
493    /// One directory path or `https://` URL.
494    Source(String),
495    /// Several sources.
496    Sources(Vec<String>),
497}
498
499impl Serialize for HarnessConfigSkills {
500    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
501        match self {
502            Self::Enabled(enabled) => serializer.serialize_bool(*enabled),
503            Self::Source(source) => serializer.serialize_str(source),
504            Self::Sources(sources) => sources.serialize(serializer),
505        }
506    }
507}
508
509/// The portable `interventions`: one value or a list (presets, `.cedar` paths, policies).
510#[derive(Debug, Clone, PartialEq, Eq)]
511#[non_exhaustive]
512pub enum HarnessConfigInterventions {
513    /// One value.
514    One(String),
515    /// Several values, layered in order.
516    Many(Vec<String>),
517}
518
519impl Serialize for HarnessConfigInterventions {
520    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
521        match self {
522            Self::One(value) => serializer.serialize_str(value),
523            Self::Many(values) => values.serialize(serializer),
524        }
525    }
526}
527
528/// Key-value pairs serialized as a JSON object in their order.
529fn pairs_as_map<S: Serializer, T: Serialize>(pairs: &[(String, T)], serializer: S) -> Result<S::Ok, S::Error> {
530    serializer.collect_map(pairs.iter().map(|(key, value)| (key, value)))
531}
532
533/// Dependencies a project declares for the runtimes that load its modules (`HarnessDependencies`).
534#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, bon::Builder)]
535pub struct HarnessDependencies {
536    /// npm package names to version ranges, in declaration order; serialized as a JSON object.
537    #[serde(serialize_with = "pairs_as_map")]
538    #[builder(default, with = |packages: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>| {
539        packages.into_iter().map(|(name, version)| (name.into(), version.into())).collect()
540    })]
541    pub typescript: Vec<(String, String)>,
542    /// pip requirement lines.
543    #[builder(default, with = |lines: impl IntoIterator<Item = impl Into<String>>| lines.into_iter().map(Into::into).collect())]
544    pub python: Vec<String>,
545}
546
547/// The complete portable form of a harness definition (`HarnessAgentConfig`).
548///
549/// Parse one from JSON with `serde_json`, which applies the config validation and its messages;
550/// unknown keys are dropped with a warning.
551///
552/// ```
553/// use strands_harness::{Effort, HarnessAgentConfig};
554///
555/// let config: HarnessAgentConfig = serde_json::from_value(serde_json::json!({
556///     "name": "Reviewer",
557///     "effort": "high",
558///     "builtinTools": ["read", "shell"],
559/// }))?;
560/// assert_eq!(config.effort, Effort::High);
561/// assert_eq!(config.model, "bedrock/global.anthropic.claude-opus-5-5");
562/// # Ok::<(), serde_json::Error>(())
563/// ```
564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, bon::Builder)]
565#[serde(rename_all = "camelCase", try_from = "serde_json::Value")]
566#[builder(on(String, into))]
567pub struct HarnessAgentConfig {
568    /// The agent's name.
569    #[builder(default = "Strands harness".to_owned())]
570    pub name: String,
571    /// What the agent does.
572    #[builder(default)]
573    pub description: String,
574    /// A domain block appended after the harness contract.
575    #[builder(default)]
576    pub instructions: String,
577    /// A `"provider/name"` model string.
578    #[builder(default = DEFAULT_MODEL.to_owned())]
579    pub model: String,
580    /// A model defined in code, replacing `model`.
581    pub model_module: Option<HarnessModuleReference>,
582    /// Reasoning effort.
583    #[builder(default = DEFAULT_EFFORT)]
584    pub effort: Effort,
585    /// Tools defined in code.
586    #[builder(default)]
587    pub tools: Vec<HarnessModuleReference>,
588    /// Specialist agents defined in code, each exposed as a tool.
589    #[builder(default)]
590    pub subagents: Vec<HarnessModuleReference>,
591    /// MCP servers to connect.
592    #[builder(default)]
593    pub mcp_servers: HarnessConfigMcpServers,
594    /// Which built-in tools to enable.
595    #[builder(default = HarnessConfigBuiltinToolsOption::List(DEFAULT_BUILTIN_TOOLS.to_vec()))]
596    pub builtin_tools: HarnessConfigBuiltinToolsOption,
597    /// Prompt caching.
598    #[builder(default = true)]
599    pub caching: bool,
600    /// SDK context management.
601    #[builder(default = HarnessConfigContextManager::Auto)]
602    pub context_manager: HarnessConfigContextManager,
603    /// Session persistence.
604    #[builder(default = Setting::Enabled(true))]
605    pub session: Setting<SessionConfig>,
606    /// Agent Skills.
607    #[builder(default = HarnessConfigSkills::Enabled(true))]
608    pub skills: HarnessConfigSkills,
609    /// Long-term memory.
610    #[builder(default = Setting::Enabled(true))]
611    pub memory: Setting<HarnessConfigMemory>,
612    /// Memory stores defined in code.
613    #[builder(default)]
614    pub memory_stores: Vec<HarnessModuleReference>,
615    /// Plugins defined in code.
616    #[builder(default)]
617    pub plugins: Vec<HarnessModuleReference>,
618    /// Built-in feature plugins.
619    #[builder(default = DEFAULT_BUILTIN_PLUGINS.to_vec())]
620    pub builtin_plugins: Vec<BuiltinPluginName>,
621    /// Tool-call interventions.
622    pub interventions: Option<HarnessConfigInterventions>,
623    /// Intervention handlers defined in code.
624    #[builder(default)]
625    pub intervention_modules: Vec<HarnessModuleReference>,
626    /// A sandbox defined in code.
627    pub sandbox: Option<HarnessModuleReference>,
628    /// SDK `AgentConfig` values defined in code, by key, in declaration order; serialized as a
629    /// JSON object.
630    #[serde(serialize_with = "pairs_as_map")]
631    #[builder(default)]
632    pub agent_config_modules: Vec<(String, HarnessModuleReference)>,
633    /// Dependencies of the referenced modules.
634    #[builder(default)]
635    pub dependencies: HarnessDependencies,
636    /// JSON-compatible SDK `AgentConfig` fields the harness does not own.
637    #[builder(default)]
638    pub agent_config: JsonObject,
639}
640
641impl Default for HarnessAgentConfig {
642    fn default() -> Self {
643        Self::builder().build()
644    }
645}
646
647impl TryFrom<serde_json::Value> for HarnessAgentConfig {
648    type Error = String;
649
650    fn try_from(value: serde_json::Value) -> Result<Self, String> {
651        normalize_harness_agent_config(&value).map_err(|error| error.to_string())
652    }
653}
654
655/// The defaults every key of a portable config falls back to (`DEFAULT_HARNESS_AGENT_CONFIG`).
656pub static DEFAULT_HARNESS_AGENT_CONFIG: LazyLock<HarnessAgentConfig> = LazyLock::new(HarnessAgentConfig::default);
657
658/// Validates a config built in code the way a parsed one is.
659///
660/// ```
661/// use strands_harness::{HarnessAgentConfig, define_harness_agent_config};
662///
663/// let config = define_harness_agent_config(HarnessAgentConfig {
664///     name: "Reviewer".into(),
665///     ..Default::default()
666/// })?;
667/// assert_eq!(config.name, "Reviewer");
668/// assert!(define_harness_agent_config(HarnessAgentConfig { name: String::new(), ..Default::default() }).is_err());
669/// # Ok::<(), strands::Error>(())
670/// ```
671///
672/// # Errors
673///
674/// The validation messages, such as `Invalid agent config:\nname must be a non-empty string.`
675pub fn define_harness_agent_config(config: HarnessAgentConfig) -> strands::Result<HarnessAgentConfig> {
676    let value = serde_json::to_value(config).map_err(strands::Error::other)?;
677    normalize_harness_agent_config(&value)
678}
679
680#[cfg(test)]
681mod tests;