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
test(agent): use canonical middleware invocations
Steven Enamakelb4a9fd073f14
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rsindex 08b7174b47..b22fad824a 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs@@ -15,15 +15,23 @@ async fn sampling_tool_output_still_hits_the_byte_budget_backstop() {payload.len());let mut result = tool_result("get_tool_output_sample", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("sample-budget", "get_tool_output_sample"),+ &mut result,+ )+ .await+ .unwrap();assert_ne!(- result.content, payload,+ result_text(&result),+ payload,"get_tool_output_sample must still be subject to the shared byte-budget backstop");assert!(- result.content.contains("truncated by tool_result_budget"),+ result_text(&result).contains("truncated by tool_result_budget"),"expected the byte-budget truncation marker: {}",- result.content+ result_text(&result));}@@ -114,7 +122,9 @@ async fn repeated_tool_failure_pauses_only_after_the_threshold() {// nudges (Redirect) on the second, but must NOT pause (halt) yet.for _ in 0..2 {let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ .await+ .unwrap();}assert_eq!(drain_pause_count(&handle),@@ -123,7 +133,9 @@ async fn repeated_tool_failure_pauses_only_after_the_threshold() {);// Third identical failure exhausts the same-strategy retries → halt.let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ .await+ .unwrap();assert_eq!(drain_pause_count(&handle),1,@@ -142,15 +154,21 @@ async fn repeated_tool_failure_resets_on_a_success() {// Two failures, then a success clears the counter.for _ in 0..2 {let mut r = failing_result("t", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("t", "t"), &mut r)+ .await+ .unwrap();}let mut ok = tool_result("t", "fine"); // error = None- mw.after_tool(&mut ctx(), &(), &mut ok).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("t", "t"), &mut ok)+ .await+ .unwrap();// Two more failures — still below the halt threshold because the counter// reset, so the ladder never reaches the third identical repeat.for _ in 0..2 {let mut r = failing_result("t", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("t", "t"), &mut r)+ .await+ .unwrap();}assert_eq!(drain_pause_count(&handle),@@ -172,7 +190,9 @@ async fn repeated_tool_failure_ignores_distinct_errors() {// at 4 / halts at 6, both above this count).for err in ["e1", "e2", "e3"] {let mut r = failing_result("t", err);- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("t", "t"), &mut r)+ .await+ .unwrap();}assert_eq!(handle.pending(),@@ -230,7 +250,9 @@ async fn halt_on_missing_connection_asks_the_user_instead_of_reporting_back() {"slack_post","Slack is not connected — connect it in Connections.",);- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("slack", "slack_post"), &mut r)+ .await+ .unwrap();}let summary = slot.lock()@@ -269,14 +291,18 @@ async fn repeated_tool_failure_nudges_change_of_strategy_before_the_halt() {);// First identical failure: not a loop yet — no steering.let mut r = failing_result("read_file", "file not found");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("read-1", "read_file"), &mut r)+ .await+ .unwrap();assert!(handle.drain().is_empty(),"a single failure is never a loop");// Second identical failure: the nudge fires, still no halt.let mut r = failing_result("read_file", "file not found");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("read-2", "read_file"), &mut r)+ .await+ .unwrap();let nudges = drain_nudge_messages(&handle);assert_eq!(nudges.len(),@@ -359,8 +385,15 @@ async fn repeated_validate_workflow_ok_false_trips_the_breaker() {"validate_workflow",json!({ "errors": ["node 'x' has no outgoing edge"] }),);- assert!(r.error.is_none(), "the tool call itself did not error");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ assert!(!r.is_error, "the tool call itself did not error");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("validate", "validate_workflow"),+ &mut r,+ )+ .await+ .unwrap();if drain_pause_count(&handle) > 0 {halted = true;break;@@ -382,7 +415,14 @@ async fn single_or_unrelated_ok_false_does_not_falsely_trip_the_breaker() {);// A single validate_workflow ok:false is not a loop.let mut r = body_failure_result("validate_workflow", json!({}));- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("validate", "validate_workflow"),+ &mut r,+ )+ .await+ .unwrap();assert_eq!(drain_pause_count(&handle),0,@@ -393,7 +433,14 @@ async fn single_or_unrelated_ok_false_does_not_falsely_trip_the_breaker() {// a failure signal — it may be legitimate data from that tool.for _ in 0..8 {let mut r = body_failure_result("some_other_tool", json!({ "count": 0 }));- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("other", "some_other_tool"),+ &mut r,+ )+ .await+ .unwrap();}assert_eq!(drain_pause_count(&handle),@@ -419,7 +466,9 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {);for _ in 0..2 {let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ .await+ .unwrap();}assert_eq!(drain_pause_count(&handle),@@ -427,7 +476,9 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {"no halt before the threshold");let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ .await+ .unwrap();assert_eq!(drain_pause_count(&handle),1,@@ -444,8 +495,15 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {);for _ in 0..2 {let mut r = body_failure_result("validate_workflow", json!({}));- r.error = Some("validation failed".to_string());- mw2.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ r = TaToolResult::error(result_text(&r));+ mw2.after_tool(+ &mut ctx(),+ &(),+ &invocation("validate", "validate_workflow"),+ &mut r,+ )+ .await+ .unwrap();}assert_eq!(drain_pause_count(&handle2),@@ -453,8 +511,15 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {"two identical error+ok:false results are one repeat each, not two — below the halt threshold");let mut r = body_failure_result("validate_workflow", json!({}));- r.error = Some("validation failed".to_string());- mw2.after_tool(&mut ctx(), &(), &mut r).await.unwrap();+ r = TaToolResult::error(result_text(&r));+ mw2.after_tool(+ &mut ctx(),+ &(),+ &invocation("validate", "validate_workflow"),+ &mut r,+ )+ .await+ .unwrap();assert_eq!(drain_pause_count(&handle2),1,@@ -579,16 +644,14 @@ async fn memory_write_without_index_read_gets_a_corrective_note() {let mw = MemoryProtocolMiddleware::new();let result = run_cycle(&mw, "memory_store", json!({}), "stored entry 42", None).await;assert!(- result.content.contains(MEMORY_PROTOCOL_MARKER),+ result_text(&result).contains(MEMORY_PROTOCOL_MARKER),"a write with no preceding dedupe read should be annotated: {}",- result.content+ result_text(&result));- assert!(result- .content- .contains("without first reading the memory index"));- assert!(result.content.contains("update_memory_md"));+ assert!(result_text(&result).contains("without first reading the memory index"));+ assert!(result_text(&result).contains("update_memory_md"));// The original tool output is preserved, guidance is appended.- assert!(result.content.starts_with("stored entry 42"));+ assert!(result_text(&result).starts_with("stored entry 42"));}#[tokio::test]@@ -597,17 +660,15 @@ async fn full_cycle_read_then_write_then_update_only_reminds_on_the_write() {let read = run_cycle(&mw, "memory_recall", json!({}), "no dupes", None).await;assert!(- !read.content.contains(MEMORY_PROTOCOL_MARKER),+ !result_text(&read).contains(MEMORY_PROTOCOL_MARKER),"a read is not annotated");let write = run_cycle(&mw, "memory_store", json!({}), "stored", None).await;- assert!(write.content.contains(MEMORY_PROTOCOL_MARKER));+ assert!(result_text(&write).contains(MEMORY_PROTOCOL_MARKER));// The read preceded the write, so no missing-read complaint — just the// forward "sync the index" reminder.- assert!(!write- .content- .contains("without first reading the memory index"));+ assert!(!result_text(&write).contains("without first reading the memory index"));let update = run_cycle(&mw,@@ -618,7 +679,7 @@ async fn full_cycle_read_then_write_then_update_only_reminds_on_the_write() {).await;assert!(- !update.content.contains(MEMORY_PROTOCOL_MARKER),+ !result_text(&update).contains(MEMORY_PROTOCOL_MARKER),"closing the cycle needs no guidance");}@@ -644,9 +705,9 @@ async fn skill_md_update_does_not_close_the_memory_cycle() {// A following write reports drift, proving pending was not cleared.let next = run_cycle(&mw, "memory_store", json!({}), "again", None).await;assert!(- next.content.contains("drifting"),+ result_text(&next).contains("drifting"),"SKILL.md update must not mask the stale MEMORY.md index: {}",- next.content+ result_text(&next));}@@ -662,8 +723,8 @@ async fn consolidated_memory_tree_ingest_is_treated_as_a_write() {).await;assert!(- ingest.content.contains(MEMORY_PROTOCOL_MARKER),+ result_text(&ingest).contains(MEMORY_PROTOCOL_MARKER),"memory_tree ingest_document is a write and must be annotated: {}",- ingest.content+ result_text(&ingest));}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 89b783f668..129ce2abff 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -121,6 +121,17 @@ fn tool_result(_name: &str, content: &str) -> TaToolResult {TaToolResult::success(content)}+fn invocation(call_id: impl AsRef<str>, tool_name: impl Into<String>) -> ToolInvocationIdentity {+ ToolInvocationIdentity::new(+ tinyagents_harness::ids::CallId::new(call_id.as_ref()),+ tool_name,+ )+}++fn result_text(result: &TaToolResult) -> String {+ result.output()+}+// ── ToolOutcomeCaptureMiddleware policy-block enrichment (issue #4094) ───fn outcome_capture_mw() -> ToolOutcomeCaptureMiddleware {@@ -305,6 +316,8 @@ fn repeated_success_response(tool: &str, args: serde_json::Value) -> ModelResponresolved_model: None,continue_turn: None,served_from_cache: false,+ correlation: None,+ resolved_route: None,}}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rsindex 0731ebe369..7c45f5cece 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs@@ -52,23 +52,23 @@ async fn a_wrapped_read_of_a_persisted_artifact_is_paged_not_resummarized_or_repmw.before_tool(&mut ctx, &(), &mut call).await.unwrap();let mut result = tool_result("use_skill", &"y".repeat(5_000));- mw.after_tool(&mut ctx, &(), &mut result).await.unwrap();+ mw.after_tool(&mut ctx, &(), &invocation("c1", "use_skill"), &mut result)+ .await+ .unwrap();assert!(- result.content.starts_with("yyyy"),+ result_text(&result).starts_with("yyyy"),"an artifact read must return the stored body, not a summary of it: {:?}",- &result.content[..result.content.len().min(120)]+ &result_text(&result)[..result_text(&result).len().min(120)]);- let page_end = result- .content+ let rendered = result_text(&result);+ let page_end = rendered.find("\n\n[artifact page").expect("an over-budget read must be paged with a continuation marker");assert!(- result- .content- .contains(&format!("\"offset\":{}", 2_000 + page_end)),+ rendered.contains(&format!("\"offset\":{}", 2_000 + page_end)),"the page must name the exact offset the next read starts at: {}",- &result.content[page_end..]+ &rendered[page_end..]);assert!(!tmp.path().join("artifacts").exists(),@@ -85,12 +85,14 @@ async fn an_oversized_result_is_stored_as_the_tool_returned_it_not_as_rewritten(let raw = "r".repeat(8_000);let mut result = tool_result("echo", &raw);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("c1", "echo"), &mut result)+ .await+ .unwrap();assert!(- result.content.contains("[tool_result_preview]"),+ result_text(&result).contains("[tool_result_preview]"),"an over-budget result is persisted: {}",- result.content+ result_text(&result));let stored = std::fs::read_to_string(tmp.path()@@ -102,9 +104,9 @@ async fn an_oversized_result_is_stored_as_the_tool_returned_it_not_as_rewritten("the artifact must hold the tool's own output, not the rewritten copy");assert!(- result.content.contains("original_bytes: 8000"),+ result_text(&result).contains("original_bytes: 8000"),"the envelope must report the size of what was stored: {}",- result.content+ result_text(&result));}@@ -116,7 +118,9 @@ async fn a_raw_result_file_read_cannot_open_is_stored_as_the_processed_copy() {let mw = artifact_mw(Some(summarized(&summary, raw_len)), tmp.path());let mut result = tool_result("echo", &"r".repeat(raw_len));- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation("c1", "echo"), &mut result)+ .await+ .unwrap();let stored = std::fs::read_to_string(tmp.path()@@ -143,9 +147,16 @@ async fn handoff_leaves_an_artifact_read_for_the_pager_but_still_hands_off_otherlet oversized = "y".repeat(400_000);let mut ordinary = tool_result("echo", &oversized);- mw.after_tool(&mut ctx(), &(), &mut ordinary).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("ordinary", "echo"),+ &mut ordinary,+ )+ .await+ .unwrap();assert_ne!(- ordinary.content.len(),+ result_text(&ordinary).len(),oversized.len(),"control: an oversized ordinary result is still handed off");@@ -158,9 +169,11 @@ async fn handoff_leaves_an_artifact_read_for_the_pager_but_still_hands_off_otherlet mut ctx = ctx();mw.before_tool(&mut ctx, &(), &mut call).await.unwrap();let mut read = tool_result("file_read", &oversized);- mw.after_tool(&mut ctx, &(), &mut read).await.unwrap();+ mw.after_tool(&mut ctx, &(), &invocation("c1", "file_read"), &mut read)+ .await+ .unwrap();assert_eq!(- read.content.len(),+ result_text(&read).len(),oversized.len(),"an artifact read must reach the artifact pager with its bytes, not a handoff pointer");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.rsindex d40d540d82..089f47d486 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@@ -54,9 +54,14 @@ async fn unavailable_summarization_is_disclosed_in_the_payload() {let mut ctx = ctx();let mut result = tool_result("test_tool", "RAW-TOOL-OUTPUT");- mw.after_tool(&mut ctx, &(), &mut result)- .await- .expect("after_tool should not fail");+ mw.after_tool(+ &mut ctx,+ &(),+ &invocation("test-1", "test_tool"),+ &mut result,+ )+ .await+ .expect("after_tool should not fail");assert!(result@@ -81,9 +86,14 @@ async fn a_payload_that_needed_nothing_is_left_completely_alone() {let mut ctx = ctx();let mut result = tool_result("test_tool", "RAW-TOOL-OUTPUT");- mw.after_tool(&mut ctx, &(), &mut result)- .await- .expect("after_tool should not fail");+ mw.after_tool(+ &mut ctx,+ &(),+ &invocation("test-2", "test_tool"),+ &mut result,+ )+ .await+ .expect("after_tool should not fail");assert_eq!(result.content, "RAW-TOOL-OUTPUT",@@ -114,9 +124,14 @@ async fn a_summarizer_error_is_disclosed_rather_than_swallowed() {let mut ctx = ctx();let mut result = tool_result("test_tool", "RAW-TOOL-OUTPUT");- mw.after_tool(&mut ctx, &(), &mut result)- .await- .expect("a summarizer error must never break the tool call");+ mw.after_tool(+ &mut ctx,+ &(),+ &invocation("test-3", "test_tool"),+ &mut result,+ )+ .await+ .expect("a summarizer error must never break the tool call");assert!(result@@ -186,8 +201,15 @@ async fn raw_security_policy_block_is_enriched_with_workaround_and_relay() {"run_command","[policy-blocked] Security policy: read-only mode — only read commands are allowed",);- result.error = Some(result.content.clone());- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ result = TaToolResult::error(result_text(&result));+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("policy-1", "shell"),+ &mut result,+ )+ .await+ .unwrap();// The bare denial now carries a workaround + relay directive, and keeps the// marker so classification / the loop-breaker still recognise it.assert!(result.content.contains("Workaround:"), "{}", result.content);@@ -206,8 +228,10 @@ async fn already_structured_denial_is_not_double_wrapped() {let structured ="Blocked: Tool 'x' denied. Reason: nope. Workaround: do y. Relay this to the user: ...";let mut result = tool_result("x", structured);- result.error = Some(result.content.clone());- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ result = TaToolResult::error(result_text(&result));+ mw.after_tool(&mut ctx(), &(), &invocation("policy-2", "x"), &mut result)+ .await+ .unwrap();assert_eq!(result.content.matches("Workaround:").count(),1,@@ -321,7 +345,14 @@ async fn tool_output_truncates_over_the_flat_budget() {artifact_reads: Default::default(),};let mut result = tool_result("echo", &"x".repeat(5_000));- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("echo-capped", "echo"),+ &mut result,+ )+ .await+ .unwrap();assert!(result.content.len() < 5_000, "content should be capped");assert!(result.content.contains("truncated by tool_result_budget"),@@ -344,7 +375,14 @@ async fn tool_output_leaves_small_results_untouched() {artifact_reads: Default::default(),};let mut result = tool_result("echo", "tiny");- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("echo-small", "echo"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, "tiny");}@@ -421,7 +459,14 @@ async fn an_unavailable_notice_survives_a_tool_cap_shorter_than_itself() {};let mut result = tool_result("terse", &"payload ".repeat(200));- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("terse-notice", "terse"),+ &mut result,+ )+ .await+ .unwrap();let notice = UnavailableReason::Failed.notice();assert!(@@ -476,7 +521,14 @@ async fn tool_output_honors_a_tools_own_cap() {artifact_reads: Default::default(),};let mut result = tool_result("capped", &"y".repeat(500));- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("capped", "capped"),+ &mut result,+ )+ .await+ .unwrap();assert!(result.content@@ -525,7 +577,14 @@ async fn tool_output_tabulates_a_large_graph_for_a_non_exempt_tool() {"baseline payload must clear OpenHuman's configured compaction floor");let mut result = tool_result("some_other_tool", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("other-compact", "some_other_tool"),+ &mut result,+ )+ .await+ .unwrap();assert_ne!(result.content, payload,"a non-exempt tool's large uniform-array payload should be rewritten by tokenjuice"@@ -546,7 +605,14 @@ async fn tool_output_leaves_propose_workflow_byte_for_byte_intact() {let mw = compaction_enabled_mw();let payload = large_workflow_proposal_json();let mut result = tool_result("propose_workflow", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("proposal-compact", "propose_workflow"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, payload,"propose_workflow results must pass through compaction untouched"@@ -562,7 +628,14 @@ async fn tool_output_leaves_every_exempt_tool_name_intact() {let payload = large_workflow_proposal_json();for tool in COMPACTION_EXEMPT_TOOLS {let mut result = tool_result(tool, &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation(format!("exempt-{tool}"), tool),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, payload,"{tool}'s result must pass through compaction untouched"@@ -586,7 +659,14 @@ async fn tool_output_leaves_an_oversized_propose_workflow_byte_for_byte_intact()payload.len());let mut result = tool_result("propose_workflow", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("proposal-truncate", "propose_workflow"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, payload,"an oversized propose_workflow result must not be truncated by the shared byte-budget backstop"@@ -606,7 +686,14 @@ async fn tool_output_truncates_the_same_oversized_payload_for_a_non_exempt_tool(let mw = truncation_probe_mw();let payload = oversized_workflow_proposal_json(30);let mut result = tool_result("some_other_tool", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("other-truncate", "some_other_tool"),+ &mut result,+ )+ .await+ .unwrap();assert_ne!(result.content, payload,"a non-exempt tool's oversized payload should be truncated by the shared byte-budget backstop"@@ -631,7 +718,14 @@ async fn get_tool_output_sample_is_compaction_exempt() {let mw = compaction_enabled_mw();let payload = large_sample_response_json(10);let mut result = tool_result("get_tool_output_sample", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("sample", "get_tool_output_sample"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, payload,"get_tool_output_sample's response must not be tokenjuice-tabulated"@@ -643,7 +737,14 @@ async fn get_tool_contract_is_compaction_exempt() {let mw = compaction_enabled_mw();let payload = large_sample_response_json(10);let mut result = tool_result("get_tool_contract", &payload);- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("contract", "get_tool_contract"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(result.content, payload,"get_tool_contract's response must not be tokenjuice-tabulated"@@ -674,9 +775,14 @@ async fn the_turns_task_hint_reaches_the_payload_summarizer() {mw.task_hint = Some("find the release notes for v2".to_string());let mut result = tool_result("use_skill", "RAW-TOOL-OUTPUT");- mw.after_tool(&mut ctx(), &(), &mut result)- .await- .expect("after_tool should not fail");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("use-skill", "use_skill"),+ &mut result,+ )+ .await+ .expect("after_tool should not fail");assert_eq!(recorder.0.lock().expect("recorder lock").clone(),@@ -714,7 +820,14 @@ async fn the_summarized_size_survives_a_tool_cap_shorter_than_the_summary() {mw.tool_policies = tool_policies;let mut result = tool_result("terse", &"payload ".repeat(200));- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("terse-cap", "terse"),+ &mut result,+ )+ .await+ .unwrap();assert!(resultdiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_tests.rsindex 29baafd2d8..9d04161e59 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_tests.rs@@ -13,7 +13,7 @@ async fn failed_memory_write_does_not_advance_the_protocol() {.await;// A failed write is not annotated and leaves nothing pending, so a later// run-end sweep must not warn about a stale index.- assert!(!failed.content.contains(MEMORY_PROTOCOL_MARKER));+ assert!(!result_text(&failed).contains(MEMORY_PROTOCOL_MARKER));let mut run = AgentRun::new();// after_agent is a no-op warn path; it must not error.mw.after_agent(&mut ctx(), &(), &mut run).await.unwrap();@@ -24,14 +24,14 @@ async fn second_write_without_an_update_flags_index_drift() {let mw = MemoryProtocolMiddleware::new();run_cycle(&mw, "memory_recall", json!({}), "checked", None).await;let first = run_cycle(&mw, "memory_store", json!({}), "a", None).await;- assert!(!first.content.contains("drifting"));+ assert!(!result_text(&first).contains("drifting"));// No update_memory_md between the two writes → the index is drifting.let second = run_cycle(&mw, "memory_store", json!({}), "b", None).await;assert!(- second.content.contains("drifting"),+ result_text(&second).contains("drifting"),"a second unsynced write should flag index drift: {}",- second.content+ result_text(&second));}@@ -49,15 +49,15 @@ async fn embedder_tool_hooks_post_use_replays_the_normalized_pre_call_arguments(};mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();- let mut result = TaToolResult {- call_id: "call-1".into(),- name: "lookup".into(),- content: "found".into(),- raw: None,- error: None,- elapsed_ms: 7,- };- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ let mut result = TaToolResult::success("found");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("call-1", "lookup"),+ &mut result,+ )+ .await+ .unwrap();assert_eq!(pre.lock().unwrap().len(), 1, "one pre-use notification");let post = post.lock().unwrap();@@ -70,7 +70,10 @@ async fn embedder_tool_hooks_post_use_replays_the_normalized_pre_call_arguments("post-use context must preserve the normalized pre-call arguments, not Null");assert_eq!(*success, Some(true));- assert_eq!(*duration, Some(7));+ assert_eq!(+ *duration, None,+ "canonical ToolResult carries no elapsed field"+ );}#[tokio::test]@@ -113,15 +116,15 @@ async fn embedder_tool_hooks_post_use_without_pre_call_falls_back_to_null() {// A result with no matching `before_tool` (defensive path) must not panic// and falls back to `Null`, the pre-fix behaviour.- let mut result = TaToolResult {- call_id: "orphan".into(),- name: "lookup".into(),- content: "found".into(),- raw: None,- error: None,- elapsed_ms: 3,- };- mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();+ let mut result = TaToolResult::success("found");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("orphan", "lookup"),+ &mut result,+ )+ .await+ .unwrap();let post = post.lock().unwrap();assert_eq!(post.len(), 1);assert_eq!(post[0].1, serde_json::Value::Null);diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.mdindex e1ea65bbf9..daa42e3297 100644--- a/gitbooks/developing/architecture/agent-harness.md+++ b/gitbooks/developing/architecture/agent-harness.md@@ -488,19 +488,21 @@ When the backend doesn't surface a charged amount (older builds, providers that## Explicit run context and host capabilities-Every TinyAgents turn receives an explicit `OpenHumanRunContext`, converted to-the canonical `RunContext`. It carries OpenHuman-only values such as origin,+Phase B1 defines and tests an explicit `OpenHumanRunContext`, which converts to+the canonical `RunContext`. It carries the future explicit values for origin,parent execution state, progress, attachment/artifact scope, dispatch andrecency state, sandbox/depth, route observation, cancellation, thread,-workspace and stop hooks. Child contexts inherit shared tree handles while-isolating child route observation and usage accounting, so a child cannot-overwrite the parent turn's persisted facts.+workspace and stop hooks. The live task-local and public-route cutovers remain+deferred: no current turn receives this context yet. Its child rule will inherit+shared tree handles while isolating child route observation and usage+accounting, so a child cannot overwrite the parent turn's persisted facts.-`OpenHumanHostBundleFactory` is the one host composition point. It constructs+`OpenHumanHostBundleFactory` is the B1 host composition point. It constructsthe context, definition, security, model, memory, budget, progress, learning,tool-outcome and experience adapters from the same session/runtime inputs.OpenHuman retains all policy decisions; TinyAgents receives only the resulting-capabilities and canonical run context.+capabilities and canonical run context once the deferred live cutover wires it+into invocation.## Self-healing recap