Skip to content

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

fix(agent): correct orchestrator prompt to use session host factory

Steven Enamakel748458544bfe
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
index ea98c8425e..687bd46953 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
@@ -354,8 +354,8 @@ fn strip_route_lines(archetype: &str, skills: bool, mcp: bool, composio: bool) -
///
/// So: exact match first, then the longest registry id that `agent_id` extends
/// at an `_` boundary. Longest wins because ids are not prefix-free —
-/// no id is a prefix of another today, but ids that share a stem (`goals_agent`
-/// vs a future `goals`) would, and a shorter accidental match would resolve
+/// no id is a prefix of another today, but ids that share a stem (`task_manager_agent`
+/// vs a future `task_manager`) would, and a shorter accidental match would resolve
/// a renamed session onto the wrong agent's subagent list.
fn resolve_definition<'r>(
registry: &'r AgentDefinitionRegistry,
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index 95c35e28df..bfd4bfe4d3 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -2,7 +2,6 @@
//! `build_session_agent_inner` constructor.
use super::dispatcher::{resolve_dispatcher_kind, DispatcherKind};
-use super::helpers::prefetch_tool_memory_rules_blocking;
use super::should_synthesize_delegation_tools;
use crate::agent::harness::definition::NO_TOOLS_SENTINEL;
use crate::agent::harness::definition::{AgentDefinitionRegistry, PromptSource, ToolScope};
@@ -11,8 +10,6 @@ use crate::agent::prompts::SystemPromptBuilder;
use crate::agent::session_host::types::OpenHumanSessionHost;
use crate::config::Config;
use crate::inference::provider;
-use crate::memory::tool_memory::capture::ToolMemoryCaptureHook;
-use crate::memory::Memory;
use crate::security::SecurityPolicy;
use crate::tools;
use anyhow::Result;
@@ -58,10 +55,10 @@ impl OpenHumanSessionHost {
/// Shared infrastructure between agent ids is identical:
/// 1. Initializing the host runtime (native or docker).
/// 2. Setting up security policies.
- /// 3. Initializing memory and embedding services.
- /// 4. Registering all built-in and orchestrator tools.
- /// 5. Configuring the routed AI provider.
- /// 6. Setting up the learning system and post-turn hooks.
+ /// 3. Registering all built-in and orchestrator tools (the `memory` tool
+ /// only while memory is on).
+ /// 4. Configuring the routed AI provider.
+ /// 5. Setting up post-turn hooks.
///
/// What differs per agent id:
/// * `visible_tool_names` is the agent's `ToolScope::Named` list
@@ -89,7 +86,7 @@ impl OpenHumanSessionHost {
log::info!(
"[agent::builder] building session agent id={} \
- (scope={}, omit_identity={}, omit_profile={}, omit_memory_md={}, temperature={:.2})",
+ (scope={}, omit_identity={}, omit_memory_context={}, temperature={:.2})",
agent_id,
target_def
.as_ref()
@@ -102,11 +99,10 @@ impl OpenHumanSessionHost {
.as_ref()
.map(|d| d.omit_identity)
.unwrap_or(false),
- target_def.as_ref().map(|d| d.omit_profile).unwrap_or(true),
target_def
.as_ref()
- .map(|d| d.omit_memory_md)
- .unwrap_or(true),
+ .map(|d| d.omit_memory_context)
+ .unwrap_or(false),
target_def
.as_ref()
.map(|d| d.temperature)
@@ -172,35 +168,6 @@ impl OpenHumanSessionHost {
config.workspace_dir.clone(),
)?;
- // The session's store, through the same binding the archivist resolves
- // two statements down — so one subtree yields one store rather than an
- // engine handle beside a driver over the same files.
- //
- // The two reasons this was deferred are both settled. **Embedder
- // resolution**: the factory's ladder and the driver's are the same
- // code reading the same field. `Config::workload_local_model` and
- // `EngineRuntimeConfig::workload_local_model` both take
- // `embeddings_provider`, strip `"ollama:"`, trim and reject empty, and
- // that `Option` is the only input to `effective_embedding_settings`.
- // The Ollama health-gate is not a difference either: it lives inside
- // `create_unified_memory_full`, which the module runs because the
- // module *is* the engine, and its probe address is proxied back here
- // through `EmbeddingHost::ollama_base_url`. (`embedding_routes` never
- // mattered — the engine's own parameter is underscore-prefixed and
- // unused.) **The test build**: `binding::module_provider` under
- // `cfg(test)` loads the module when `TINYMEMORY_TEST_MODULE` names it
- // and degrades to the null driver otherwise, which is the same footing
- // the archivist has had here all along.
- let memory: Arc<dyn Memory> =
- crate::agent::experience::ops::DriverMemory::for_config(config)
- .map_err(|e| anyhow::anyhow!("session memory binding: {e}"))?;
- // The archivist takes the bound driver for this session's memory
- // subtree — the same subtree `session_memory` opened — rather than the
- // raw SQLite handle the factory used to strip off the engine result.
- // That handle was the #5378 `:290` blocker: a concrete connection no
- // module or remote driver can supply. The engine's connection is now
- // exclusively the engine's. Lane C (#6040) rides the same binding.
- let (archivist_provider, auto_recall) = super::helpers::bind_session_memory(config)?;
// Load the user's persisted tool preferences once. They drive two
// things below: granting the App UI Control / App Automation mutation
// opt-in (#3762) and filtering the tool set to the enabled snapshot.
@@ -224,7 +191,7 @@ impl OpenHumanSessionHost {
enabled_tools.extend(["browser".to_string(), "browser_open".to_string()]);
}
// Share a single `Arc<Config>` across the heavyweight per-build consumers
- // (the tool registry, the reflection hook, the turn provider) instead of
+ // (the tool registry, the turn provider) instead of
// deep-cloning the large `Config` at each site (#5050, Fix 1). `Config` is
// immutable after construction, so one refcounted instance is behaviourally
// identical to N independent clones.
@@ -430,139 +397,7 @@ impl OpenHumanSessionHost {
},
None => SystemPromptBuilder::with_defaults(),
};
- if config.learning.enabled {
- // Insert the privileged reflection block ahead of the
- // generic `user_memory` section when one is already
- // present (the `with_defaults` chain includes it). For
- // builders that do not contain `user_memory` (dynamic /
- // sub-agent prompts), the helper falls back to appending,
- // which still keeps reflections ahead of the
- // learned-context / user-profile blocks added immediately
- // after.
- prompt_builder = prompt_builder
- .insert_section_before(
- "user_memory",
- Box::new(crate::agent::prompts::UserReflectionsSection),
- )
- .add_section(Box::new(
- crate::agent::learning::LearnedContextSection::new(memory.clone()),
- ))
- .add_section(Box::new(crate::agent::learning::UserProfileSection::new(
- memory.clone(),
- )));
- // NOTE: MemoryAccessSection is added after tool-filtering so we can
- // gate it on retrieval-tool visibility — see below.
- log::info!(
- "[learning] prompt sections registered (user_reflections, learned_context, user_profile)"
- );
- }
-
- // Explicit-preferences injection — independent of the full learning
- // subsystem. When `explicit_preferences_enabled` is true (the default)
- // and the full learning subsystem is NOT already wiring UserProfileSection,
- // we add it here so pinned preferences written by `remember_preference`
- // reach every session prompt. The `fetch_learned_context` gate is
- // widened by `explicit_preferences_enabled` on the OpenHumanSessionHost (see
- // `session/turn.rs`) so the data is actually fetched and populated.
- if config.learning.explicit_preferences_enabled && !config.learning.enabled {
- prompt_builder = prompt_builder.add_section(Box::new(
- crate::agent::learning::UserProfileSection::new(memory.clone()),
- ));
- log::info!(
- "[learning] explicit-preference UserProfileSection registered \
- (learning.enabled=false, explicit_preferences_enabled=true)"
- );
- }
-
- // Build post-turn hooks when learning is enabled
let mut post_turn_hooks: Vec<Arc<dyn crate::agent::hooks::PostTurnHook>> = Vec::new();
- if config.learning.enabled {
- if config.learning.reflection_enabled {
- // The reflection hook needs an owned `Arc<Config>`; reuse the
- // shared base config (a refcount bump) rather than a second deep
- // clone of the full config (#5050, Fix 1).
- let full_config = Arc::clone(&base_config);
- // For cloud reflection, wrap the provider in an Arc.
- // For local, no provider needed.
- let reflection_provider: Option<Arc<dyn tinyinference_llm::model::ChatModel<()>>> =
- if config.learning.reflection_source == crate::config::ReflectionSource::Cloud {
- let (model, resolved_model) =
- provider::create_chat_model_with_model_id("reasoning", config, 0.3)?;
- log::debug!(
- "[learning] built crate-native reflection model resolved_model={resolved_model}"
- );
- Some(model)
- } else {
- None
- };
- post_turn_hooks.push(Arc::new(crate::agent::learning::ReflectionHook::new(
- config.learning.clone(),
- full_config.clone(),
- memory.clone(),
- reflection_provider,
- )));
- log::info!(
- "[learning] reflection hook registered (source={:?})",
- config.learning.reflection_source
- );
- }
-
- if config.learning.user_profile_enabled {
- post_turn_hooks.push(Arc::new(crate::agent::learning::UserProfileHook::new(
- config.learning.clone(),
- memory.clone(),
- )));
- log::info!("[learning] user_profile hook registered");
- }
-
- if config.learning.tool_tracking_enabled {
- post_turn_hooks.push(Arc::new(crate::agent::learning::ToolTrackerHook::new(
- config.learning.clone(),
- memory.clone(),
- )));
- log::info!("[learning] tool_tracker hook registered");
- }
-
- if config.learning.tool_memory_capture_enabled {
- post_turn_hooks.push(Arc::new(ToolMemoryCaptureHook::new(memory.clone(), true)));
- log::info!("[learning] tool_memory_capture hook registered");
- }
-
- if config.learning.tool_memory_capture_enabled {
- post_turn_hooks.push(Arc::new(
- crate::agent::experience::AgentExperienceCaptureHook::new(memory.clone(), true),
- ));
- log::info!("[learning] agent_experience_capture hook registered");
- }
- }
-
- // ── ArchivistHook — register independently of learning.enabled ──────
- //
- // Episodic capture (FTS5 index, segment lifecycle, LLM recap, embedding)
- // is the system-of-record for chat turns and must stay active even when
- // the inference stack (`reflection`, `stability_detector`) is disabled.
- // Gated only on `config.learning.episodic_capture_enabled` (default: true)
- // using the explicit SQLite resource returned by the session factory.
- let archivist_hook_arc: Option<Arc<crate::agent::harness::archivist::ArchivistHook>> =
- if config.learning.episodic_capture_enabled {
- let hook = Arc::new(
- crate::agent::harness::archivist::ArchivistHook::new(archivist_provider, true)
- .with_config(Arc::clone(&base_config)),
- );
- post_turn_hooks
- .push(Arc::clone(&hook) as Arc<dyn crate::agent::hooks::PostTurnHook>);
- log::info!(
- "[archivist] episodic capture hook registered (learning.enabled={})",
- config.learning.enabled
- );
- Some(hook)
- } else {
- log::info!(
- "[archivist] episodic_capture_enabled=false — archivist hook not registered"
- );
- None
- };
-
post_turn_hooks.extend(crate::agent::hooks::embedder_post_turn_hooks());
// Best-effort prewarm from the shared Composio cache. This avoids
@@ -788,45 +623,11 @@ impl OpenHumanSessionHost {
}
}
- // Memory prompt sections — the read side (#566) and the write side
- // (#6048); both gates live in `helpers::add_memory_prompt_sections`.
- prompt_builder = super::helpers::add_memory_prompt_sections(
- prompt_builder,
- &tools,
- &delegation_tools,
- &visible,
- agent_id,
- );
-
// The delegation tools stay beside the durable registry rather than
// inside it: the builder holds them in `OpenHumanSessionHost::synthesized_tools`,
// drops any name a durable tool already owns, and
// `refresh_delegation_tools` replaces the whole set later (#6145).
- // Pre-fetch Critical + High priority tool-scoped memory rules so they
- // pin into the (compression-resistant) system prompt for the whole
- // session. Done here — after the tool list is finalised — so we only
- // fetch rules for tools this agent can actually use. Skipped when
- // `learning.enabled` is false (no new rules are written in that mode,
- // and users who opt out of learning expect no stored rules to surface)
- // or when the runtime cannot host a synchronous bridge (single-threaded
- // test harnesses).
- if config.learning.enabled && config.learning.tool_memory_capture_enabled {
- let agent_tool_names: Vec<String> = tools
- .iter()
- .chain(delegation_tools.iter())
- .map(|t| t.name().to_string())
- .collect();
- let pinned = prefetch_tool_memory_rules_blocking(memory.clone(), &agent_tool_names);
- if !pinned.is_empty() {
- log::info!(
- "[memory::tool_memory] pinning {} tool-scoped rule(s) into system prompt",
- pinned.len()
- );
- prompt_builder = prompt_builder.with_tool_memory_rules(pinned);
- }
- }
-
// 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
@@ -989,8 +790,6 @@ impl OpenHumanSessionHost {
.synthesized_tools(delegation_tools)
.visible_tool_names(visible)
.deferred_tools(target_def.map_or_else(Vec::new, |d| d.deferred_tools.clone()))
- .memory(memory)
- .auto_recall(Some(auto_recall))
.tool_dispatcher(tool_dispatcher)
.prompt_builder(prompt_builder)
.config(effective_agent_config)
@@ -1007,14 +806,9 @@ impl OpenHumanSessionHost {
catalogue.extend(crate::flows::catalogue::flow_entries(config));
catalogue
})
- .auto_save(config.memory.auto_save)
.post_turn_hooks(post_turn_hooks)
- .learning_enabled(config.learning.enabled)
- .explicit_preferences_enabled(config.learning.explicit_preferences_enabled)
.agent_definition_name(agent_id.to_string())
- .omit_profile(effective_omit_profile)
- .omit_memory_md(effective_omit_memory_md)
- .trigger_memory_agent(effective_trigger_memory_agent)
+ .omit_memory_context(effective_omit_memory_context)
.tokenjuice_compression(effective_tokenjuice_compression);
if let Some(ps) = payload_summarizer {
builder = builder.payload_summarizer(ps);
@@ -1025,7 +819,6 @@ impl OpenHumanSessionHost {
if let Some(policy) = host_policy {
builder = builder.tool_policy(policy);
}
- builder = builder.archivist_hook(archivist_hook_arc);
let mut agent = builder.build()?;
let connected_integrations_initialized = prewarmed_integrations.is_some();
agent.connected_integrations = prewarmed_integrations.unwrap_or_default();
@@ -1040,7 +833,6 @@ impl OpenHumanSessionHost {
config: Arc::clone(&base_config),
definitions,
security_policy: security,
- memory: agent.memory_arc(),
post_turn_hooks: agent.post_turn_hooks.clone(),
// The caller's own definition, when this session was built from
// one rather than from a registry id. `AgentSpec::into_core`