Skip to content

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

feat(tinyagents): register canonical tool aliases

Steven Enamakel57a5ad7868e8
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
index 29c8d02d4b..11f02ab16a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
@@ -1,7 +1,10 @@
//! Coverage for the host's tool registration over the runtime builder.
use super::*;
+use async_trait::async_trait;
+use std::sync::atomic::{AtomicBool, Ordering};
use tinyagents_harness::runtime::AgentHarness;
+use tinytools::{Tool, ToolCallOptions, ToolResult};
/// Register the real goal tools on a fresh harness and return the candidate
/// names handed on to the exposure layer.
@@ -69,3 +72,80 @@ async fn registered_memory_dispatch_enforces_one_budget_across_distinct_calls()
assert_eq!(result.is_error, index == 8, "call {index}");
}
}
+
+struct OriginObservingTool(Arc<AtomicBool>);
+
+#[async_trait]
+impl Tool for OriginObservingTool {
+ fn name(&self) -> &str {
+ "origin_observer"
+ }
+ fn description(&self) -> &str {
+ "Observes the per-turn core authority."
+ }
+ fn parameters_schema(&self) -> serde_json::Value {
+ serde_json::json!({"type":"object"})
+ }
+ async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
+ Ok(ToolResult::success("executed"))
+ }
+ async fn execute_with_context(
+ &self,
+ _args: serde_json::Value,
+ _options: ToolCallOptions,
+ _context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ self.0.store(
+ matches!(
+ crate::core::runtime::CoreContext::current_turn_origin(),
+ Some(crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel { .. })
+ ),
+ Ordering::SeqCst,
+ );
+ Ok(ToolResult::success("executed"))
+ }
+}
+
+#[tokio::test]
+async fn shared_adapter_scopes_tool_execution_to_the_run_origin() {
+ use tinyagents_harness::context::RunConfig;
+
+ let context =
+ crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
+ let observed = Arc::new(AtomicBool::new(false));
+ let tools: Vec<Arc<Vec<Box<dyn Tool>>>> = vec![Arc::new(vec![Box::new(OriginObservingTool(
+ observed.clone(),
+ ))])];
+ let adapter = shared_tool_adapter(tools, "origin_observer").unwrap();
+ let mut host = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ host.origin = Some(
+ crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel {
+ sender_name: None,
+ channel: "test".into(),
+ sender: None,
+ reply_target: "room".into(),
+ message_id: "message".into(),
+ history_key: None,
+ },
+ );
+ let run = host.into_tinyagents(RunConfig::new("origin-observer"));
+ let tool_context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(
+ &run,
+ tinyagents_harness::ids::CallId::new("call"),
+ );
+
+ crate::core::runtime::CoreContext::scope(context, async {
+ adapter
+ .execute_with_context(
+ serde_json::json!({}),
+ ToolCallOptions::default(),
+ Some(&tool_context),
+ )
+ .await
+ .expect("tool execution succeeds");
+ assert!(observed.load(Ordering::SeqCst));
+ assert!(crate::core::runtime::CoreContext::current_turn_origin().is_none());
+ })
+ .await;
+}
+
diff --git a/crates/openhuman-core/src/agent/tinyagents/tools.rs b/crates/openhuman-core/src/agent/tinyagents/tools.rs
deleted file mode 100644
index 4f2102f4a0..0000000000
--- a/crates/openhuman-core/src/agent/tinyagents/tools.rs
+++ /dev/null
@@ -1,258 +0,0 @@
-//! `tinyagents` [`Tool`] adapter over an openhuman [`Tool`] (issue #4249).
-//!
-//! It resolves a tool from the session's shared registry and delegates through
-//! the canonical `tinytools::Tool` contract without creating a second tool
-//! result vocabulary.
-
-use std::sync::{Arc, Mutex, PoisonError};
-
-use async_trait::async_trait;
-use tinyagents_harness::steering::{SteeringCommand, SteeringHandle};
-use tinytools::{Tool, ToolCallOptions, ToolResult, ToolRunContext};
-
-/// A captured early-exit: a sub-agent invoked an early-exit tool (e.g.
-/// `ask_user_clarification`), so the loop should pause and surface `question`
-/// to the user. Mirrors the legacy `run_turn_engine` `early_exit_tool` seam.
-#[derive(Debug, Clone)]
-pub(crate) struct EarlyExit {
- pub(crate) tool: String,
- pub(crate) question: String,
-}
-
-/// Shared early-exit hook handed to the adapters for the early-exit tool names.
-/// On a successful call to one of those tools it records the [`EarlyExit`] and
-/// sends a [`SteeringCommand::Pause`] so the harness loop short-circuits at the
-/// next checkpoint (before the next model call) — the tinyagents analogue of the
-/// legacy loop's "break on early-exit tool" behavior.
-#[derive(Clone)]
-pub(crate) struct EarlyExitHook {
- handle: SteeringHandle,
- slot: Arc<Mutex<Option<EarlyExit>>>,
-}
-
-impl EarlyExitHook {
- /// Build a hook that pauses `handle` and records into a fresh slot.
- pub(crate) fn new(handle: SteeringHandle) -> Self {
- Self {
- handle,
- slot: Arc::new(Mutex::new(None)),
- }
- }
-
- /// The captured early-exit, if one fired during the run.
- pub(crate) fn take(&self) -> Option<EarlyExit> {
- // #4469 item 3: recover a poisoned slot rather than panic — a panic while
- // some other tool held this lock must not swallow the early-exit.
- self.slot
- .lock()
- .unwrap_or_else(PoisonError::into_inner)
- .take()
- }
-
- /// Record an early-exit and request a cooperative pause. Only the first
- /// early-exit in a run is kept (matching the legacy "halt on first").
- fn trigger(&self, tool: &str, question: String) {
- {
- // #4469 item 3: `into_inner` keeps early-exit recording working even
- // if the slot mutex was poisoned by an unrelated panic.
- let mut slot = self.slot.lock().unwrap_or_else(PoisonError::into_inner);
- if slot.is_none() {
- *slot = Some(EarlyExit {
- tool: tool.to_string(),
- question,
- });
- }
- }
- tracing::info!(tool, "[tinyagents] early-exit tool — requesting pause");
- self.handle.send(SteeringCommand::Pause);
- }
-}
-
-/// Canonical TinyTools adapter over the shared session tool sets.
-///
-/// The runtime now executes the canonical `tinytools::Tool` contract directly;
-/// this wrapper only resolves a non-cloneable tool from the shared registry and
-/// preserves the early-exit control hook.
-pub(crate) struct CanonicalSharedToolAdapter {
- sets: Vec<Arc<Vec<Box<dyn Tool>>>>,
- name: String,
- description: String,
- parameters_schema: serde_json::Value,
- early_exit: Option<EarlyExitHook>,
- /// Report `Deferred` whatever the resolved tool says: the session serves
- /// this tool through `tool_search` for its own agent only.
- force_deferred: bool,
-}
-
-impl CanonicalSharedToolAdapter {
- pub(crate) fn for_name(sets: Vec<Arc<Vec<Box<dyn Tool>>>>, name: &str) -> Option<Self> {
- let spec = sets
- .iter()
- .flat_map(|set| set.iter())
- .find(|tool| tool.name() == name)
- .map(|tool| tool.spec())?;
- Some(Self {
- sets,
- name: spec.name,
- description: spec.description,
- parameters_schema: spec.parameters,
- early_exit: None,
- force_deferred: false,
- })
- }
-
- /// Register this tool as `Deferred` for the turn (see
- /// `OpenHumanRunContext::deferred_tool_names`). A `Hidden` tool stays
- /// hidden: deferral only ever subtracts.
- pub(crate) fn deferred(mut self) -> Self {
- self.force_deferred = true;
- self
- }
-
- pub(crate) fn with_early_exit(mut self, hook: EarlyExitHook) -> Self {
- self.early_exit = Some(hook);
- self
- }
-
- fn resolved_tool(&self) -> Option<&dyn Tool> {
- self.sets
- .iter()
- .flat_map(|set| set.iter())
- .find(|tool| tool.name() == self.name)
- .map(|tool| tool.as_ref())
- }
-}
-
-#[async_trait]
-impl Tool for CanonicalSharedToolAdapter {
- fn name(&self) -> &str {
- &self.name
- }
-
- fn description(&self) -> &str {
- &self.description
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- self.parameters_schema.clone()
- }
-
- fn policy(&self) -> tinytools::ToolPolicy {
- self.resolved_tool().map(Tool::policy).unwrap_or_default()
- }
-
- /// Forwarded so the harness indexes `Deferred` registrations for its
- /// `tool_search` bridge instead of advertising them. Without this every
- /// registered tool reported `Direct` and the bridge stayed inert.
- ///
- /// `Hidden` is **not** forwarded. The host is the exposure policy owner:
- /// the session builder already drops every `Hidden` registration from a
- /// wildcard belt, so a `Hidden` tool that reaches harness registration was
- /// named by hand in a `[tools] named` belt (`memory_recall` on the
- /// orchestrator, the `memory_*` readers on `flow_memory_agent`) or is a
- /// synthesised specialist route the belt admitted. Forwarding `Hidden`
- /// made the harness advertise 14 of the orchestrator's 25 visible tools
- /// while the prompt described all 25 (#6370): every `research` / `plan` /
- /// `memory_*` call the model was told about was unreachable.
- fn exposure(&self) -> tinytools::ToolExposure {
- match self.resolved_tool().map(Tool::exposure) {
- Some(tinytools::ToolExposure::Deferred) => tinytools::ToolExposure::Deferred,
- // Deferral only subtracts: a session-deferred `Hidden` tool stays
- // hidden rather than becoming searchable.
- Some(tinytools::ToolExposure::Hidden) if self.force_deferred => {
- tinytools::ToolExposure::Hidden
- }
- Some(tinytools::ToolExposure::Direct) if self.force_deferred => {
- tinytools::ToolExposure::Deferred
- }
- _ => tinytools::ToolExposure::Direct,
- }
- }
-
- fn family(&self) -> Option<&str> {
- self.resolved_tool().and_then(Tool::family)
- }
-
- /// Forwarded so each call gets the wrapped tool's own deadline; the trait
- /// default capped every tool, `shell` included, at the inherited 120s.
- fn timeout_policy(&self, arguments: &serde_json::Value) -> tinytools::ToolTimeout {
- self.resolved_tool()
- .map_or(tinytools::ToolTimeout::Inherit, |tool| {
- tool.timeout_policy(arguments)
- })
- }
-
- async fn prepare_authorization(
- &self,
- arguments: &serde_json::Value,
- ) -> anyhow::Result<Option<serde_json::Value>> {
- match self.resolved_tool() {
- Some(tool) => tool.prepare_authorization(arguments).await,
- None => Ok(None),
- }
- }
-
- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- self.execute_with_context(
- args,
- ToolCallOptions {
- prefer_markdown: true,
- },
- None,
- )
- .await
- }
-
- async fn execute_with_context(
- &self,
- args: serde_json::Value,
- options: ToolCallOptions,
- context: Option<&dyn ToolRunContext>,
- ) -> anyhow::Result<ToolResult> {
- let Some(tool) = self.resolved_tool() else {
- tracing::warn!(tool = %self.name, "[tinyagents] shared tool not found");
- return Ok(ToolResult::error(format!("unknown tool '{}'", self.name)));
- };
- // A callable tool's operational failure is input to the agent loop, not
- // a failure of the harness itself. Preserve it as an error result so
- // the model can recover (or explain the failure) on its next round.
- let origin = context
- .and_then(tinytools::ToolRunContext::host_extension)
- .and_then(|extension| {
- extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>()
- })
- .and_then(|context| {
- context.state::<crate::agent::tinyagents::host::run_context::HostOperationContext>()
- })
- .and_then(|context| context.origin.clone());
- let execution = tool.execute_with_context(args, options, context);
- let execution = match (origin, crate::core::runtime::CoreContext::current()) {
- (Some(origin), Some(core_context)) => {
- crate::core::runtime::CoreContext::scope_with_turn_origin(
- core_context,
- Some(origin),
- execution,
- )
- .await
- }
- _ => execution.await,
- };
- let result = match execution {
- Ok(result) => result,
- Err(error) => {
- tracing::warn!(tool = %self.name, %error, "[tinyagents] shared tool execution failed");
- ToolResult::error(format!("{} failed: {error}", self.name))
- }
- };
- if !result.is_error {
- if let Some(hook) = &self.early_exit {
- hook.trigger(&self.name, result.output_for_llm(true));
- }
- }
- Ok(result)
- }
-}
-
-#[cfg(test)]
-#[path = "tools_canonical_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs
deleted file mode 100644
index d714bd549a..0000000000
--- a/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs
+++ /dev/null
@@ -1,385 +0,0 @@
-use super::*;
-
-use std::sync::atomic::{AtomicBool, Ordering};
-
-use tinytools::{ToolContent, ToolPolicy};
-
-struct RecordingTool {
- saw_context: AtomicBool,
-}
-
-#[async_trait]
-impl Tool for RecordingTool {
- fn name(&self) -> &str {
- "recording"
- }
-
- fn description(&self) -> &str {
- "Preserves the canonical TinyTools contract."
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({"type": "object", "properties": {"fail": {"type": "boolean"}}})
- }
-
- fn policy(&self) -> ToolPolicy {
- ToolPolicy::read_only().requiring_approval()
- }
-
- /// Like `ShellTool`: unbounded unless the call passes `timeout_secs`.
- fn timeout_policy(&self, args: &serde_json::Value) -> tinytools::ToolTimeout {
- args["timeout_secs"]
- .as_u64()
- .map_or(tinytools::ToolTimeout::Unbounded, |secs| {
- tinytools::ToolTimeout::Millis(secs * 1000)
- })
- }
-
- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- self.execute_with_context(args, ToolCallOptions::default(), None)
- .await
- }
-
- async fn execute_with_context(
- &self,
- args: serde_json::Value,
- options: ToolCallOptions,
- context: Option<&dyn ToolRunContext>,
- ) -> anyhow::Result<ToolResult> {
- self.saw_context.store(
- context.is_some() && options.prefer_markdown,
- Ordering::SeqCst,
- );
- Ok(ToolResult {
- content: vec![
- ToolContent::Text {
- text: "plain content".to_string(),
- },
- ToolContent::Json {
- data: serde_json::json!({"preserved": true}),
- },
- ],
- is_error: args["fail"].as_bool().unwrap_or(false),
- markdown_formatted: Some("markdown content".to_string()),
- ..ToolResult::default()
- })
- }
-}
-
-struct TestToolRunContext;
-impl ToolRunContext for TestToolRunContext {}
-
-#[tokio::test]
-async fn canonical_adapter_preserves_spec_policy_context_and_result() {
- let seen_context = Arc::new(AtomicBool::new(false));
- struct SharedRecordingTool(Arc<AtomicBool>);
- #[async_trait]
- impl Tool for SharedRecordingTool {
- fn name(&self) -> &str {
- "recording"
- }
- fn description(&self) -> &str {
- "Preserves the canonical TinyTools contract."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({"type": "object"})
- }
- fn policy(&self) -> ToolPolicy {
- ToolPolicy::read_only().requiring_approval()
- }
- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- self.execute_with_context(args, ToolCallOptions::default(), None)
- .await
- }
- async fn execute_with_context(
- &self,
- args: serde_json::Value,
- options: ToolCallOptions,
- context: Option<&dyn ToolRunContext>,
- ) -> anyhow::Result<ToolResult> {
- self.0.store(
- context.is_some() && options.prefer_markdown,
- Ordering::SeqCst,
- );
- Ok(ToolResult {
- content: vec![
- ToolContent::Text {
- text: "plain content".into(),
- },
- ToolContent::Json {
- data: serde_json::json!({"preserved": true}),
- },
- ],
- is_error: args["fail"].as_bool().unwrap_or(false),
- markdown_formatted: Some("markdown content".into()),
- ..ToolResult::default()
- })
- }
- }
- let sets: Vec<Arc<Vec<Box<dyn Tool>>>> = vec![Arc::new(vec![Box::new(SharedRecordingTool(
- seen_context.clone(),
- ))])];
- let adapter = CanonicalSharedToolAdapter::for_name(sets, "recording").expect("registered tool");
-
- assert_eq!(adapter.name(), "recording");
- assert_eq!(
- adapter.description(),
- "Preserves the canonical TinyTools contract."
- );
- assert_eq!(
- adapter.parameters_schema(),
- serde_json::json!({"type": "object"})
- );
- assert_eq!(
- adapter.policy(),
- ToolPolicy::read_only().requiring_approval()
- );
-
- let result = adapter
- .execute_with_context(
- serde_json::json!({"fail": true}),
- ToolCallOptions::prefer_markdown(),
- Some(&TestToolRunContext),
- )
- .await
- .expect("canonical result");
- assert!(seen_context.load(Ordering::SeqCst));
- assert!(result.is_error);
- assert_eq!(
- result.markdown_formatted.as_deref(),
- Some("markdown content")
- );
- assert_eq!(result.content.len(), 2);
- assert!(matches!(result.content[0], ToolContent::Text { ref text } if text == "plain content"));
- assert!(
- matches!(result.content[1], ToolContent::Json { ref data } if data == &serde_json::json!({"preserved": true}))
- );
-}
-
-struct OriginObservingTool(Arc<AtomicBool>);
-
-#[async_trait]
-impl Tool for OriginObservingTool {
- fn name(&self) -> &str {
- "origin_observer"
- }
- fn description(&self) -> &str {
- "Observes the per-turn core authority."
- }
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({"type":"object"})
- }
- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
- Ok(ToolResult::success("executed"))
- }
- async fn execute_with_context(
- &self,
- _args: serde_json::Value,
- _options: ToolCallOptions,
- _context: Option<&dyn ToolRunContext>,
- ) -> anyhow::Result<ToolResult> {
- self.0.store(
- matches!(
- crate::core::runtime::CoreContext::current_turn_origin(),
- Some(crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel { .. })
- ),
- Ordering::SeqCst,
- );
- Ok(ToolResult::success("executed"))
- }
-}
-
-#[tokio::test]
-async fn canonical_adapter_scopes_tool_execution_to_the_run_origin() {
- use tinyagents_harness::context::RunConfig;
-
- let context =
- crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
- let observed = Arc::new(AtomicBool::new(false));
- let tools: Vec<Arc<Vec<Box<dyn Tool>>>> = vec![Arc::new(vec![Box::new(OriginObservingTool(
- observed.clone(),
- ))])];
- let adapter = CanonicalSharedToolAdapter::for_name(tools, "origin_observer").unwrap();
- let mut host = crate::agent::tinyagents::host::OpenHumanRunContext::new();
- host.origin = Some(
- crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel {
- sender_name: None,
- channel: "test".into(),
- sender: None,
- reply_target: "room".into(),
- message_id: "message".into(),
- history_key: None,
- },
- );
- let run = host.into_tinyagents(RunConfig::new("origin-observer"));
- let tool_context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(
- &run,
- tinyagents_harness::ids::CallId::new("call"),
- );
-
- crate::core::runtime::CoreContext::scope(context, async {
- adapter
- .execute_with_context(
- serde_json::json!({}),
- ToolCallOptions::default(),
- Some(&tool_context),
- )
- .await
- .expect("tool execution succeeds");
- assert!(observed.load(Ordering::SeqCst));
- assert!(crate::core::runtime::CoreContext::current_turn_origin().is_none());
- })
- .await;
-}
-
-#[tokio::test]
-async fn canonical_adapter_fails_closed_when_the_registered_tool_is_gone() {
- let adapter = CanonicalSharedToolAdapter {
- sets: Vec::new(),
- name: "missing".to_string(),
- description: "missing".to_string(),
- parameters_schema: serde_json::json!({"type": "object"}),
- early_exit: None,
- force_deferred: false,
- };
-
- let result = adapter
- .execute(serde_json::json!({}))
- .await
- .expect("reported failure");
- assert!(result.is_error);
- assert_eq!(result.output(), "unknown tool 'missing'");
- assert_eq!(
- adapter.timeout_policy(&serde_json::json!({"timeout_secs": 300})),
- tinytools::ToolTimeout::Inherit
- );
-}
-
-#[tokio::test]
-async fn early_exit_only_fires_after_a_successful_canonical_result() {
- let sets: Vec<Arc<Vec<Box<dyn Tool>>>> = vec![Arc::new(vec![Box::new(RecordingTool {
- saw_context: AtomicBool::new(false),
- })])];
- let hook = EarlyExitHook::new(SteeringHandle::allow_all());
- let adapter = CanonicalSharedToolAdapter::for_name(sets, "recording")
- .expect("registered tool")
- .with_early_exit(hook.clone());
-
- let failed = adapter
- .execute(serde_json::json!({"fail": true}))
- .await
- .expect("reported failure");
- assert!(failed.is_error);
- assert!(
- hook.take().is_none(),
- "reported tool errors must not pause the run"
- );
-
- let successful = adapter
- .execute(serde_json::json!({"fail": false}))
- .await
- .expect("success");
- assert!(!successful.is_error);
- let early_exit = hook
- .take()
- .expect("successful early-exit tool pauses the run");
- assert_eq!(early_exit.tool, "recording");
- assert_eq!(early_exit.question, "markdown content");
-}
-
-struct ExposedTool(&'static str, tinytools::ToolExposure);
-
-#[async_trait]
-impl Tool for ExposedTool {
- fn name(&self) -> &str {
- self.0
- }
-
- fn description(&self) -> &str {
- "exposure probe"
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({"type": "object"})
- }
-
- fn exposure(&self) -> tinytools::ToolExposure {
- self.1
- }
-
- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
- Ok(ToolResult::default())
- }
-}
-
-/// The host decides what a belt advertises; the harness only needs to know
-/// which admitted registrations are searchable rather than advertised. A
-/// `Hidden` tool that reached registration was named by the belt, so it is
-/// advertised; `Deferred` stays deferred (#6370).
-#[test]
-fn adapter_advertises_admitted_hidden_tools_and_keeps_deferred_ones_deferred() {
- let set: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![
- Box::new(ExposedTool("direct", tinytools::ToolExposure::Direct)),
- Box::new(ExposedTool("hidden", tinytools::ToolExposure::Hidden)),
- Box::new(ExposedTool("deferred", tinytools::ToolExposure::Deferred)),
- ]);
- let exposure = |name: &str| {
- CanonicalSharedToolAdapter::for_name(vec![set.clone()], name)
- .expect("registered")
- .exposure()
- };
- assert_eq!(exposure("direct"), tinytools::ToolExposure::Direct);
- assert_eq!(exposure("hidden"), tinytools::ToolExposure::Direct);
- assert_eq!(exposure("deferred"), tinytools::ToolExposure::Deferred);
-}
-
-/// A tool the session defers for its own agent (`deferred_tools` →
-/// `OpenHumanRunContext::deferred_tool_names`) registers as `Deferred`, so the
-/// harness keeps it off the wire and indexes it for `tool_search`. Deferral only
-/// subtracts: a forced `Hidden` tool stays `Hidden` instead of becoming
-/// searchable, and an already-`Deferred` tool is unchanged.
-#[test]
-fn session_deferred_adapter_reports_deferred_but_never_surfaces_a_hidden_tool() {
- let set: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![
- Box::new(ExposedTool("direct", tinytools::ToolExposure::Direct)),
- Box::new(ExposedTool("hidden", tinytools::ToolExposure::Hidden)),
- Box::new(ExposedTool("deferred", tinytools::ToolExposure::Deferred)),
- ]);
- let forced = |name: &str| {
- CanonicalSharedToolAdapter::for_name(vec![set.clone()], name)
- .expect("registered")
- .deferred()
- .exposure()
- };
- assert_eq!(forced("direct"), tinytools::ToolExposure::Deferred);
- assert_eq!(forced("hidden"), tinytools::ToolExposure::Hidden);
- assert_eq!(forced("deferred"), tinytools::ToolExposure::Deferred);
-}
-
-/// The harness bounds a call by the *registered* tool's `timeout_policy`, and
-/// every OpenHuman tool is registered through this adapter (#7712).
-#[test]
-fn adapter_forwards_the_wrapped_tools_timeout_policy() {
- use tinytools::ToolTimeout::{Inherit, Millis, Unbounded};
- let set: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![
- Box::new(RecordingTool {
- saw_context: AtomicBool::new(false),
- }),
- Box::new(ExposedTool("plain", tinytools::ToolExposure::Direct)),
- ]);
- let policy = |name: &str, args: serde_json::Value| {
- CanonicalSharedToolAdapter::for_name(vec![set.clone()], name)
- .expect("registered")
- .timeout_policy(&args)
- };
- assert_eq!(policy("recording", serde_json::json!({})), Unbounded);
- assert_eq!(
- policy("recording", serde_json::json!({"timeout_secs": 300})),
- Millis(300_000)
- );
- // A tool without its own policy still inherits the configured timeout.
- assert_eq!(
- policy("plain", serde_json::json!({"timeout_secs": 300})),
- Inherit
- );
-}