Skip to content

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

refactor(session): flatten search-tool rehydration and move logging into the helper

Steven Enamakel6bdfb4133e08
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
index c00e38b823..82d65f3d0d 100644
--- a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
@@ -123,11 +123,15 @@ fn is_search_role_tool(name: &str) -> bool {
#[cfg(feature = "modules")]
pub(super) fn rehydrate_search_tools(
recorded: &[ToolSpec],
- live: &[Box<dyn Tool>],
+ live: &[&[Box<dyn Tool>]],
+ agent_id: &str,
) -> Vec<Box<dyn Tool>> {
- let live_names: HashSet<&str> = live.iter().map(|tool| tool.name()).collect();
+ let live_names: HashSet<&str> = live
+ .iter()
+ .flat_map(|tools| tools.iter().map(|tool| tool.name()))
+ .collect();
let mut seen = HashSet::new();
- recorded
+ let rebuilt: Vec<Box<dyn Tool>> = recorded
.iter()
.filter(|spec| is_search_role_tool(&spec.name))
.filter(|spec| !live_names.contains(spec.name.as_str()))
@@ -141,7 +145,14 @@ pub(super) fn rehydrate_search_tools(
},
)) as Box<dyn Tool>
})
- .collect()
+ .collect();
+ if !rebuilt.is_empty() {
+ log::info!(
+ "[session] rebuilt {} recorded search tool(s) the live surface did not supply agent={agent_id}",
+ rebuilt.len()
+ );
+ }
+ rebuilt
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
index a4ad9e4305..0cd2a3e876 100644
--- a/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
@@ -158,7 +158,7 @@ fn missing_search_tools_are_rebuilt_once_with_their_recorded_declaration() {
parameters: serde_json::json!({"type": "object"}),
},
))];
- let rebuilt = rehydrate_search_tools(&recorded, &live);
+ let rebuilt = rehydrate_search_tools(&recorded, &[live.as_slice()], "test-agent");
assert_eq!(rebuilt.len(), 1);
assert_eq!(rebuilt[0].name(), "web_answer_tool");
assert_eq!(rebuilt[0].description(), "web_answer_tool description");
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 6a0d5b11b0..d502379126 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -489,24 +489,12 @@ impl OpenHumanTurnPrelude {
.unwrap_or_else(std::sync::PoisonError::into_inner)
.recorded_search_tools
.clone();
- let mut present: Vec<&dyn tinytools::Tool> =
- surface.tools.iter().map(|tool| tool.as_ref()).collect();
- present.extend(collected.iter().map(|tool| tool.as_ref()));
- let present_names: std::collections::HashSet<String> =
- present.iter().map(|tool| tool.name().to_string()).collect();
- let missing: Vec<tinytools::ToolSpec> = recorded
- .into_iter()
- .filter(|spec| !present_names.contains(&spec.name))
- .collect();
- let rebuilt = super::recorded_tools::rehydrate_search_tools(&missing, &[]);
- if !rebuilt.is_empty() {
- log::info!(
- "[session] rebuilt {} recorded search tool(s) the live surface did not supply agent={}",
- rebuilt.len(),
- self.agent_definition_id
- );
- collected.extend(rebuilt);
- }
+ let rebuilt = super::recorded_tools::rehydrate_search_tools(
+ &recorded,
+ &[surface.tools.as_slice(), collected.as_slice()],
+ &self.agent_definition_id,
+ );
+ collected.extend(rebuilt);
}
let synthesized =
super::builder::drop_synthesized_name_collisions(&surface.tools, collected);