Skip to content

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

refactor(session_host): extract tool dispatcher construction into helper

Steven Enamakelabcbc433c588
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs b/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs
index 6871297eea..d9d6e8f895 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs
@@ -371,52 +371,9 @@ impl OpenHumanSessionHost {
// drops any name a durable tool already owns, and
// `refresh_delegation_tools` replaces the whole set later (#6145).
- // Build the P-Format registry AFTER the tool list is finalised
- // (including orchestrator tools) so every tool gets a signature
- // entry. The registry is self-contained — it doesn't hold a
- // reference back into the tools Vec.
- let pformat_registry = tinytools_agent::build_registry(
- tools
- .iter()
- .chain(delegation_tools.iter())
- .map(|tool| (tool.name(), tool.parameters_schema())),
+ let tool_dispatcher = helpers::tool_dispatcher(
+ &tools, &delegation_tools, &dispatcher_choice, supports_native, agent_id,
);
- let dispatcher_kind = ToolCallFormat::resolve(&dispatcher_choice, supports_native);
- let tool_dispatcher: Box<dyn ToolDialect> = match dispatcher_kind {
- ToolCallFormat::Native => Box::new(NativeDialect),
- ToolCallFormat::Json => Box::new(XmlDialect),
- ToolCallFormat::PFormat => Box::new(PFormatDialect::new(pformat_registry.clone())),
- ToolCallFormat::Python => Box::new(CodeDialect::new(
- CodeStyle::Python,
- pformat_registry.clone(),
- )),
- ToolCallFormat::TypeScript => Box::new(CodeDialect::new(
- CodeStyle::TypeScript,
- pformat_registry.clone(),
- )),
- };
-
- log::debug!(
- "[agent] tool dispatcher selected: choice={dispatcher_choice} agent_id={agent_id} \
- kind={dispatcher_kind:?} sends_tool_specs={} pformat_registry_entries={}",
- tool_dispatcher.should_send_tool_specs(),
- pformat_registry.len()
- );
-
- // The resolved definition's TOML value takes precedence over the
- // configured default for canonical agent runs.
- let effective_temperature = target_def
- .map(|def| def.temperature)
- .unwrap_or(config.default_temperature);
-
- // Whether a new session gets `context.md` prepended to its first user
- // message; agents without a definition get it.
- let effective_omit_memory_context = target_def
- .map(|def| def.extensions.omit_memory_context)
- .unwrap_or(false);
- let effective_tokenjuice_compression = target_def
- .map(|def| def.extensions.tokenjuice_for(&def.model))
- .unwrap_or(tinyjuice_bus::types::AgentTokenjuiceCompression::Full);
// Stamp the resolved agent definition id onto the OpenHumanSessionHost via the
// builder. Without this call, `agent_definition_name` falls