Skip to content

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

fix(agent): correlate TinyAgents middleware by call identity

Steven Enamakela1c615784a66
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 6bb61ef26e..59b75a0eaa 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -3,9 +3,9 @@
//! `tinyagents_harness::context::RunContext` owns generic runtime mechanics.
//! This type owns the product values that used to be recovered from ambient
//! task-locals: approval origin, host progress, attachment and artifact scope,
-//! parent dispatch state, and the handles a tool needs to continue a run. A
-//! caller passes it through every turn and child invocation, then converts it
-//! into the canonical TinyAgents context with [`Self::into_tinyagents`].
+//! parent dispatch state, and the handles a tool needs to continue a run.
+//! Phase B1 defines and tests this canonical conversion; it is not yet the live
+//! turn carrier. The task-local and public-route cutovers remain later work.
use std::sync::{Arc, Mutex};
use std::time::Duration;
@@ -23,7 +23,8 @@ use crate::agent::tinyagents::resolved_route::RouteSlot;
use crate::agent::tinyagents::turn_outcome::ToolOutcomeSink;
use crate::agent::turn_origin::AgentTurnOrigin;
-/// Explicit OpenHuman data carried by a single top-level or child agent run.
+/// Explicit OpenHuman data carried by a prospective top-level or child agent
+/// run once the Phase B task-local cutover wires it into live invocation.
///
/// Shared members (`Arc`s, cancellation and workspace descriptor) retain the
/// identity required by a recursive run tree. [`Self::child`] deliberately
@@ -118,9 +119,10 @@ impl OpenHumanRunContext {
/// Builds the explicit child state for a recursive invocation.
///
- /// Cancellation, workspace, progress, policy hooks and dispatch state are
- /// inherited. Route observation and usage accounting are isolated, so a
- /// completed child cannot mutate facts subsequently persisted for its
+ /// This inheritance rule is tested in B1 and is ready for the later live
+ /// plumbing. Cancellation, workspace, progress, policy hooks and dispatch
+ /// state are inherited. Route observation and usage accounting are isolated,
+ /// so a completed child cannot mutate facts subsequently persisted for its
/// parent.
pub fn child(&self) -> Self {
let mut child = self.clone();
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
index fa4c7485a6..1129fa01b5 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
@@ -42,12 +42,11 @@
//! is the point: the middleware and this classifier must not disagree about
//! whether a call timed out.
//!
-//! **3. Error text lives in two places.** The middleware combines
-//! [`ToolResult::error`] and [`ToolResult::content`] before classifying (#4459),
-//! because the policy markers and timeout phrases are emitted by the tool layer
-//! into whichever of the two it had to hand. This adapter uses the same
-//! combination, so a `[policy-denied]` marker is honoured wherever it landed and
-//! a user refusal can never be re-dispatched.
+//! **3. Error text is canonical content.** [`ToolResult::content`] carries text
+//! and structured blocks while [`ToolResult::is_error`] says whether execution
+//! reported a failure. This adapter renders the canonical blocks, so a
+//! `[policy-denied]` marker is honoured wherever the tool put it and a user
+//! refusal can never be re-dispatched.
//!
//! **4. A timeout cannot be assumed safe to repeat.** `Timeout` is the one
//! failure class where "the call failed" and "the call succeeded but the reply
@@ -188,8 +187,8 @@ impl OpenHumanToolOutcomeClassifier {
/// Renders canonical content into the text the heuristic reads.
///
/// Mirrors `TinyAgentsToolStatusMiddleware::after_tool` exactly (#4459): the
- /// classifier historically read `error` while the marker/timeout sniffs read
- /// `content`, and the two disagreeing is the bug that combination fixed.
+ /// classifier historically read distinct legacy error/content fields, and
+ /// the two disagreeing was the bug that canonical content fixed.
/// Borrows wherever possible so the common single-source case allocates
/// nothing on the hot path.
fn failure_text(result: &ToolResult) -> Cow<'static, str> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
index c43afe112e..d0f6812055 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
@@ -2,13 +2,9 @@ use super::*;
use crate::security::{POLICY_BLOCKED_MARKER, POLICY_DENIED_MARKER};
fn result(error: Option<&str>, content: &str) -> ToolResult {
- ToolResult {
- call_id: "call-1".to_string(),
- name: "shell".to_string(),
- content: content.to_string(),
- raw: None,
- error: error.map(str::to_string),
- elapsed_ms: 5,
+ match error {
+ Some(message) => ToolResult::error(if content.is_empty() { message } else { content }),
+ None => ToolResult::success(content),
}
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
index 10762cdc37..ec1c56ecdb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
@@ -5,7 +5,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinyinference_llm::tool::ToolCall as TaToolCall;
use tinytools::ToolResult as TaToolResult;
@@ -103,7 +103,7 @@ impl Middleware<()> for EmbedderToolHooksMiddleware {
self.arguments_by_call_id
.lock()
.expect("embedder tool-hook arguments poisoned")
- .insert(call.name.clone(), call.arguments.clone());
+ .insert(call.id.clone(), call.arguments.clone());
Ok(())
}
@@ -111,20 +111,20 @@ impl Middleware<()> for EmbedderToolHooksMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let call_id = invocation.call_id().to_string();
+ let tool_name = invocation.tool_name();
let arguments = self
.arguments_by_call_id
.lock()
.expect("embedder tool-hook arguments poisoned")
- .remove(tool_name)
+ .remove(&call_id)
.unwrap_or(serde_json::Value::Null);
let context = crate::agent::hooks::ToolHookContext {
event: crate::agent::hooks::ToolHookEvent::PostToolUse,
- // The canonical post-tool hook supplies the canonical tool name;
- // call ids are intentionally not duplicated in ToolResult.
- call_id: tool_name.to_string(),
+ call_id,
tool_name: tool_name.to_string(),
arguments,
success: Some(!result.is_error),
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs
index 102c2d409c..2fabed4913 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs
@@ -5,7 +5,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::{AgentRun, Middleware};
+use tinyagents_harness::middleware::{AgentRun, Middleware, ToolInvocationIdentity};
use tinyinference_llm::tool::ToolCall as TaToolCall;
use tinytools::ToolResult as TaToolResult;
@@ -28,7 +28,7 @@ pub struct MemoryProtocolMiddleware {
/// call_id → classified op, captured in `before_tool` (the tool result carries
/// no arguments, yet `update_memory_md` and `memory_tree` can only be
/// classified from their `file` / `mode` argument). Correlated back by
- /// `result.call_id` in `after_tool`.
+ /// the invocation identity in `after_tool`.
pending_ops: std::sync::Mutex<
std::collections::HashMap<String, crate::agent::harness::memory_protocol::MemoryOp>,
>,
@@ -70,7 +70,7 @@ impl Middleware<()> for MemoryProtocolMiddleware {
crate::agent::harness::memory_protocol::classify_memory_op(&call.name, &call.arguments);
if op != crate::agent::harness::memory_protocol::MemoryOp::Other {
if let Ok(mut ops) = self.pending_ops.lock() {
- ops.insert(call.name.clone(), op);
+ ops.insert(call.id.clone(), op);
}
}
Ok(())
@@ -80,16 +80,17 @@ impl Middleware<()> for MemoryProtocolMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
// Consume the op captured for this call (removing it so the map can't
// grow unbounded). Absent → a non-memory tool: nothing to enforce.
let op = self
.pending_ops
.lock()
.ok()
- .and_then(|mut ops| ops.remove(tool_name));
+ .and_then(|mut ops| ops.remove(&invocation.call_id().to_string()));
let Some(op) = op else {
return Ok(());
};
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
index 83b80bbe12..ae2566cf37 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
@@ -10,7 +10,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinyagents_harness::no_progress::{
fingerprint_arguments, SuccessfulRepeat, SuccessfulRepeatTracker,
};
@@ -218,15 +218,14 @@ impl Middleware<()> for RepeatProgressMiddleware {
assistant_visible_text(&response.message).trim(),
call_sig
);
- // Per-tool signatures for the recurrence ledger. The canonical
- // post-tool hook supplies the resolved tool name rather than copying
- // transport call ids into `ToolResult`.
+ // Per-call signatures for the recurrence ledger. The invocation
+ // identity joins each post-tool result to the provider call id.
let call_sigs = tool_calls
.iter()
.filter(|call| !is_repeat_call_exempt(&call.name))
.map(|call| {
(
- call.name.clone(),
+ call.id.clone(),
format!(
"{}\u{1}{}",
call.name,
@@ -259,9 +258,11 @@ impl Middleware<()> for RepeatProgressMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
+ let call_id = invocation.call_id().to_string();
// Fold this result into the pending batch; the call guard only acts once
// the batch is complete so it sees whole-batch success.
let (already_halted, recurrence, completed) = {
@@ -275,13 +276,13 @@ impl Middleware<()> for RepeatProgressMiddleware {
let mut recurrence = SuccessfulRepeat::Continue;
if result.is_error {
batch.all_ok = false;
- } else if let Some(sig) = batch.call_sigs.get(tool_name) {
+ } else if let Some(sig) = batch.call_sigs.get(&call_id) {
recurrence = self.state.tracker.record_call_outcome(
sig,
&crate::agent::tinyagents::middleware::tool_result_text(result),
);
if let Ok(mut recorded) = self.state.recorded.lock() {
- recorded.insert(tool_name.to_string());
+ recorded.insert(call_id);
}
}
if matches!(recurrence, SuccessfulRepeat::Halt(_)) {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
index f2f763fa25..b242d40c4a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -8,7 +8,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinyagents_harness::no_progress::{NoProgress, NoProgressTracker, ToolAttempt};
use tinyagents_harness::steering::{SteeringCommand, SteeringHandle};
use tinyinference_llm::message::Message as TaMessage;
@@ -235,7 +235,7 @@ impl Middleware<()> for RepeatedToolFailureMiddleware {
// The tool result carries no arguments, so capture a fingerprint here and
// correlate it by call_id in `after_tool`.
if let Ok(mut sigs) = self.arg_sigs.lock() {
- sigs.insert(call.name.clone(), args_fingerprint(&call.arguments));
+ sigs.insert(call.id.clone(), args_fingerprint(&call.arguments));
}
Ok(())
}
@@ -244,15 +244,16 @@ impl Middleware<()> for RepeatedToolFailureMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
let content = crate::agent::tinyagents::middleware::tool_result_text(result);
let arg_fp = self
.arg_sigs
.lock()
.ok()
- .and_then(|mut sigs| sigs.remove(tool_name))
+ .and_then(|mut sigs| sigs.remove(&invocation.call_id().to_string()))
.unwrap_or_default();
let step = self.step.fetch_add(1, Ordering::SeqCst) + 1;
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_outcome_capture.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_outcome_capture.rs
index 9bfd0d9b53..4cf4f40bb6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_outcome_capture.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_outcome_capture.rs
@@ -6,7 +6,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinytools::ToolResult as TaToolResult;
/// `after_tool`: capture each tool call's execution outcome (success + content)
@@ -47,9 +47,11 @@ impl Middleware<()> for ToolOutcomeCaptureMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
+ let call_id = invocation.call_id().to_string();
// Enrich a raw security-policy / autonomy block (issue #4094): the ~20
// `[policy-blocked]` denials emitted deep in `SecurityPolicy` / the tools
// return a bare marker line with no workaround and no relay directive, so
@@ -93,7 +95,7 @@ impl Middleware<()> for ToolOutcomeCaptureMiddleware {
// for old/deserialized completion events; TinyAgents 1.6 supplies
// these fields directly on live `ToolCompleted` events.
map.insert(
- tool_name.to_string(),
+ call_id.clone(),
(
success,
failure,
@@ -106,7 +108,7 @@ impl Middleware<()> for ToolOutcomeCaptureMiddleware {
}
if let Ok(mut sink) = self.sink.lock() {
sink.push(crate::agent::tinyagents::ToolCallOutcome {
- call_id: tool_name.to_string(),
+ call_id,
name: tool_name.to_string(),
success,
content: crate::agent::tinyagents::middleware::tool_result_text(result),
@@ -115,3 +117,49 @@ impl Middleware<()> for ToolOutcomeCaptureMiddleware {
Ok(())
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use tinyagents_harness::context::{RunConfig, RunContext};
+
+ fn context() -> RunContext<()> {
+ RunContext::new(RunConfig::new("outcome-capture-test"), ())
+ }
+
+ #[tokio::test]
+ async fn same_tool_calls_keep_completion_and_failure_records_by_call_id() {
+ let sink = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
+ let failure_map = std::sync::Arc::new(std::sync::Mutex::new(Default::default()));
+ let middleware = ToolOutcomeCaptureMiddleware::new(sink.clone(), failure_map.clone());
+ let mut ctx = context();
+
+ let success = ToolInvocationIdentity::new("echo-success", "echo");
+ let mut success_result = TaToolResult::success("done");
+ middleware
+ .after_tool(&mut ctx, &(), &success, &mut success_result)
+ .await
+ .expect("successful result is captured");
+
+ let failure = ToolInvocationIdentity::new("echo-failure", "echo");
+ let mut failure_result = TaToolResult::error("request timed out");
+ middleware
+ .after_tool(&mut ctx, &(), &failure, &mut failure_result)
+ .await
+ .expect("failed result is captured");
+
+ let outcomes = sink.lock().expect("outcome sink");
+ assert_eq!(outcomes.len(), 2);
+ assert_eq!(outcomes[0].call_id, "echo-success");
+ assert!(outcomes[0].success);
+ assert_eq!(outcomes[1].call_id, "echo-failure");
+ assert!(!outcomes[1].success);
+ drop(outcomes);
+
+ let recorded = failure_map.lock().expect("failure lookup");
+ assert_eq!(recorded.len(), 2, "same tool names cannot overwrite calls");
+ assert_eq!(recorded["echo-success"].0, true);
+ assert_eq!(recorded["echo-failure"].0, false);
+ assert!(recorded["echo-failure"].1.is_some());
+ }
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs
index 34f8147662..238d528305 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs
@@ -10,7 +10,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
use tinyagents_harness::events::AgentEvent;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinyinference_llm::tool::ToolCall as TaToolCall;
use tinytools::{ToolPolicy as TaToolPolicy, ToolResult as TaToolResult};
@@ -145,7 +145,7 @@ impl Middleware<()> for ToolOutputMiddleware {
"[tinyagents::mw] call reads a persisted tool-result artifact"
);
if let Ok(mut reads) = self.artifact_reads.lock() {
- reads.insert(call.name.clone(), read);
+ reads.insert(call.id.clone(), read);
}
}
Ok(())
@@ -155,9 +155,11 @@ impl Middleware<()> for ToolOutputMiddleware {
&self,
ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
+ let call_id = invocation.call_id().to_string();
let mut content = crate::agent::tinyagents::middleware::tool_result_text(result);
// A read of a persisted artifact is the model following the envelope's
// `read_with` instruction. Every stage below would defeat it: the
@@ -169,7 +171,7 @@ impl Middleware<()> for ToolOutputMiddleware {
.artifact_reads
.lock()
.ok()
- .and_then(|mut reads| reads.remove(tool_name));
+ .and_then(|mut reads| reads.remove(&call_id));
if let Some(read) = artifact_read {
tracing::info!(
tool = tool_name,
@@ -365,7 +367,7 @@ impl Middleware<()> for ToolOutputMiddleware {
full_output,
self.artifact_store.as_ref(),
tool_name,
- Some(tool_name),
+ Some(&call_id),
self.budget_bytes,
)
.await;
@@ -378,10 +380,10 @@ impl Middleware<()> for ToolOutputMiddleware {
);
if let Some(path) = outcome.artifact_path.as_deref() {
if let Some(store) = ctx.stores.get(TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE) {
- let key = tool_name.to_string();
+ let key = call_id.clone();
let mut fields = serde_json::Map::new();
fields.insert("tool".to_string(), tool_name.into());
- fields.insert("call_id".to_string(), tool_name.into());
+ fields.insert("call_id".to_string(), call_id.clone().into());
fields.insert("artifact_path".to_string(), path.to_string().into());
fields.insert(
"original_bytes".to_string(),
@@ -396,12 +398,14 @@ impl Middleware<()> for ToolOutputMiddleware {
if let Err(err) = index_result {
tracing::warn!(
tool = tool_name,
+ call_id = %call_id,
error = %err,
"[tinyagents::mw] failed to index tool_result_artifact"
);
} else {
tracing::debug!(
tool = tool_name,
+ call_id = %call_id,
artifact_path = %path,
"[tinyagents::mw] indexed tool_result_artifact in run store"
);
@@ -437,3 +441,59 @@ impl Middleware<()> for ToolOutputMiddleware {
Ok(())
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use tinyagents_harness::context::{RunConfig, RunContext};
+
+ fn context() -> RunContext<()> {
+ RunContext::new(RunConfig::new("tool-output-identity-test"), ())
+ }
+
+ #[tokio::test]
+ async fn same_tool_calls_persist_artifacts_under_distinct_call_ids() {
+ let temp = tempfile::tempdir().expect("temporary artifact root");
+ let middleware = ToolOutputMiddleware {
+ budget_bytes: 8,
+ payload_summarizer: None,
+ task_hint: None,
+ artifact_store: Some(ToolResultArtifactStore::new(
+ temp.path().to_path_buf(),
+ "identity-session",
+ )),
+ tokenjuice_compaction_enabled: false,
+ tokenjuice_compression: AgentTokenjuiceCompression::Off,
+ runtime_config: None,
+ tool_policies: HashMap::new(),
+ artifact_reads: Default::default(),
+ };
+ let mut ctx = context();
+
+ let first = ToolInvocationIdentity::new("echo-1", "echo");
+ let mut first_result = TaToolResult::success("first result is deliberately oversized");
+ middleware
+ .after_tool(&mut ctx, &(), &first, &mut first_result)
+ .await
+ .expect("first artifact is persisted");
+
+ let second = ToolInvocationIdentity::new("echo-2", "echo");
+ let mut second_result = TaToolResult::success("second result is deliberately oversized");
+ middleware
+ .after_tool(&mut ctx, &(), &second, &mut second_result)
+ .await
+ .expect("second artifact is persisted");
+
+ let root = temp
+ .path()
+ .join("artifacts/tool-results/identity-session/echo");
+ assert_eq!(
+ std::fs::read_to_string(root.join("echo-1.txt")).expect("first artifact"),
+ "first result is deliberately oversized"
+ );
+ assert_eq!(
+ std::fs::read_to_string(root.join("echo-2.txt")).expect("second artifact"),
+ "second result is deliberately oversized"
+ );
+ }
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
index 239c42e176..bdf3de78eb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -9,7 +9,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::RunContext;
use tinyagents_harness::error::Result as TaResult;
-use tinyagents_harness::middleware::Middleware;
+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
use tinyagents_harness::runtime::AgentHarness;
use tinyinference_llm::message::Message;
use tinyinference_llm::model::{ModelRequest, ModelResponse};
@@ -172,14 +172,14 @@ impl Middleware<()> for TranscriptSnapshotMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
// A tool result reaches a provider only with the next request, so it
// also sits past `accepted_len` until that request is answered.
if let Ok(mut guard) = self.sink.lock() {
guard.messages.push(Message::tool(
- tool_name,
+ invocation.call_id().to_string(),
crate::agent::tinyagents::middleware::tool_result_text(result),
));
}
@@ -380,7 +380,7 @@ impl Middleware<()> for HandoffMiddleware {
.is_some()
{
if let Ok(mut reads) = self.artifact_reads.lock() {
- reads.insert(call.name.clone());
+ reads.insert(call.id.clone());
}
}
Ok(())
@@ -390,17 +390,20 @@ impl Middleware<()> for HandoffMiddleware {
&self,
_ctx: &mut RunContext<()>,
_state: &(),
- tool_name: &str,
+ invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
) -> TaResult<()> {
+ let tool_name = invocation.tool_name();
+ let call_id = invocation.call_id().to_string();
let artifact_read = self
.artifact_reads
.lock()
- .map(|mut reads| reads.remove(tool_name))
+ .map(|mut reads| reads.remove(&call_id))
.unwrap_or(false);
if artifact_read {
tracing::debug!(
tool = tool_name,
+ call_id = %call_id,
task_id = %self.task_id,
"[tinyagents::mw] artifact read: skipping result handoff so the artifact pager sees the bytes"
);
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
index 2aa5358a23..89b783f668 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
@@ -14,7 +14,7 @@ use std::sync::Arc;
use async_trait::async_trait;
-use tinyagents_harness::middleware::{AgentRun, BudgetTracker, Middleware};
+use tinyagents_harness::middleware::{AgentRun, BudgetTracker, Middleware, ToolInvocationIdentity};
use tinyagents_harness::steering::{SteeringCommand, SteeringHandle};
use tinyinference_llm::message::{ContentBlock, Message as TaMessage};
use tinyinference_llm::model::{ModelResponse, SegmentRole};
@@ -117,15 +117,8 @@ impl Tool for FakeTool {
}
}
-fn tool_result(name: &str, content: &str) -> TaToolResult {
- TaToolResult {
- call_id: "c1".into(),
- name: name.into(),
- content: content.into(),
- raw: None,
- error: None,
- elapsed_ms: 0,
- }
+fn tool_result(_name: &str, content: &str) -> TaToolResult {
+ TaToolResult::success(content)
}
// ── ToolOutcomeCaptureMiddleware policy-block enrichment (issue #4094) ───
@@ -253,9 +246,8 @@ fn large_sample_response_json(row_count: usize) -> String {
// ── RepeatedToolFailureMiddleware ───────────────────────────────────────
fn failing_result(name: &str, err: &str) -> TaToolResult {
- let mut r = tool_result(name, err);
- r.error = Some(err.to_string());
- r
+ let _ = name;
+ TaToolResult::error(err)
}
/// Count how many of the steering commands drained from `handle` are
@@ -327,11 +319,14 @@ async fn run_successful_repeat_cycle(
mw.after_model(&mut ctx(), &(), &mut response)
.await
.unwrap();
- let mut result = tool_result(tool, output);
- // Answer the call `repeated_success_response` issued.
- result.call_id = "repeat-1".into();
- result.error = error.map(str::to_string);
- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();
+ let mut result = match error {
+ Some(error) => TaToolResult::error(error),
+ None => tool_result(tool, output),
+ };
+ let invocation = ToolInvocationIdentity::new("repeat-1", tool);
+ mw.after_tool(&mut ctx(), &(), &invocation, &mut result)
+ .await
+ .unwrap();
}
// ── MemoryProtocolMiddleware (issue #4116) ──────────────────────────────
@@ -355,9 +350,14 @@ async fn run_cycle(
invalid: None,
};
mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
- let mut result = tool_result(name, content); // call_id "c1" matches
- result.error = error.map(|e| e.to_string());
- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();
+ let mut result = match error {
+ Some(error) => TaToolResult::error(error),
+ None => tool_result(name, content),
+ };
+ let invocation = ToolInvocationIdentity::new("c1", name);
+ mw.after_tool(&mut ctx(), &(), &invocation, &mut result)
+ .await
+ .unwrap();
result
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_tests.rs
index bf21497051..d40d540d82 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_tests.rs
@@ -4,6 +4,7 @@ use crate::agent::tinyagents::middleware::tool_output::ToolOutputMiddleware;
// fully-qualified), so the module itself no longer references the type.
use super::*;
use tinyagents_harness::middleware::MicrocompactMiddleware;
+use tinytools::{ToolRuntime, ToolTimeout};
// #4462: image-aware token estimation. A base64 image marker must be priced
// at the flat IMAGE_MARKER_TOKEN_COST, not chars/4 of its payload — otherwise
@@ -352,9 +353,9 @@ fn tool_char_cap_reads_the_tools_own_declared_cap() {
let mut tool_policies = HashMap::new();
tool_policies.insert(
"big".to_string(),
- TaToolPolicy::classified().with_runtime(tinyagents_harness::tool::ToolRuntime {
+ TaToolPolicy::classified().with_runtime(ToolRuntime {
timeout_ms: None,
- timeout: tinyagents_harness::tool::ToolTimeout::Inherit,
+ timeout: ToolTimeout::Inherit,
max_retries: None,
idempotent: false,
cancelable: true,
@@ -391,9 +392,9 @@ async fn an_unavailable_notice_survives_a_tool_cap_shorter_than_itself() {
let mut tool_policies = HashMap::new();
tool_policies.insert(
"terse".to_string(),
- TaToolPolicy::classified().with_runtime(tinyagents_harness::tool::ToolRuntime {
+ TaToolPolicy::classified().with_runtime(ToolRuntime {
timeout_ms: None,
- timeout: tinyagents_harness::tool::ToolTimeout::Inherit,
+ timeout: ToolTimeout::Inherit,
max_retries: None,
idempotent: false,
cancelable: true,
@@ -452,9 +453,9 @@ async fn tool_output_honors_a_tools_own_cap() {
let mut tool_policies = HashMap::new();
tool_policies.insert(
"capped".to_string(),
- TaToolPolicy::classified().with_runtime(tinyagents_harness::tool::ToolRuntime {
+ TaToolPolicy::classified().with_runtime(ToolRuntime {
timeout_ms: None,
- timeout: tinyagents_harness::tool::ToolTimeout::Inherit,
+ timeout: ToolTimeout::Inherit,
max_retries: None,
idempotent: false,
cancelable: true,
@@ -691,9 +692,9 @@ async fn the_summarized_size_survives_a_tool_cap_shorter_than_the_summary() {
let mut tool_policies = HashMap::new();
tool_policies.insert(
"terse".to_string(),
- TaToolPolicy::classified().with_runtime(tinyagents_harness::tool::ToolRuntime {
+ TaToolPolicy::classified().with_runtime(ToolRuntime {
timeout_ms: None,
- timeout: tinyagents_harness::tool::ToolTimeout::Inherit,
+ timeout: ToolTimeout::Inherit,
max_retries: None,
idempotent: false,
cancelable: true,
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/cap_pauser_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability/cap_pauser_tests.rs
index a48e99e532..81d38592d2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability/cap_pauser_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/cap_pauser_tests.rs
@@ -6,7 +6,7 @@ use async_trait::async_trait;
use tinyagents_harness::context::{RunConfig, RunContext};
use tinyagents_harness::error::Result as TaResult;
use tinyagents_harness::events::EventSink;
-use tinyagents_harness::middleware::{AgentRun, Middleware};
+use tinyagents_harness::middleware::{AgentRun, Middleware, ToolInvocationIdentity};
use tinyagents_harness::runtime::{AgentHarness, RunPolicy};
use tinyagents_harness::steering::SteeringPolicy;
use tinyagents_harness::subagent::SubAgent;
@@ -90,6 +90,7 @@ impl Middleware<()> for NestedRunAfterEveryTool {
&self,
ctx: &mut RunContext<()>,
_state: &(),
+ _invocation: &ToolInvocationIdentity,
_result: &mut ToolResult,
) -> TaResult<()> {
let model: Arc<dyn ChatModel<()>> = Arc::new(ScriptedModel::replies(vec!["summary"]));
@@ -115,6 +116,7 @@ impl Middleware<()> for OverlappingNestedRunsAfterEveryTool {
&self,
ctx: &mut RunContext<()>,
_state: &(),
+ _invocation: &ToolInvocationIdentity,
_result: &mut ToolResult,
) -> TaResult<()> {
let depth = ctx.depth();
diff --git a/scripts/ci/agent-runtime-boundary-baseline.json b/scripts/ci/agent-runtime-boundary-baseline.json
index 585d6e8a69..a4c501dbb3 100644
--- a/scripts/ci/agent-runtime-boundary-baseline.json
+++ b/scripts/ci/agent-runtime-boundary-baseline.json
@@ -2480,7 +2480,7 @@
{
"rule": "tinyagents-tool-calling-facade",
"path": "vendor/tinyagents/crates/tinyagents-harness/src/agent_loop/run_loop.rs",
- "line": 938,
+ "line": 976,
"text": "use tinytools_agent::dialect::{DialectResponse, ToolDialect, XmlDialect};",
"occurrence": 1
},