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: add recorded tools module
Steven Enamakel04c9b2d18ab4
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools.rsnew file mode 100644index 0000000000..011c460f0f--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs@@ -0,0 +1,84 @@+//! Rebuilds the executors a resumed thread already declared to the model.+//!+//! The tinyagents session records the exact tool declarations each turn was+//! sent with and hands them back on resume (`SessionStateView::recorded_tools`).+//! A new process, though, rebuilds its live tool surface from state that may+//! not be there yet: Composio actions are synthesised from the connected+//! integrations list, which comes from a 60 s process cache that is empty+//! after a restart and may be unreachable. Without a fallback, a resumed+//! thread whose prompt says "search for the Gmail action" loses every+//! integration action — and with it the `tool_search` bridge — for the turn.+//!+//! This module turns the recorded Composio action declarations back into+//! executable deferred tools, so the tool list a thread was sent never+//! shrinks just because a cache went cold. The live surface stays+//! authoritative for any action it still supplies.++use std::collections::HashSet;++use tinytools::{Tool, ToolSpec};++use crate::integrations::composio::action_tool::ComposioActionTool;++/// Whether `name` is a Composio action slug (`GMAIL_SEND_EMAIL`).+///+/// Composio slugs are upper-case `TOOLKIT_ACTION`; every OpenHuman-owned tool+/// name is lower-case snake case, so the shapes never overlap.+pub(super) fn is_integration_action_name(name: &str) -> bool {+ let mut parts = name.splitn(2, '_');+ let (Some(toolkit), Some(action)) = (parts.next(), parts.next()) else {+ return false;+ };+ !toolkit.is_empty()+ && !action.is_empty()+ && name+ .chars()+ .all(|ch| ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_')+}++/// The toolkit slug an action slug belongs to (`GMAIL_SEND_EMAIL` → `gmail`).+/// Only used as the tool's search family.+fn toolkit_of(action: &str) -> String {+ action+ .split('_')+ .next()+ .unwrap_or(action)+ .to_ascii_lowercase()+}++/// The recorded integration action declarations, in recorded order.+pub(super) fn recorded_integration_actions(recorded: &[ToolSpec]) -> Vec<ToolSpec> {+ recorded+ .iter()+ .filter(|spec| is_integration_action_name(&spec.name))+ .cloned()+ .collect()+}++/// Deferred executors for every recorded action the live set does not+/// already provide. `live` names win: a still-connected integration keeps+/// its freshly fetched declaration.+pub(super) fn rehydrate_integration_actions(+ recorded: &[ToolSpec],+ live: &[Box<dyn Tool>],+) -> Vec<Box<dyn Tool>> {+ let live_names: HashSet<&str> = live.iter().map(|tool| tool.name()).collect();+ let mut seen = HashSet::new();+ recorded+ .iter()+ .filter(|spec| !live_names.contains(spec.name.as_str()))+ .filter(|spec| seen.insert(spec.name.clone()))+ .map(|spec| {+ Box::new(ComposioActionTool::deferred(+ &toolkit_of(&spec.name),+ spec.name.clone(),+ spec.description.clone(),+ Some(spec.parameters.clone()),+ )) as Box<dyn Tool>+ })+ .collect()+}++#[cfg(test)]+#[path = "recorded_tools_tests.rs"]+mod tests;