Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(config): validate tool_dispatcher and agent fields in apply_agent_settings

Steven Enamakel8a65101f6cd1
diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs
index 7b5f581817..e04d3430a4 100644
--- a/crates/openhuman-core/src/config/ops/agent.rs
+++ b/crates/openhuman-core/src/config/ops/agent.rs
@@ -56,17 +56,12 @@ pub struct AgentSettingsPatch {
/// running core writes wherever `Config::save` actually points.
pub chat_agent_id: Option<String>,
/// How tool calls are spoken to the model (`[agent] tool_dispatcher`):
- /// one of [`TOOL_DISPATCHER_CHOICES`] (case-insensitive). `None` leaves it
+ /// one of [`super::tool_dispatcher::TOOL_DISPATCHER_CHOICES`] (case-insensitive). `None` leaves it
/// unchanged. Takes effect for new sessions; a resumed thread keeps the
/// dialect its prompt was frozen with.
pub tool_dispatcher: Option<String>,
}
-/// Accepted spellings of `[agent] tool_dispatcher`. `auto` is the default:
-/// native structured calls when the provider supports them, else JSON-in-tag.
-pub const TOOL_DISPATCHER_CHOICES: [&str; 6] =
- ["auto", "native", "xml", "pformat", "python", "typescript"];
-
/// Partial update for the agent's editable filesystem roots.
///
/// `action_dir` (issue #3240) and the files folder (#5505) are editable.
@@ -245,6 +240,34 @@ pub async fn apply_agent_settings(
}
}
+ let tool_dispatcher = update
+ .tool_dispatcher
+ .as_deref()
+ .map(super::tool_dispatcher::normalize_tool_dispatcher)
+ .transpose()?;
+
+ if let Some(timeout_secs) = update.agent_timeout_secs {
+ if !(MIN_TIMEOUT_SECS..=MAX_TIMEOUT_SECS).contains(&timeout_secs) {
+ log::warn!(
+ "[config][agent] rejected agent_timeout_secs={timeout_secs} (valid {MIN_TIMEOUT_SECS}..={MAX_TIMEOUT_SECS})"
+ );
+ return Err(format!(
+ "agent_timeout_secs must be between {MIN_TIMEOUT_SECS} and {MAX_TIMEOUT_SECS} seconds (got {timeout_secs})"
+ ));
+ }
+ }
+
+ if let Some(chat_agent_id) = update.chat_agent_id.as_deref() {
+ let trimmed = chat_agent_id.trim();
+ if !trimmed.is_empty()
+ && !crate::agent::OpenHumanSessionHost::is_runnable_agent_id(config, trimmed)
+ {
+ return Err(format!(
+ "chat_agent_id '{trimmed}' is not a runnable agent definition"
+ ));
+ }
+ }
+
let tool_dispatcher = match update.tool_dispatcher.as_deref() {
Some(raw) => {
let normalized = raw.trim().to_ascii_lowercase();
diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rs
index 1151b72bf2..3719f14a22 100644
--- a/crates/openhuman-core/src/config/ops/mod.rs
+++ b/crates/openhuman-core/src/config/ops/mod.rs
@@ -5,6 +5,7 @@ mod loader;
mod model;
mod privacy;
mod sandbox;
+mod tool_dispatcher;
mod search;
mod ui;
diff --git a/crates/openhuman-core/src/config/ops/tool_dispatcher.rs b/crates/openhuman-core/src/config/ops/tool_dispatcher.rs
new file mode 100644
index 0000000000..681a3384be
--- /dev/null
+++ b/crates/openhuman-core/src/config/ops/tool_dispatcher.rs
@@ -0,0 +1,20 @@
+//! Validation for the `[agent] tool_dispatcher` setting.
+
+/// Accepted spellings of `[agent] tool_dispatcher`. `auto` is the default:
+/// native structured calls when the provider supports them, else JSON-in-tag.
+pub const TOOL_DISPATCHER_CHOICES: [&str; 6] =
+ ["auto", "native", "xml", "pformat", "python", "typescript"];
+
+/// Trim and lowercase `raw`, rejecting anything outside
+/// [`TOOL_DISPATCHER_CHOICES`].
+pub fn normalize_tool_dispatcher(raw: &str) -> Result<String, String> {
+ let normalized = raw.trim().to_ascii_lowercase();
+ if !TOOL_DISPATCHER_CHOICES.contains(&normalized.as_str()) {
+ log::warn!("[config][agent] rejected tool_dispatcher={normalized:?}");
+ return Err(format!(
+ "invalid tool_dispatcher '{normalized}' (expected {})",
+ TOOL_DISPATCHER_CHOICES.join(" | ")
+ ));
+ }
+ Ok(normalized)
+}