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
chore(openhuman-core): update session host runtime imports
Steven Enamakel51b5cd9239cb
diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rsnew file mode 100644index 0000000000..27eb6090af--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs@@ -0,0 +1,207 @@+//! Turn-boundary refresh of the prelude's integration state: hydrating the+//! connected integrations a session starts without, tracking connects and+//! revokes between turns, and adopting the integration actions the tinyagents+//! session restored for a resumed thread.++use tinyagents_runtime::ToolSnapshot;++use super::OpenHumanTurnPrelude;++impl OpenHumanTurnPrelude {++ /// Takes the declarations the tinyagents session restored for this+ /// thread. Called before the boundary refresh so the rebuilt surface can+ /// include them.+ pub(super) fn adopt_recorded_tools(&self, recorded: Option<&ToolSnapshot>) {+ let Some(recorded) = recorded else {+ return;+ };+ let actions = super::recorded_tools::recorded_integration_actions(recorded.specs());+ if actions.is_empty() {+ return;+ }+ log::debug!(+ "[session] adopting {} recorded integration action declaration(s) agent={}",+ actions.len(),+ self.agent_definition_id+ );+ self.mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .recorded_integration_actions = actions;+ }++ pub(super) async fn refresh_turn_boundary(&self, cold: bool) {+ // Hydrate on the first turn of *this session instance*, not only on a+ // brand-new thread. A resumed thread is never `cold`, and a session+ // rebuilt after a restart (or any rebuild past the 60 s integrations+ // cache TTL) is seeded from an empty cache — gating the fetch on+ // `cold` left it with zero integrations, no deferred Composio+ // actions, and no `tool_search` bridge for the whole thread.+ // `refresh_cold_integrations` is a no-op once hydrated.+ self.refresh_cold_integrations().await;+ if !cold {+ self.refresh_dynamic_announcements().await;+ }+ // Integration changes are authority changes, not only display+ // announcements. Refresh the delegation executable set and rebuild+ // its schema/policy in the same hook pass before the driver sees it.+ self.refresh_delegation_tool_surface();+ }+++ pub(super) async fn refresh_cold_integrations(&self) {+ let should_fetch = !self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .connected_integrations_initialized;+ if !should_fetch {+ return;+ }+ let config = match self.runtime_config.clone() {+ Some(config) => Some(config),+ None => crate::config::Config::load_or_init()+ .await+ .ok()+ .map(Arc::new),+ };+ let Some(config) = config else {+ return;+ };+ let Some(connected) = load_connected_integrations(&config).await else {+ // Backend unreachable and nothing cached: stay un-hydrated so the+ // next turn retries rather than pinning an empty surface.+ log::warn!(+ "[session] integrations unavailable and no cached snapshot; will retry next turn agent={}",+ self.agent_definition_id+ );+ return;+ };+ log::info!(+ "[session] hydrated connected integrations count={} agent={}",+ connected.len(),+ self.agent_definition_id+ );+ let mcp_servers = crate::mcp::registry::connections::connected_overview()+ .await+ .into_iter()+ .map(|server| server.qualified_name)+ .collect::<std::collections::HashSet<_>>();+ let mut mutable = self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ mutable.connected_integrations = connected;+ mutable.connected_integrations_initialized = true;+ mutable.announced_integrations = mutable+ .connected_integrations+ .iter()+ .map(|item| item.toolkit.clone())+ .collect();+ mutable.announced_mcp_servers = mcp_servers;+ }++ pub(super) async fn refresh_dynamic_announcements(&self) {+ let skills_changed = self.drain_host_events();+ if let Some(config) = self.runtime_config.as_deref() {+ // An expired cache is refetched rather than skipped, so a+ // long-lived session keeps tracking connects/revokes.+ let current = match crate::integrations::composio::cached_active_integrations(config) {+ Some(current) => Some(current),+ None => load_connected_integrations(config).await,+ };+ if let Some(current) = current {+ let mut mutable = self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ let current_slugs: std::collections::HashSet<_> =+ current.iter().map(|item| item.toolkit.clone()).collect();+ for slug in ¤t_slugs {+ if mutable.announced_integrations.insert(slug.clone())+ && !mutable.pending_integration_announcement.contains(slug)+ {+ mutable.pending_integration_announcement.push(slug.clone());+ }+ }+ mutable.connected_integrations = current;+ }+ }+ let connected_mcp = crate::mcp::registry::connections::connected_overview()+ .await+ .into_iter()+ .map(|server| server.qualified_name)+ .collect::<Vec<_>>();+ let mut mutable = self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ for server in connected_mcp {+ if mutable.announced_mcp_servers.insert(server.clone())+ && !mutable.pending_mcp_announcement.contains(&server)+ {+ mutable.pending_mcp_announcement.push(server);+ }+ }+ if !skills_changed {+ return;+ }+ // Event-driven metadata refresh keeps the steady-state hot path free+ // of the old per-turn filesystem scan.+ let latest = crate::skills::load_workflow_metadata(&self.workspace_dir);+ let id = |workflow: &crate::skills::Workflow| {+ if workflow.dir_name.is_empty() {+ workflow.name.clone()+ } else {+ workflow.dir_name.clone()+ }+ };+ let previous: std::collections::HashSet<_> = mutable.workflows.iter().map(&id).collect();+ let current: std::collections::HashSet<_> = latest.iter().map(&id).collect();+ for id in current.difference(&previous) {+ if mutable.announced_skills.insert((*id).clone())+ && !mutable.pending_skill_announcement.contains(id)+ {+ mutable.pending_skill_announcement.push((*id).clone());+ }+ }+ for id in previous.difference(¤t) {+ mutable.announced_skills.remove(id);+ mutable+ .pending_skill_announcement+ .retain(|pending| pending != id);+ if !mutable.pending_skill_retraction.contains(id) {+ mutable.pending_skill_retraction.push((*id).clone());+ }+ }+ mutable.workflows = latest;+ }++ /// Rebuild every delegation-dependent tool view from the current cached+ /// integration set. This mirrors the legacy refresh's replace-not-append+ /// semantics, but keeps the mutable authority in hook state rather than a+ /// second turn loop. A revoked delegate is removed from the executable+ /// source, schema, and policy together before this request is prepared.+}++/// Live connected integrations, falling back to the last cached snapshot+/// (even past its TTL) when the backend is unreachable. `None` only when+/// there is neither a live answer nor any snapshot to fall back to.+async fn load_connected_integrations(+ config: &crate::config::Config,+) -> Option<Vec<crate::agent::prompts::ConnectedIntegration>> {+ use crate::integrations::composio::FetchConnectedIntegrationsStatus;+ match crate::integrations::composio::fetch_connected_integrations_status(config).await {+ FetchConnectedIntegrationsStatus::Authoritative(connected) => Some(connected),+ FetchConnectedIntegrationsStatus::Unavailable => {+ let stale =+ crate::integrations::composio::cached_active_integrations_including_expired(config);+ log::warn!(+ "[session] integrations fetch unavailable; using stale snapshot={}",+ stale.as_ref().map_or(0, Vec::len)+ );+ stale+ }+ }+}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex b1ffb3f0c6..0f794728a3 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -227,47 +227,6 @@ impl OpenHumanTurnPrelude {exact_tools: false,})}-- /// Takes the declarations the tinyagents session restored for this- /// thread. Called before the boundary refresh so the rebuilt surface can- /// include them.- fn adopt_recorded_tools(&self, recorded: Option<&ToolSnapshot>) {- let Some(recorded) = recorded else {- return;- };- let actions = super::recorded_tools::recorded_integration_actions(recorded.specs());- if actions.is_empty() {- return;- }- log::debug!(- "[session] adopting {} recorded integration action declaration(s) agent={}",- actions.len(),- self.agent_definition_id- );- self.mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .recorded_integration_actions = actions;- }-- async fn refresh_turn_boundary(&self, cold: bool) {- // Hydrate on the first turn of *this session instance*, not only on a- // brand-new thread. A resumed thread is never `cold`, and a session- // rebuilt after a restart (or any rebuild past the 60 s integrations- // cache TTL) is seeded from an empty cache — gating the fetch on- // `cold` left it with zero integrations, no deferred Composio- // actions, and no `tool_search` bridge for the whole thread.- // `refresh_cold_integrations` is a no-op once hydrated.- self.refresh_cold_integrations().await;- if !cold {- self.refresh_dynamic_announcements().await;- }- // Integration changes are authority changes, not only display- // announcements. Refresh the delegation executable set and rebuild- // its schema/policy in the same hook pass before the driver sees it.- self.refresh_delegation_tool_surface();- }-fn begin_user_effects(&self, state: &mut OpenHumanSessionState, request: &SessionTurnRequest) {let user_text = request.input.text();if self.auto_save && crate::agent::turn_origin::current_is_user_authored() {@@ -433,140 +392,6 @@ impl OpenHumanTurnPrelude {.unwrap_or_else(std::sync::PoisonError::into_inner).build_system_prompt_tiered(&context)}-- async fn refresh_cold_integrations(&self) {- let should_fetch = !self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .connected_integrations_initialized;- if !should_fetch {- return;- }- let config = match self.runtime_config.clone() {- Some(config) => Some(config),- None => crate::config::Config::load_or_init()- .await- .ok()- .map(Arc::new),- };- let Some(config) = config else {- return;- };- let Some(connected) = load_connected_integrations(&config).await else {- // Backend unreachable and nothing cached: stay un-hydrated so the- // next turn retries rather than pinning an empty surface.- log::warn!(- "[session] integrations unavailable and no cached snapshot; will retry next turn agent={}",- self.agent_definition_id- );- return;- };- log::info!(- "[session] hydrated connected integrations count={} agent={}",- connected.len(),- self.agent_definition_id- );- let mcp_servers = crate::mcp::registry::connections::connected_overview()- .await- .into_iter()- .map(|server| server.qualified_name)- .collect::<std::collections::HashSet<_>>();- let mut mutable = self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- mutable.connected_integrations = connected;- mutable.connected_integrations_initialized = true;- mutable.announced_integrations = mutable- .connected_integrations- .iter()- .map(|item| item.toolkit.clone())- .collect();- mutable.announced_mcp_servers = mcp_servers;- }-- async fn refresh_dynamic_announcements(&self) {- let skills_changed = self.drain_host_events();- if let Some(config) = self.runtime_config.as_deref() {- // An expired cache is refetched rather than skipped, so a- // long-lived session keeps tracking connects/revokes.- let current = match crate::integrations::composio::cached_active_integrations(config) {- Some(current) => Some(current),- None => load_connected_integrations(config).await,- };- if let Some(current) = current {- let mut mutable = self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- let current_slugs: std::collections::HashSet<_> =- current.iter().map(|item| item.toolkit.clone()).collect();- for slug in ¤t_slugs {- if mutable.announced_integrations.insert(slug.clone())- && !mutable.pending_integration_announcement.contains(slug)- {- mutable.pending_integration_announcement.push(slug.clone());- }- }- mutable.connected_integrations = current;- }- }- let connected_mcp = crate::mcp::registry::connections::connected_overview()- .await- .into_iter()- .map(|server| server.qualified_name)- .collect::<Vec<_>>();- let mut mutable = self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- for server in connected_mcp {- if mutable.announced_mcp_servers.insert(server.clone())- && !mutable.pending_mcp_announcement.contains(&server)- {- mutable.pending_mcp_announcement.push(server);- }- }- if !skills_changed {- return;- }- // Event-driven metadata refresh keeps the steady-state hot path free- // of the old per-turn filesystem scan.- let latest = crate::skills::load_workflow_metadata(&self.workspace_dir);- let id = |workflow: &crate::skills::Workflow| {- if workflow.dir_name.is_empty() {- workflow.name.clone()- } else {- workflow.dir_name.clone()- }- };- let previous: std::collections::HashSet<_> = mutable.workflows.iter().map(&id).collect();- let current: std::collections::HashSet<_> = latest.iter().map(&id).collect();- for id in current.difference(&previous) {- if mutable.announced_skills.insert((*id).clone())- && !mutable.pending_skill_announcement.contains(id)- {- mutable.pending_skill_announcement.push((*id).clone());- }- }- for id in previous.difference(¤t) {- mutable.announced_skills.remove(id);- mutable- .pending_skill_announcement- .retain(|pending| pending != id);- if !mutable.pending_skill_retraction.contains(id) {- mutable.pending_skill_retraction.push((*id).clone());- }- }- mutable.workflows = latest;- }-- /// Rebuild every delegation-dependent tool view from the current cached- /// integration set. This mirrors the legacy refresh's replace-not-append- /// semantics, but keeps the mutable authority in hook state rather than a- /// second turn loop. A revoked delegate is removed from the executable- /// source, schema, and policy together before this request is prepared.#[cfg(test)]fn synthesized_tool_names_for_test(&self) -> std::collections::HashSet<String> {self.tool_surface@@ -2076,26 +1901,8 @@ impl OpenHumanSessionHost {}}-/// Live connected integrations, falling back to the last cached snapshot-/// (even past its TTL) when the backend is unreachable. `None` only when-/// there is neither a live answer nor any snapshot to fall back to.-async fn load_connected_integrations(- config: &crate::config::Config,-) -> Option<Vec<crate::agent::prompts::ConnectedIntegration>> {- use crate::integrations::composio::FetchConnectedIntegrationsStatus;- match crate::integrations::composio::fetch_connected_integrations_status(config).await {- FetchConnectedIntegrationsStatus::Authoritative(connected) => Some(connected),- FetchConnectedIntegrationsStatus::Unavailable => {- let stale =- crate::integrations::composio::cached_active_integrations_including_expired(config);- log::warn!(- "[session] integrations fetch unavailable; using stale snapshot={}",- stale.as_ref().map_or(0, Vec::len)- );- stale- }- }-}+#[path = "prelude_integrations.rs"]+mod prelude_integrations;#[cfg(test)]#[path = "runtime_session_tests.rs"]