Skip to content

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

refactor(config): extract tool dispatcher helpers into dedicated module

Steven Enamakel03d386cc14d1
diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs
index 7dfad275f2..1afb9862b5 100644
--- a/crates/openhuman-core/src/config/ops/agent.rs
+++ b/crates/openhuman-core/src/config/ops/agent.rs
@@ -8,6 +8,9 @@ use crate::config::Config;
use crate::core::Outcome;
use super::loader::{load_config_with_timeout, snapshot_config_json};
+use super::tool_dispatcher::{
+ apply_tool_dispatcher, normalize_optional, tool_dispatcher_env_override,
+};
/// Partial update for the `[autonomy]` block — the agent's filesystem access
/// mode. Each `None` field is left unchanged. `trusted_roots`, `allowed_commands`,
@@ -56,7 +59,7 @@ 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 [`super::tool_dispatcher::TOOL_DISPATCHER_CHOICES`] (case-insensitive). `None` leaves it
+ /// one of [`TOOL_DISPATCHER_CHOICES`](super::tool_dispatcher::TOOL_DISPATCHER_CHOICES). `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>,
@@ -240,20 +243,13 @@ pub async fn apply_agent_settings(
}
}
- let tool_dispatcher = update
- .tool_dispatcher
- .as_deref()
- .map(super::tool_dispatcher::normalize_tool_dispatcher)
- .transpose()?;
+ let tool_dispatcher = normalize_optional(update.tool_dispatcher.as_deref())?;
if let Some(timeout_secs) = update.agent_timeout_secs {
config.agent.agent_timeout_secs = timeout_secs;
}
- if let Some(tool_dispatcher) = tool_dispatcher {
- log::debug!("[config][agent] tool_dispatcher -> {tool_dispatcher}");
- config.agent.tool_dispatcher = tool_dispatcher;
- }
+ apply_tool_dispatcher(config, tool_dispatcher);
if let Some(chat_agent_id) = update.chat_agent_id {
let trimmed = chat_agent_id.trim();
@@ -304,9 +300,7 @@ pub async fn get_agent_settings() -> Result<Outcome<serde_json::Value>, String>
"min_timeout_secs": crate::tools::timeout::MIN_TIMEOUT_SECS,
"max_timeout_secs": crate::tools::timeout::MAX_TIMEOUT_SECS,
"tool_dispatcher": config.agent.tool_dispatcher,
- "tool_dispatcher_env_override": std::env::var("OPENHUMAN_TOOL_DISPATCHER")
- .map(|v| !v.trim().is_empty())
- .unwrap_or(false),
+ "tool_dispatcher_env_override": tool_dispatcher_env_override(),
});
Ok(Outcome::single_log(value, "agent settings read"))
}
diff --git a/crates/openhuman-core/src/config/ops/tool_dispatcher.rs b/crates/openhuman-core/src/config/ops/tool_dispatcher.rs
index 681a3384be..88d49bdc1c 100644
--- a/crates/openhuman-core/src/config/ops/tool_dispatcher.rs
+++ b/crates/openhuman-core/src/config/ops/tool_dispatcher.rs
@@ -18,3 +18,23 @@ pub fn normalize_tool_dispatcher(raw: &str) -> Result<String, String> {
}
Ok(normalized)
}
+
+/// [`normalize_tool_dispatcher`] over an optional patch field.
+pub fn normalize_optional(raw: Option<&str>) -> Result<Option<String>, String> {
+ raw.map(normalize_tool_dispatcher).transpose()
+}
+
+/// Store a validated dispatcher on the agent config; `None` leaves it alone.
+pub fn apply_tool_dispatcher(config: &mut crate::config::Config, value: Option<String>) {
+ if let Some(value) = value {
+ log::debug!("[config][agent] tool_dispatcher -> {value}");
+ config.agent.tool_dispatcher = value;
+ }
+}
+
+/// True when `OPENHUMAN_TOOL_DISPATCHER` overrides the persisted setting.
+pub fn tool_dispatcher_env_override() -> bool {
+ std::env::var("OPENHUMAN_TOOL_DISPATCHER")
+ .map(|v| !v.trim().is_empty())
+ .unwrap_or(false)
+}