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(agent): consolidate prompt surface refresh into one call
Steven Enamakelaa6b0dfecdc6
diff --git a/crates/openhuman-core/src/agent/session_host/turn/mod.rs b/crates/openhuman-core/src/agent/session_host/turn/mod.rsindex 808ea78744..0b75f0aa61 100644--- a/crates/openhuman-core/src/agent/session_host/turn/mod.rs+++ b/crates/openhuman-core/src/agent/session_host/turn/mod.rs@@ -4,6 +4,4 @@//! `tinyagents_runtime::Session` in `runtime_session`.mod context;-#[path = "../../../integrations/host_refresh.rs"]-mod tools;pub(crate) mod graph;diff --git a/crates/openhuman-core/src/core/agent_cli/debug/mod.rs b/crates/openhuman-core/src/core/agent_cli/debug/mod.rsindex 766809fa14..ecc96acf60 100644--- a/crates/openhuman-core/src/core/agent_cli/debug/mod.rs+++ b/crates/openhuman-core/src/core/agent_cli/debug/mod.rs@@ -182,14 +182,9 @@ async fn render_via_session(config: &Config, agent_id: &str) -> Result<DumpedPro).with_context(|| format!("building session agent for `{agent_id}`"))?;- // Match turn-1 behaviour: fetch the user's active Composio- // connections so the rendered prompt mirrors what the LLM actually- // sees. Best-effort — failures degrade to an empty integration- // list, same as the live runtime.- agent.fetch_connected_integrations().await;- // Mirror turn-1: synthesise `delegate_*` tools for connected- // Composio toolkits now that we know what's actually authorised.- agent.refresh_delegation_tools();+ // Use the live turn prelude's hydration and surface reconciliation so this+ // snapshot matches what the runtime will send, without starting a model turn.+ agent.refresh_prompt_surface().await;let text = agent.build_system_prompt()diff --git a/crates/openhuman-core/src/integrations/host_refresh.rs b/crates/openhuman-core/src/integrations/host_refresh.rsdeleted file mode 100644index 2548a3953b..0000000000--- a/crates/openhuman-core/src/integrations/host_refresh.rs+++ /dev/null@@ -1,246 +0,0 @@-//! Tool execution and Composio delegation refresh.--use super::super::types::OpenHumanSessionHost;--use std::sync::Arc;--impl OpenHumanSessionHost {- // ─────────────────────────────────────────────────────────────────- // Sub-agent context snapshots- // ─────────────────────────────────────────────────────────────────-- /// Fetches the user's active Composio connections and populates- /// `self.connected_integrations` so the system prompt can surface them.- ///- /// Delegates to the shared [`crate::integrations::composio::fetch_connected_integrations`]- /// which is the single source of truth for integration discovery.- ///- /// **No session-scoped Composio client is cached on the agent any- /// more (#1710 Wave 2)**. Every downstream caller that needs to- /// dispatch a Composio action now resolves a fresh client via- /// [`crate::integrations::composio::client::resolve_composio_route`]- /// at call time so the live `composio.mode` toggle is honoured- /// without rebuilding the session — see `ComposioActionTool`,- /// `ProviderContext::execute`, the 5 migrated agent tools in- /// `composio/tools.rs`, and the spawn-time per-action tool build- /// path in `subagent_host/ops.rs`.- pub async fn fetch_connected_integrations(&mut self) {- let config = match self.runtime_config.clone() {- Some(config) => config,- None => match crate::config::Config::load_or_init().await {- Ok(config) => Arc::new(config),- Err(e) => {- log::debug!(- "[agent] skipping connected integrations fetch: config load failed: {e}"- );- return;- }- },- };- self.connected_integrations =- crate::integrations::composio::fetch_connected_integrations(&config).await;- self.connected_integrations_initialized = true;- }-- /// Re-synthesise `delegate_*` tools for the orchestrator's `subagents`- /// declaration using the live `connected_integrations` slice, and- /// reconcile the resulting set into `self.synthesized_tools` /- /// `self.tool_specs` / `self.visible_tool_specs` / `self.visible_tool_names`.- /// `self.tools` is never touched.- ///- /// **Reconciliation strategy** — full rebuild of the synthesised- /// subset:- ///- /// 1. Drop every spec whose name was in [`Self::synthesized_tool_names`]- /// from the previous synthesis. Direct tools (`query_memory`,- /// `cron_add`, …) are untouched because their names are not in- /// that set.- /// 2. Append the fresh specs, and replace [`Self::synthesized_tools`]- /// with the fresh instances — minus any name a durable tool owns,- /// which the durable tool keeps (the same rule the builder applies).- /// 3. Replace `synthesized_tool_names` with the new set so the- /// next refresh has a clean mask to undo.- ///- /// This is safer than appending-only or strict-diff reconcile:- ///- /// * Stale tools after a revoke can never leak — anything from the- /// previous synthesis is unconditionally dropped, the new set is- /// authoritative.- /// * Direct tools can never be accidentally removed — only names- /// in `synthesized_tool_names` are touched, and a durable name is- /// never added to that mask.- /// * Duplicate registration is impossible — the fresh set replaces the- /// previous one wholesale and is disjoint from `self.tools`, so a- /// name is registered at most once across both sets.- ///- /// **When to call**: on turn 1 only when the session was built- /// without a prewarmed Composio cache snapshot, and on any- /// subsequent turn where the connection set has changed since the- /// last reconcile (detected via- /// [`Self::last_seen_integrations_hash`] vs.- /// [`crate::integrations::composio::cached_active_integrations`]).- ///- /// **Concurrency**: this cannot fail on a shared session. The synthesised- /// instances live in their own [`OpenHumanSessionHost::synthesized_tools`] `Arc`, which is- /// *replaced* rather than mutated in place — so an in-flight turn or a- /// spawned sub-agent holding a clone never blocks reconciliation. Those- /// readers keep the previous, self-consistent set for the rest of their- /// turn; the superseded instances are freed when the last of them drops.- ///- /// This is what makes the schema and the executable surface inseparable.- /// Reconciling into `self.tools` instead required `Arc::get_mut`, which- /// fails under exactly that sharing — and the old code proceeded to- /// reconcile `tool_specs` anyway, so the two halves drifted: a newly- /// connected toolkit's delegate had a spec with no instance (and no policy- /// decision, so the fail-closed visibility filter hid it — silently missing- /// until a unique-owner refresh) while a revoked toolkit's delegate kept its- /// instance with no spec — still registered and callable (#6145).- ///- /// Returns nothing: with the synthesised set held in its own `Arc` there is- /// no longer a way for this to half-apply, so the `bool` it used to hand- /// back — and the caller rollback keyed on it — had no reachable `false`.- pub fn refresh_delegation_tools(&mut self) {- use crate::agent_registry::host_definition::AgentDefinitionRegistry;- use crate::tools::orchestrator_tools::collect_orchestrator_tools;-- let Some(reg) = AgentDefinitionRegistry::current() else {- // No registry — there's nothing we can do until the- // registry is initialised. The agent's surface stays at- // whatever the builder produced.- return;- };- let Some(def) = self.resolved_definition() else {- log::debug!(- "[agent] refresh_delegation_tools: definition '{}' not in registry — skipping",- self.agent_definition_id- );- return;- };- if def.subagents.is_empty() {- return;- }-- // A durable name wins a collision, exactly as at build time. Filtering- // here also keeps such a name out of the mask below, so the spec- // `retain` can never withdraw a durable tool's spec.- let synthed = super::super::builder::drop_synthesized_name_collisions(- &self.tools,- collect_orchestrator_tools(&def, ®, &self.connected_integrations),- );- let synthed_names: std::collections::HashSet<String> =- synthed.iter().map(|t| t.name().to_string()).collect();- let synthed_specs: Vec<Arc<tinytools::ToolSpec>> =- synthed.iter().map(|t| Arc::new(t.spec())).collect();-- // Skip mutation when neither the previous nor the next synthesis- // produced any names — saves work on agents without dynamic- // delegation. `synthesized_tools` is already empty in that state, so- // there is nothing to publish either.- if self.synthesized_tool_names.is_empty() && synthed_names.is_empty() {- return;- }-- // Mask of the previous synthesis — the names whose `tool_specs` are- // currently live (this set is kept in lock-step with `tool_specs`).- let old_synth = std::mem::take(&mut self.synthesized_tool_names);-- // `tool_specs` are plain data and therefore cloneable. Drop exactly the- // previous synthesised spec set, then append the fresh one.- {- let specs_vec = Arc::make_mut(&mut self.tool_specs);- specs_vec.retain(|s| !old_synth.contains(&s.name));- specs_vec.extend(synthed_specs);- }-- // The executable instances are replaced wholesale. `synthed` already IS- // the complete new set — `collect_orchestrator_tools` rebuilds every- // delegate from the current connection set — so there is nothing to- // retain and no mask to apply: assigning a fresh `Arc` drops exactly- // the previous synthesis and nothing else.- //- // This is the step that used to be conditional on `Arc::get_mut`- // succeeding against `self.tools`. It no longer touches `self.tools` at- // all, so a concurrent reader cannot block it, and the specs above and- // the instances here can never drift apart again (#6145).- // Readers still holding the previous `Arc` keep a coherent set for the- // rest of their turn; those instances are freed when the last one goes.- let previous_instances = self.synthesized_tools.len();- self.synthesized_tools = Arc::new(synthed);- // The pack tool's handle holds a `Weak` into the allocation that was- // just replaced. Without this re-bind it stops upgrading once the last- // reader of the old set goes, and every packed delegate — `do_crypto`,- // `make_presentation`, `create_image`, … — answers "no tool in skill"- // instead of running: withheld from the wire and unreachable through- // the route that replaced it.- crate::tools::toolpacks::bind_synthesized_pack_registry(- &self.tools,- &self.synthesized_tools,- );-- // `visible_tool_names` carries an explicit allowlist for- // [`ToolScope::Named`] agents. Drop the previously-synthesised- // names and add the new ones so the visible set tracks the- // tool list. Wildcard-scope agents keep this empty ("no- // filter") and never need touching.- if !self.visible_tool_names.is_empty() {- for name in &old_synth {- self.visible_tool_names.remove(name);- }- for name in &synthed_names {- self.visible_tool_names.insert(name.clone());- }- // The synthesis above re-adds delegate names wholesale, including- // any that belong to a tool pack — so re-apply the withholding here- // or a packed `delegate_*` tool would reappear on the wire on the- // first Composio reconcile, silently undoing the compression.- let agent_id = self.agent_definition_name.clone();- crate::tools::toolpacks::strip_packed_from_visible(- &mut self.visible_tool_names,- &agent_id,- );- }- // The synthesis above can carry `Deferred` entries (per-action- // integration tools for a newly connected toolkit); keep them off the- // wire and in the searchable set, exactly as the build did.- self.recompute_deferred_tool_names();-- // Rebuild the visible-spec cache from the new tool_specs so the- // next provider call carries the reconciled schema. Dedup- // afterward so a delegate synthesised here (e.g.- // `delegate_name = "plan"`) doesn't collide with a- // same-named skill tool on the wire — Anthropic 400s on dup- // tool names where OpenHuman's backend silently accepts.- self.rebuild_tool_policy_session();- self.sync_runtime_tool_surface();-- // Compute add/remove deltas for the log line — useful when- // diagnosing a Composio connect/revoke that should have rebuilt- // the surface but didn't. Materialise to owned `Vec<String>`- // so we can move `synthed_names` into `self.synthesized_tool_names`- // below without the log-statement reborrow blocking the move.- let added: Vec<String> = synthed_names- .iter()- .filter(|n| !old_synth.contains(n.as_str()))- .cloned()- .collect();- let removed: Vec<String> = old_synth- .iter()- .filter(|n| !synthed_names.contains(n.as_str()))- .cloned()- .collect();-- // Specs and instances reconciled to the same set in the same pass, so- // the name mask tracks that set unconditionally.- self.synthesized_tool_names = synthed_names.clone();-- log::info!(- "[agent] refresh_delegation_tools: reconciled delegation surface for agent '{}' (display='{}'); now {} synthesised tool name(s); added={:?} removed={:?} superseded_instances={}",- self.agent_definition_id,- self.agent_definition_name,- synthed_names.len(),- added,- removed,- previous_instances- );- }-}diff --git a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs b/crates/openhuman-core/src/mcp/server/tools/dispatch.rsindex 2fe88f5418..94b4751083 100644--- a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs+++ b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs@@ -232,8 +232,7 @@ async fn build_orchestrator_agent(.map_err(|err| {ToolCallError::Internal(format!("failed to build orchestrator agent: {err}"))})?;- agent.fetch_connected_integrations().await;- agent.refresh_delegation_tools();+ agent.refresh_prompt_surface().await;Ok(agent)}@@ -356,8 +355,7 @@ async fn run_subagent_tool(format!("mcp:{}:{}", agent_id, uuid::Uuid::new_v4()),"mcp_server",);- agent.fetch_connected_integrations().await;- agent.refresh_delegation_tools();+ agent.refresh_prompt_surface().await;// The MCP server surface exposes openhuman agents to remote MCP// clients. Treat callers as ExternalChannel — their prompt text isdiff --git a/crates/openhuman-core/src/plan_review/gate_tests.rs b/crates/openhuman-core/src/plan_review/gate_tests.rsindex 96fed577ff..3335ea5506 100644--- a/crates/openhuman-core/src/plan_review/gate_tests.rs+++ b/crates/openhuman-core/src/plan_review/gate_tests.rs@@ -1,5 +1,9 @@use super::*;+fn tenant() -> crate::core::runtime::Tenant {+ crate::core::runtime::Tenant::default()+}+#[tokio::test]async fn approve_resolves_parked_turn() {let gate = PlanReviewGate::new(Duration::from_secs(5));@@ -7,6 +11,7 @@ async fn approve_resolves_parked_turn() {let g2 = gate.clone();let parked = tokio::spawn(async move {g2.request_review(+ tenant(),Some("t1".into()),Some("c1".into()),"Ship it".into(),@@ -17,7 +22,7 @@ async fn approve_resolves_parked_turn() {});// Let the park register the waiter.tokio::time::sleep(Duration::from_millis(20)).await;- assert!(gate.decide_by_thread("t1", PlanReviewResolution::Approve));+ assert!(gate.decide_by_thread(&tenant(), "t1", PlanReviewResolution::Approve));assert_eq!(parked.await.unwrap(), PlanReviewResolution::Approve);}@@ -26,12 +31,12 @@ async fn revise_carries_feedback_back() {let gate = std::sync::Arc::new(PlanReviewGate::new(Duration::from_secs(5)));let g2 = gate.clone();let parked = tokio::spawn(async move {- g2.request_review(Some("t2".into()), None, "Plan".into(), vec![], None)+ g2.request_review(tenant(), Some("t2".into()), None, "Plan".into(), vec![], None).await});tokio::time::sleep(Duration::from_millis(20)).await;assert!(gate.decide_by_thread(- "t2",+ &tenant(), "t2",PlanReviewResolution::Revise {feedback: "add a test step".into(),},@@ -48,17 +53,17 @@ async fn revise_carries_feedback_back() {async fn timeout_fails_closed_to_reject() {let gate = PlanReviewGate::new(Duration::from_millis(40));let resolution = gate- .request_review(Some("t3".into()), None, "Plan".into(), vec![], None)+ .request_review(tenant(), Some("t3".into()), None, "Plan".into(), vec![], None).await;assert_eq!(resolution, PlanReviewResolution::Reject);// The waiter is cleaned up after timeout.- assert!(!gate.decide_by_thread("t3", PlanReviewResolution::Approve));+ assert!(!gate.decide_by_thread(&tenant(), "t3", PlanReviewResolution::Approve));}#[tokio::test]async fn decide_unknown_request_is_false() {let gate = PlanReviewGate::new(Duration::from_secs(5));- assert!(!gate.decide("nope", PlanReviewResolution::Approve));+ assert!(!gate.decide(&tenant(), "nope", PlanReviewResolution::Approve));}#[tokio::test]@@ -68,14 +73,14 @@ async fn cancelled_park_cleans_up_waiter() {let gate = std::sync::Arc::new(PlanReviewGate::new(Duration::from_secs(30)));let g2 = gate.clone();let handle = tokio::spawn(async move {- g2.request_review(Some("t-drop".into()), None, "Plan".into(), vec![], None)+ g2.request_review(tenant(), Some("t-drop".into()), None, "Plan".into(), vec![], None).await});tokio::time::sleep(Duration::from_millis(20)).await;handle.abort();let _ = handle.await;// The drop guard removed the entry, so there is nothing left to decide.- assert!(!gate.decide_by_thread("t-drop", PlanReviewResolution::Approve));+ assert!(!gate.decide_by_thread(&tenant(), "t-drop", PlanReviewResolution::Approve));}#[tokio::test]@@ -84,6 +89,7 @@ async fn parked_review_for_thread_carries_tool_call_id_and_expiry() {let g2 = gate.clone();let parked = tokio::spawn(async move {g2.request_review(+ tenant(),Some("t-replay".into()),Some("c-replay".into()),"Ship it".into(),@@ -95,7 +101,7 @@ async fn parked_review_for_thread_carries_tool_call_id_and_expiry() {tokio::time::sleep(Duration::from_millis(20)).await;let row = gate- .parked_review_for_thread("t-replay")+ .parked_review_for_thread(&tenant(), "t-replay").expect("review should be parked");assert_eq!(row.thread_id, Some("t-replay".to_string()));assert_eq!(row.client_id, Some("c-replay".to_string()));@@ -103,17 +109,17 @@ async fn parked_review_for_thread_carries_tool_call_id_and_expiry() {assert!(row.expires_at.is_some());assert_eq!(row.steps, vec!["step one".to_string()]);- assert!(gate.decide_by_thread("t-replay", PlanReviewResolution::Approve));+ assert!(gate.decide_by_thread(&tenant(), "t-replay", PlanReviewResolution::Approve));parked.await.unwrap();// Decided reviews are no longer parked.- assert!(gate.parked_review_for_thread("t-replay").is_none());+ assert!(gate.parked_review_for_thread(&tenant(), "t-replay").is_none());}#[tokio::test]async fn parked_review_for_thread_is_none_when_nothing_is_parked() {let gate = PlanReviewGate::new(Duration::from_secs(5));- assert!(gate.parked_review_for_thread("no-such-thread").is_none());+ assert!(gate.parked_review_for_thread(&tenant(), "no-such-thread").is_none());}#[tokio::test]diff --git a/vendor/tinyagents b/vendor/tinyagentsindex 7ddcc6a631..78b1555291 160000--- a/vendor/tinyagents+++ b/vendor/tinyagents@@ -1 +1 @@-Subproject commit 7ddcc6a631fb7b2e27b0c5401fb477a1a8cea690+Subproject commit 78b15552912a99d54831d8dec22962941c0899a2