Skip to content

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

feat(tinyagents): discover and execute tiny agent turns

Steven Enamakele795c167ab3a
diff --git a/crates/openhuman-core/src/agent/tinyagents/discovery/mod.rs b/crates/openhuman-core/src/agent/tinyagents/discovery/mod.rs
index 9b1a63347a..1554910acf 100644
--- a/crates/openhuman-core/src/agent/tinyagents/discovery/mod.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/discovery/mod.rs
@@ -129,6 +129,23 @@ pub(crate) fn discovery_policy() -> ToolDiscoveryPolicy {
policy
}
+/// What a turn's `tool_search` tells its ranker about the search: the chat the
+/// turn runs in, so a ranker that discloses the query off the machine (a cloud
+/// embedder) can show the disclosure in that chat. A turn with no chat behind
+/// it (CLI, cron, a detached sub-agent) gets an empty context.
+pub(crate) fn rank_context_for(
+ chat: Option<&crate::security::approval::ApprovalChatContext>,
+) -> tinytools::RankContext {
+ let Some(chat) = chat else {
+ return tinytools::RankContext::empty();
+ };
+ let mut routed = tinytools::RankChat::new(chat.thread_id.clone(), chat.client_id.clone());
+ if let Some(request_id) = &chat.request_id {
+ routed = routed.with_request_id(request_id.clone());
+ }
+ tinytools::RankContext::empty().with_chat(routed)
+}
+
/// The `tool_search` bridge, rendered for a TEXT dialect's prompt catalogue.
///
/// The harness mints this schema onto `request.tools` whenever a run has a
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index b0ca40288e..bf8bd4cf91 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -188,7 +188,7 @@ async fn drive_turn(
// Thread-scoped tools (`goal_*`) are only registered when it is `Some`.
let has_thread = run_context.thread_id.is_some();
let is_subagent = subagent_scope.is_some();
- let (policy, has_route_fallback) = turn_run_policy(
+ let (mut policy, has_route_fallback) = turn_run_policy(
model,
max_iterations,
deterministic_cacheable,
@@ -202,6 +202,10 @@ async fn drive_turn(
run_context.tool_rules.clone(),
run_context.tool_call_limit,
);
+ // A `tool_search` of this turn tells its ranker which chat it runs in, so a
+ // cloud embedder's disclosure reaches that chat.
+ policy.discovery.rank_context =
+ crate::agent::tinyagents::discovery::rank_context_for(run_context.approval.chat.as_ref());
// The turn's crate `ChatModel` set (`turn_models`) and the provider telemetry id are built by
// the caller via `build_turn_models`: the seam is crate-native and names no `Provider` (#4249,
// Phase 5). The telemetry id (`{provider_id}.{model}` in Langfuse) rides in as a param.