The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(session_host): reindent factory helpers and tidy module order
Steven Enamakela3edbc42ff18
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rsindex df8594be08..4d4e984402 100644--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs@@ -19,12 +19,12 @@ use tinytools_agent::dialect::{CodeDialect, CodeStyle, NativeDialect, PFormatDialect, ToolCallFormat, ToolDialect, XmlDialect,};+#[path = "factory/build_session.rs"]+mod build_session;#[path = "factory_tool_registry.rs"]mod tool_registry;#[path = "factory_workflows.rs"]mod workflows;-#[path = "factory/build_session.rs"]-mod build_session;impl OpenHumanSessionHost {/// Returns whether `agent_id` resolves to a runnable definition for this@@ -149,7 +149,6 @@ impl OpenHumanSessionHost {ctx, config, agent_id, target_def, host_only, host, session_id, None,)}-}/// Resolves the `AgentDefinition` a session should be built from, given thediff --git a/crates/openhuman-core/src/agent/session_host/builder/factory/build_helpers.rs b/crates/openhuman-core/src/agent/session_host/builder/factory/build_helpers.rsindex 4eb710e1e2..b554a2c550 100644--- a/crates/openhuman-core/src/agent/session_host/builder/factory/build_helpers.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/factory/build_helpers.rs@@ -5,54 +5,50 @@ pub(super) fn prompt_builder(config: &Config,) -> Result<SystemPromptBuilder> {Ok(match target_def {- Some(def) => match &def.system_prompt {- PromptSource::Dynamic(()) => SystemPromptBuilder::from_dynamic(def.prompt_fn()?),- PromptSource::Verbatim(text) => SystemPromptBuilder::verbatim(text.clone()),- PromptSource::Inline(text) => SystemPromptBuilder::for_subagent(- text.clone(),- def.extensions.omit_identity,- def.extensions.omit_safety_preamble,- ),- PromptSource::File { path } => {- let prompt_root = config.workspace_dir.join("agent").join("prompts");- let workspace_path = prompt_root.join(path);- let body_text = if workspace_path.is_file() {- match crate::security::validate_path_within_root(- &workspace_path,- &prompt_root,- ) {- Ok(resolved) => {- std::fs::read_to_string(&resolved).unwrap_or_else(|e| {+ Some(def) => match &def.system_prompt {+ PromptSource::Dynamic(()) => SystemPromptBuilder::from_dynamic(def.prompt_fn()?),+ PromptSource::Verbatim(text) => SystemPromptBuilder::verbatim(text.clone()),+ PromptSource::Inline(text) => SystemPromptBuilder::for_subagent(+ text.clone(),+ def.extensions.omit_identity,+ def.extensions.omit_safety_preamble,+ ),+ PromptSource::File { path } => {+ let prompt_root = config.workspace_dir.join("agent").join("prompts");+ let workspace_path = prompt_root.join(path);+ let body_text = if workspace_path.is_file() {+ match crate::security::validate_path_within_root(&workspace_path, &prompt_root)+ {+ Ok(resolved) => std::fs::read_to_string(&resolved).unwrap_or_else(|e| {log::warn!("[agent::builder] failed to read prompt {}: {e} — using empty body",workspace_path.display());String::new()- })- }- Err(e) => {- log::warn!(- "[agent::builder] prompt path rejected: {e} — using empty body"- );- String::new()+ }),+ Err(e) => {+ log::warn!(+ "[agent::builder] prompt path rejected: {e} — using empty body"+ );+ String::new()+ }}- }- } else {- log::debug!(- "[agent::builder] prompt file {} not found — using empty body",- path- );- String::new()- };- SystemPromptBuilder::for_subagent(- body_text,- def.extensions.omit_identity,- def.extensions.omit_safety_preamble,- )- }- },- None => SystemPromptBuilder::with_defaults(),-})+ } else {+ log::debug!(+ "[agent::builder] prompt file {} not found — using empty body",+ path+ );+ String::new()+ };+ SystemPromptBuilder::for_subagent(+ body_text,+ def.extensions.omit_identity,+ def.extensions.omit_safety_preamble,+ )+ }+ },+ None => SystemPromptBuilder::with_defaults(),+ })}pub(super) fn tool_dispatcher(@@ -62,38 +58,38 @@ pub(super) fn tool_dispatcher(supports_native: bool,agent_id: &str,) -> Box<dyn ToolDialect> {- // 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 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(),- )),- };+ // 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 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} \+ 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()- );- tool_dispatcher+ tool_dispatcher.should_send_tool_specs(),+ pformat_registry.len()+ );+ tool_dispatcher}pub(super) fn effective_settings(@@ -109,7 +105,11 @@ pub(super) fn effective_settings(let effective_tokenjuice_compression = target_def.map(|def| def.extensions.tokenjuice_for(&def.model)).unwrap_or(tinyjuice_bus::types::AgentTokenjuiceCompression::Full);- (effective_temperature, effective_omit_memory_context, effective_tokenjuice_compression)+ (+ effective_temperature,+ effective_omit_memory_context,+ effective_tokenjuice_compression,+ )}pub(super) fn effective_agent_config(@@ -125,15 +125,15 @@ pub(super) fn effective_agent_config(super::iteration_cap::resolve_max_tool_iterations(&config.agent, target_def);if let Some(def) = target_def {log::info!(- "[agent::builder] resolved iteration cap for agent_id={}: \+ "[agent::builder] resolved iteration cap for agent_id={}: \definition.max_iterations={} iteration_policy={:?} -> effective={} \(global default {}, explicit override {:?})",- agent_id,- def.max_iterations,- def.iteration_policy,- effective_cap,- config.agent.max_tool_iterations,- config.agent.max_tool_iterations_override,+ agent_id,+ def.max_iterations,+ def.iteration_policy,+ effective_cap,+ config.agent.max_tool_iterations,+ config.agent.max_tool_iterations_override,);}effective_agent_config.max_tool_iterations = effective_cap;@@ -154,38 +154,38 @@ pub(super) fn payload_summarizer(config: &Config,) -> Option<std::sync::Arc<crate::agent::tinyagents::payload_summarizer::DynPayloadSummarizer>> {if !host_only && super::super::summarizes_tool_output(agent_id, config) {- match crate::agent_registry::host_definition::AgentDefinitionRegistry::current() {- Some(reg) => match reg.get("summarizer") {- Some(summarizer_def) => {- log::info!(- "[agent::builder] wiring payload_summarizer for orchestrator: \+ match crate::agent_registry::host_definition::AgentDefinitionRegistry::current() {+ Some(reg) => match reg.get("summarizer") {+ Some(summarizer_def) => {+ log::info!(+ "[agent::builder] wiring payload_summarizer for orchestrator: \threshold_tokens={} max_tokens={}",- config.context.summarizer_payload_threshold_tokens,- config.context.summarizer_max_payload_tokens- );- Some(std::sync::Arc::new(+ config.context.summarizer_payload_threshold_tokens,+ config.context.summarizer_max_payload_tokens+ );+ Some(std::sync::Arc::new(crate::agent::tinyagents::payload_summarizer::SubagentPayloadSummarizer::new(summarizer_def.clone(),),))- }+ }+ None => {+ log::warn!(+ "[agent::builder] orchestrator requested payload_summarizer but \+ `summarizer` definition is not in the registry — proceeding without it"+ );+ None+ }+ },None => {log::warn!("[agent::builder] orchestrator requested payload_summarizer but \- `summarizer` definition is not in the registry — proceeding without it"+ AgentDefinitionRegistry is not initialised — proceeding without it");None}- },- None => {- log::warn!(- "[agent::builder] orchestrator requested payload_summarizer but \- AgentDefinitionRegistry is not initialised — proceeding without it"- );- None}+ } else {+ None}-} else {- None-}}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.rsindex 229aa28c47..b641f6cf04 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@@ -372,11 +372,18 @@ impl OpenHumanSessionHost {// `refresh_delegation_tools` replaces the whole set later (#6145).let tool_dispatcher = helpers::tool_dispatcher(- &tools, &delegation_tools, &dispatcher_choice, supports_native, agent_id,+ &tools,+ &delegation_tools,+ &dispatcher_choice,+ supports_native,+ agent_id,);- let (effective_temperature, effective_omit_memory_context, effective_tokenjuice_compression) =- helpers::effective_settings(target_def, config);+ let (+ effective_temperature,+ effective_omit_memory_context,+ effective_tokenjuice_compression,+ ) = helpers::effective_settings(target_def, config);helpers::log_agent_definition_name(agent_id);@@ -387,8 +394,7 @@ impl OpenHumanSessionHost {// a host provider. The `agent_harness_e2e` mock now serves SSE for streaming,// so the crate-native streaming path is exercised end-to-end.//- let effective_agent_config =- helpers::effective_agent_config(config, target_def, agent_id);+ let effective_agent_config = helpers::effective_agent_config(config, target_def, agent_id);let merged_host_tools = super::host_tools::merge_for_turn(ctx,host,diff --git a/crates/openhuman-core/src/agent/session_host/driver/execute.rs b/crates/openhuman-core/src/agent/session_host/driver/execute.rsindex 7cfae5119a..5caebca360 100644--- a/crates/openhuman-core/src/agent/session_host/driver/execute.rs+++ b/crates/openhuman-core/src/agent/session_host/driver/execute.rs@@ -448,4 +448,3 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {})}}-diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 986a4905ac..c5208e12e0 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -165,7 +165,6 @@ struct OpenHumanTurnToolSurface {mod announcement_state;use announcement_state::OpenHumanTurnPreludeMutable;-#[path = "runtime_session/ensure.rs"]mod ensure;@@ -228,7 +227,6 @@ impl OpenHumanSessionHost {self.turn_with_origin(user_message, None).await}-/// Publish a caller-driven visibility/policy mutation into the live hook/// state. The runtime keeps generic snapshots immutable per request; this/// simply replaces the host composition from which the *next* snapshot,diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/announcement_state.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/announcement_state.rsindex f8777437fd..9a049bf008 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/announcement_state.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/announcement_state.rs@@ -29,8 +29,10 @@ pub(super) struct OpenHumanTurnPreludeMutable {/// snapshot simply had no TinyJuice declarations.pub(super) recorded_tool_snapshot_adopted: bool,pub(super) workflows: Vec<tinyskills::Skill>,- pub(super) composio_events: Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,- pub(super) skill_events: Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,+ pub(super) composio_events:+ Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,+ pub(super) skill_events:+ Option<tinybus::events::EventReceiver<crate::core::events::DomainEvent>>,/// The user-authored text of the in-flight turn, held until commit so the/// committed turn can be handed to memory.pub(super) pending_user_text: Option<String>,diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/ensure.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/ensure.rsindex 4d336a2ae7..d2777295dd 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/ensure.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/ensure.rs@@ -304,5 +304,4 @@ impl OpenHumanSessionHost {);Ok(())}-}diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context/behavior.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context/behavior.rsindex 11249a6a3e..950a25afac 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context/behavior.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context/behavior.rs@@ -348,4 +348,3 @@ impl OpenHumanRunContext {self.file_state_agent_id.clone()}}-diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rsindex da41c3e04a..a954b5fd49 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs@@ -410,7 +410,6 @@ impl OpenHumanSecurityGate {}decision_for_outcome(&call.tool_name, outcome)}-}#[path = "security_gate/authorize.rs"]diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection/tool_calls.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection/tool_calls.rsindex c1a43a2035..6117572c62 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection/tool_calls.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection/tool_calls.rs@@ -208,5 +208,4 @@ impl OpenhumanEventBridge {_ => {}}}-}