Skip to content

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

refactor(agent): type tinyagents run context

Steven Enamakel4cb2ace0694e
diff --git a/crates/openhuman-core/src/agent/tinyagents/README.md b/crates/openhuman-core/src/agent/tinyagents/README.md
index ff856645a9..fe48c1edbb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/README.md
+++ b/crates/openhuman-core/src/agent/tinyagents/README.md
@@ -105,13 +105,12 @@ Responses project the crate's own `AgentObservation` and `HarnessRunStatus` serd
`HostCapabilities<()>` bundle from a single session/runtime input set, while
`OpenHumanRunContext` carries the explicit per-turn values (origin, progress,
attachments, artifacts, dispatch, cancellation, thread, workspace and stop
-hooks) across the OpenHuman turn boundary. During the current transition the
-live `AgentHarness<(), ()>` bridge maps cancellation and workspace into the
-canonical `tinyagents_harness::context::RunContext`; the runner consumes
-origin and dispatch directly and re-establishes the context's thread and route
-scopes around model execution. Generic middleware-state and remaining entrypoint
-cutovers are required before those scopes and the manual assembly shell can be
-deleted.
+hooks) across the OpenHuman turn boundary. The shared runner builds
+`RunContext<OpenHumanRunContext>` with `into_tinyagents`, and the OpenHuman
+assembly plus middleware stack are specialized to that context. Route, thread,
+and cancellation task-local scopes remain only around the drive while legacy
+tool/model consumers still require them; they are seeded solely from the typed
+carrier.
## Notes
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 72ede30229..d166d67404 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -20,6 +20,7 @@ use crate::agent::progress::AgentProgress;
use crate::agent::tinyagents::harness_context_ladder::install_context_ladder;
use crate::agent::tinyagents::harness_tool_registration::register_turn_tools_and_agents;
use crate::agent::tinyagents::host::steering;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::middleware::{self, TurnContextMiddleware};
use crate::agent::tinyagents::observability::{
IterationCursor, ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,
@@ -39,7 +40,7 @@ use super::ToolPolicyEnforcement;
pub(super) struct AssembledTurnHarness {
/// The fully assembled harness: model, tools, and middleware registered in
/// the intended order.
- pub(super) harness: AgentHarness<()>,
+ pub(super) harness: AgentHarness<(), OpenHumanRunContext>,
/// Shared 1-based model-call cursor (event bridge advances, model adapter
/// reads for out-of-band thinking attribution).
pub(super) cursor: IterationCursor,
@@ -118,6 +119,7 @@ pub(super) fn assemble_turn_harness(
context_window: Option<u64>,
early_exit_tools: &[&str],
context_mw: TurnContextMiddleware,
+ stop_hooks: Vec<Arc<dyn crate::agent::stop_hooks::StopHook>>,
tool_policy: Option<ToolPolicyEnforcement>,
required_capabilities: Option<CapabilitySet>,
deterministic_cacheable: bool,
@@ -128,7 +130,7 @@ pub(super) fn assemble_turn_harness(
// would silently convert a documented error into an answer.
pause_at_cap: bool,
) -> AssembledTurnHarness {
- let mut harness: AgentHarness<()> = AgentHarness::new();
+ let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
// Cross-route fallback ownership (issue #4249, Workstream 02.2): populate the
// SDK `RunPolicy.fallback` with the ordered same-family route chain for this
// turn's primary model so the harness fails over to a sibling workload tier
@@ -157,7 +159,8 @@ pub(super) fn assemble_turn_harness(
"[cache] response cache attached (deterministic internal run)"
);
}
- let mut capability_registry: CapabilityRegistry<()> = CapabilityRegistry::new();
+ let mut capability_registry: CapabilityRegistry<OpenHumanRunContext> =
+ CapabilityRegistry::new();
let cursor: IterationCursor = Arc::default();
// Shared `call_id → tool_name` map: the forwarder records the name on
@@ -241,11 +244,9 @@ pub(super) fn assemble_turn_harness(
.as_ref()
.map(|_| Arc::new(ToolResultArtifactIndexStore::new()));
- // Snapshot the installed stop hooks while the `CURRENT_STOP_HOOKS`
- // task-local is in scope (the harness drive future runs inline on this
- // task, but capturing here keeps the wiring robust). When present they fire
- // via `StopHookMiddleware` and pause through the shared steering handle.
- let stop_hooks_installed = crate::agent::stop_hooks::current_stop_hooks();
+ // The explicit run carrier supplies the stop hooks; no middleware needs to
+ // recover policy from a task-local while the harness is driving.
+ let stop_hooks_installed = stop_hooks;
// A single steering handle drives mid-flight steering (run queue), the
// early-exit pause, the model-call-cap pause, and stop-hook pauses, so they
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
index daef80fb62..1612ad1336 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
@@ -13,6 +13,7 @@ use std::sync::Arc;
use tinyagents_harness::middleware::ContextCompressionMiddleware;
use tinyagents_harness::runtime::AgentHarness;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::middleware;
use crate::agent::tinyagents::model::TurnChatModel;
use crate::agent::tinyagents::summarize;
@@ -28,7 +29,7 @@ use crate::agent::tinyagents::turn_outcome::ToolOutcomeSink;
/// erroring runs are excluded.
#[allow(clippy::too_many_arguments)]
pub(super) fn install_context_ladder(
- harness: &mut AgentHarness<()>,
+ harness: &mut AgentHarness<(), OpenHumanRunContext>,
model: &str,
context_window: Option<u64>,
autocompact_enabled: bool,
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
index 7cc5bbd4e1..ad3d55f254 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
@@ -11,6 +11,7 @@ use tinyagents_registry::{
CapabilityRegistry, ComponentKind, RegistryDiagnostic, RegistrySnapshot,
};
+use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::tools::{CanonicalSharedToolAdapter, EarlyExitHook};
use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;
@@ -29,8 +30,8 @@ use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;
/// fail-open.
#[allow(clippy::too_many_arguments)]
pub(super) fn register_turn_tools_and_agents(
- harness: &mut AgentHarness<()>,
- capability_registry: &mut CapabilityRegistry<()>,
+ harness: &mut AgentHarness<(), OpenHumanRunContext>,
+ capability_registry: &mut CapabilityRegistry<OpenHumanRunContext>,
tool_sets: &[Arc<Vec<Box<dyn tinytools::Tool>>>],
allowed: &Option<HashSet<String>>,
early_exit_set: &HashSet<&str>,
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 a82b113e8e..dff5fbe783 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -5,10 +5,9 @@
//! task-locals: approval origin, host progress, attachment and artifact scope,
//! parent dispatch state, and the handles a tool needs to continue a run.
//! The shared turn seam receives this as its live OpenHuman carrier. The
-//! existing middleware registry still uses `RunContext<()>`, so that seam maps
-//! only canonical TinyAgents values (cancellation and workspace) while the
-//! remaining host-local consumers migrate. `into_tinyagents` is the target
-//! conversion once the middleware registry becomes generic over this carrier.
+//! The live middleware registry uses this type as the TinyAgents run context,
+//! so every host seam receives the same explicit carrier rather than recovering
+//! product state from a task-local.
use std::sync::{Arc, Mutex};
use std::time::Duration;
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/approval.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/approval.rs
index b93818850c..473ae17a46 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/approval.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/approval.rs
@@ -78,17 +78,19 @@ impl ApprovalSecurityMiddleware {
}
#[async_trait]
-impl ToolMiddleware<()> for ApprovalSecurityMiddleware {
+impl ToolMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ApprovalSecurityMiddleware
+{
fn name(&self) -> &str {
"approval_security"
}
async fn wrap_tool(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
call: TaToolCall,
- next: ToolHandler<'_, (), ()>,
+ next: ToolHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> TaResult<MiddlewareToolOutcome> {
// Resolve external-effect up front so no tool borrow is held across the
// approval await.
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/arg_recovery.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/arg_recovery.rs
index d6eda6d9e6..99c93dd085 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/arg_recovery.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/arg_recovery.rs
@@ -49,14 +49,14 @@ impl ArgRecoveryMiddleware {
}
#[async_trait]
-impl Middleware<()> for ArgRecoveryMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for ArgRecoveryMiddleware {
fn name(&self) -> &str {
"arg_recovery"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/artifact_index_toc.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/artifact_index_toc.rs
index bff96e6eb7..dbe4ddef36 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/artifact_index_toc.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/artifact_index_toc.rs
@@ -117,14 +117,16 @@ impl ArtifactIndexTocMiddleware {
}
#[async_trait]
-impl Middleware<()> for ArtifactIndexTocMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ArtifactIndexTocMiddleware
+{
fn name(&self) -> &str {
"artifact_index_toc"
}
async fn before_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/cli_rpc_only.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/cli_rpc_only.rs
index 95055832df..711db007c4 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/cli_rpc_only.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/cli_rpc_only.rs
@@ -40,17 +40,19 @@ impl CliRpcOnlyMiddleware {
}
#[async_trait]
-impl ToolMiddleware<()> for CliRpcOnlyMiddleware {
+impl ToolMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for CliRpcOnlyMiddleware
+{
fn name(&self) -> &str {
"cli_rpc_only"
}
async fn wrap_tool(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
call: TaToolCall,
- next: ToolHandler<'_, (), ()>,
+ next: ToolHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> TaResult<MiddlewareToolOutcome> {
if self.is_cli_rpc_only(&call.name) {
tracing::warn!(
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/cost_budget.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/cost_budget.rs
index 48d991befa..f35cf7532a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/cost_budget.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/cost_budget.rs
@@ -63,14 +63,14 @@ impl CostBudgetMiddleware {
}
#[async_trait]
-impl Middleware<()> for CostBudgetMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for CostBudgetMiddleware {
fn name(&self) -> &str {
"cost_budget"
}
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
@@ -136,7 +136,7 @@ impl Middleware<()> for CostBudgetMiddleware {
/// Never fails the run.
async fn after_agent(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
run: &mut AgentRun,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub.rs
index b041e35f64..bdfe964349 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub.rs
@@ -34,17 +34,19 @@ impl CredentialScrubMiddleware {
}
#[async_trait]
-impl ToolMiddleware<()> for CredentialScrubMiddleware {
+impl ToolMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for CredentialScrubMiddleware
+{
fn name(&self) -> &str {
"credential_scrub"
}
async fn wrap_tool(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
call: TaToolCall,
- next: ToolHandler<'_, (), ()>,
+ next: ToolHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> TaResult<MiddlewareToolOutcome> {
let tool_name = call.name.clone();
let outcome = next.run(ctx, state, call).await?;
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 ec1c56ecdb..3a307f72eb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
@@ -32,14 +32,16 @@ impl EmbedderToolHooksMiddleware {
}
#[async_trait]
-impl Middleware<()> for EmbedderToolHooksMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for EmbedderToolHooksMiddleware
+{
fn name(&self) -> &str {
"embedder_tool_hooks"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
@@ -109,7 +111,7 @@ impl Middleware<()> for EmbedderToolHooksMiddleware {
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/final_call_wrap_up.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/final_call_wrap_up.rs
index 62aff3b8a6..fd2d46cfec 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/final_call_wrap_up.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/final_call_wrap_up.rs
@@ -99,14 +99,16 @@ impl FinalCallWrapUpMiddleware {
}
#[async_trait]
-impl Middleware<()> for FinalCallWrapUpMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for FinalCallWrapUpMiddleware
+{
fn name(&self) -> &str {
"final_call_wrap_up"
}
async fn before_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
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 2fabed4913..2abd1d0f7a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs
@@ -52,14 +52,16 @@ impl Default for MemoryProtocolMiddleware {
}
#[async_trait]
-impl Middleware<()> for MemoryProtocolMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for MemoryProtocolMiddleware
+{
fn name(&self) -> &str {
"memory_protocol"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
@@ -78,7 +80,7 @@ impl Middleware<()> for MemoryProtocolMiddleware {
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
@@ -123,7 +125,7 @@ impl Middleware<()> for MemoryProtocolMiddleware {
async fn after_agent(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
_run: &mut AgentRun,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/message_trim.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/message_trim.rs
index 590f5c865c..0ec8a6f826 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/message_trim.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/message_trim.rs
@@ -148,14 +148,16 @@ impl ImageAwareMessageTrimMiddleware {
}
#[async_trait]
-impl Middleware<()> for ImageAwareMessageTrimMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ImageAwareMessageTrimMiddleware
+{
fn name(&self) -> &str {
"image_aware_message_trim"
}
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/packed_tool_route.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/packed_tool_route.rs
index 3336689357..60b18f6fd2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/packed_tool_route.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/packed_tool_route.rs
@@ -113,14 +113,16 @@ impl PackedToolRouteMiddleware {
}
#[async_trait]
-impl Middleware<()> for PackedToolRouteMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for PackedToolRouteMiddleware
+{
fn name(&self) -> &str {
"packed_tool_route"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/prompt_cache.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/prompt_cache.rs
index f38bfd6345..3f11a27d4f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/prompt_cache.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/prompt_cache.rs
@@ -46,14 +46,16 @@ fn stable_prefix_fingerprint(value: &serde_json::Value) -> String {
pub(crate) struct PromptCacheSegmentMiddleware;
#[async_trait]
-impl Middleware<()> for PromptCacheSegmentMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for PromptCacheSegmentMiddleware
+{
fn name(&self) -> &str {
"prompt_cache_segments"
}
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
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 ae2566cf37..4fce4387c2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
@@ -159,14 +159,16 @@ impl RepeatProgressMiddleware {
}
#[async_trait]
-impl Middleware<()> for RepeatProgressMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for RepeatProgressMiddleware
+{
fn name(&self) -> &str {
"repeat_progress"
}
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
@@ -184,7 +186,7 @@ impl Middleware<()> for RepeatProgressMiddleware {
async fn after_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
response: &mut ModelResponse,
) -> TaResult<()> {
@@ -256,7 +258,7 @@ impl Middleware<()> for RepeatProgressMiddleware {
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
@@ -347,14 +349,16 @@ pub(crate) struct RepeatEvictionObserver {
}
#[async_trait]
-impl Middleware<()> for RepeatEvictionObserver {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for RepeatEvictionObserver
+{
fn name(&self) -> &str {
"repeat_progress_eviction"
}
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
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 b242d40c4a..9da442fff8 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -221,14 +221,16 @@ pub(crate) fn is_body_level_failure(name: &str, content: &str) -> bool {
}
#[async_trait]
-impl Middleware<()> for RepeatedToolFailureMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for RepeatedToolFailureMiddleware
+{
fn name(&self) -> &str {
"repeated_tool_failure"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
@@ -242,7 +244,7 @@ impl Middleware<()> for RepeatedToolFailureMiddleware {
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_exposure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_exposure.rs
index 65fa764e81..3a4884d2dd 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_exposure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_exposure.rs
@@ -127,14 +127,16 @@ impl OpenHumanToolExposureShadowMiddleware {
}
#[async_trait]
-impl Middleware<()> for OpenHumanToolExposureShadowMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for OpenHumanToolExposureShadowMiddleware
+{
fn name(&self) -> &str {
"openhuman_tool_exposure_shadow"
}
async fn before_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
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 4cf4f40bb6..7cdae1eb0a 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
@@ -38,14 +38,16 @@ impl ToolOutcomeCaptureMiddleware {
}
#[async_trait]
-impl Middleware<()> for ToolOutcomeCaptureMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ToolOutcomeCaptureMiddleware
+{
fn name(&self) -> &str {
"tool_outcome_capture"
}
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
@@ -123,8 +125,11 @@ mod tests {
use super::*;
use tinyagents_harness::context::{RunConfig, RunContext};
- fn context() -> RunContext<()> {
- RunContext::new(RunConfig::new("outcome-capture-test"), ())
+ fn context() -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
+ RunContext::new(
+ RunConfig::new("outcome-capture-test"),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
}
#[tokio::test]
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 238d528305..7175c03570 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs
@@ -125,14 +125,14 @@ impl ToolOutputMiddleware {
}
#[async_trait]
-impl Middleware<()> for ToolOutputMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for ToolOutputMiddleware {
fn name(&self) -> &str {
"tool_output_budget"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
@@ -153,7 +153,7 @@ impl Middleware<()> for ToolOutputMiddleware {
async fn after_tool(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
@@ -447,8 +447,11 @@ mod tests {
use super::*;
use tinyagents_harness::context::{RunConfig, RunContext};
- fn context() -> RunContext<()> {
- RunContext::new(RunConfig::new("tool-output-identity-test"), ())
+ fn context() -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
+ RunContext::new(
+ RunConfig::new("tool-output-identity-test"),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
index 489944e723..59805dcc06 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_policy.rs
@@ -298,17 +298,19 @@ impl ToolPolicyMiddleware {
}
#[async_trait]
-impl ToolMiddleware<()> for ToolPolicyMiddleware {
+impl ToolMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ToolPolicyMiddleware
+{
fn name(&self) -> &str {
"tool_policy"
}
async fn wrap_tool(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
call: TaToolCall,
- next: ToolHandler<'_, (), ()>,
+ next: ToolHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> TaResult<MiddlewareToolOutcome> {
use crate::agent::tool_policy::{ToolCallContext, ToolPolicyDecision, ToolPolicyRequest};
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 bdf3de78eb..4773180bc8 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -163,14 +163,16 @@ pub(crate) struct TranscriptSnapshotMiddleware {
}
#[async_trait]
-impl Middleware<()> for TranscriptSnapshotMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for TranscriptSnapshotMiddleware
+{
fn name(&self) -> &str {
"openhuman.transcript_snapshot"
}
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
@@ -188,7 +190,7 @@ impl Middleware<()> for TranscriptSnapshotMiddleware {
async fn before_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
request: &mut ModelRequest,
) -> TaResult<()> {
@@ -200,7 +202,7 @@ impl Middleware<()> for TranscriptSnapshotMiddleware {
async fn after_model(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
response: &mut ModelResponse,
) -> TaResult<()> {
@@ -275,7 +277,7 @@ impl TurnContextMiddleware {
/// summarization/trim handle the rest.
pub(crate) fn install(
self,
- harness: &mut AgentHarness<()>,
+ harness: &mut AgentHarness<(), crate::agent::tinyagents::host::OpenHumanRunContext>,
tool_policies: HashMap<String, TaToolPolicy>,
) {
// Transcript snapshot (#4466) runs first among before_model hooks so it
@@ -362,14 +364,14 @@ impl HandoffMiddleware {
}
#[async_trait]
-impl Middleware<()> for HandoffMiddleware {
+impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for HandoffMiddleware {
fn name(&self) -> &str {
"result_handoff"
}
async fn before_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
call: &mut tinyinference_llm::tool::ToolCall,
) -> TaResult<()> {
@@ -388,7 +390,7 @@ impl Middleware<()> for HandoffMiddleware {
async fn after_tool(
&self,
- _ctx: &mut RunContext<()>,
+ _ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
invocation: &ToolInvocationIdentity,
result: &mut TaToolResult,
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
index 129ce2abff..a328fa1c57 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
@@ -33,8 +33,11 @@ use tinyagents_harness::no_progress::{
use tinyinference_llm::model::ModelRequest;
use tinytools::Tool;
-fn ctx() -> RunContext<()> {
- RunContext::new(RunConfig::new("mw-test"), ())
+fn ctx() -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
+ RunContext::new(
+ RunConfig::new("mw-test"),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
}
// ── payload_summarizer disclosure (#5722) ──────────────────────
@@ -57,7 +60,7 @@ impl StubSummarizer {
impl PayloadSummarizer for StubSummarizer {
async fn maybe_summarize_in_parent(
&self,
- _parent_ctx: &RunContext<()>,
+ _parent_ctx: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_tool_name: &str,
_parent_task_hint: Option<&str>,
_raw: &str,
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 a6fa84f8fa..253a2f95b6 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
@@ -110,7 +110,7 @@ async fn a_summarizer_error_is_disclosed_rather_than_swallowed() {
impl PayloadSummarizer for ErroringSummarizer {
async fn maybe_summarize_in_parent(
&self,
- _parent_ctx: &RunContext<()>,
+ _parent_ctx: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_tool_name: &str,
_parent_task_hint: Option<&str>,
_raw: &str,
@@ -763,7 +763,7 @@ async fn the_turns_task_hint_reaches_the_payload_summarizer() {
impl PayloadSummarizer for HintRecorder {
async fn maybe_summarize_in_parent(
&self,
- _parent_ctx: &RunContext<()>,
+ _parent_ctx: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_tool_name: &str,
parent_task_hint: Option<&str>,
_raw: &str,
diff --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.rs
index 9d04161e59..7bef51b4a9 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
@@ -151,7 +151,10 @@ fn sink_with(entries: &[(&str, &str)]) -> crate::agent::tinyagents::ToolOutcomeS
#[tokio::test]
async fn wrap_up_leaves_a_call_with_budget_remaining_alone() {
let mw = FinalCallWrapUpMiddleware::new("CONCLUDE NOW", sink_with(&[]), 0);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(5), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(5),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
let mut request = ModelRequest {
messages: vec![TaMessage::user("hi")],
@@ -174,7 +177,10 @@ async fn wrap_up_leaves_a_call_with_budget_remaining_alone() {
#[tokio::test]
async fn wrap_up_withdraws_tools_and_appends_the_instruction_on_the_last_call() {
let mw = FinalCallWrapUpMiddleware::new("CONCLUDE NOW", sink_with(&[]), 0);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(2), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(2),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
ctx.limits.record_model_call().unwrap(); // now the final call
let mut request = ModelRequest {
@@ -220,7 +226,10 @@ async fn wrap_up_restores_tool_results_microcompact_cleared() {
// the budget that stops it (covered by its own test below).
0,
);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(2), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(2),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
ctx.limits.record_model_call().unwrap();
let mut request = ModelRequest {
@@ -252,7 +261,10 @@ async fn wrap_up_restores_tool_results_microcompact_cleared() {
async fn wrap_up_does_not_rewrite_a_result_that_was_never_cleared() {
let mw =
FinalCallWrapUpMiddleware::new("CONCLUDE NOW", sink_with(&[("call-1", "FROM SINK")]), 0);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(2), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(2),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
ctx.limits.record_model_call().unwrap();
let mut request = ModelRequest {
@@ -271,14 +283,16 @@ async fn wrap_up_does_not_rewrite_a_result_that_was_never_cleared() {
// ── ArtifactIndexTocMiddleware (issue #6014) ─────────────────────────────────
-async fn ctx_with_artifacts(entries: &[(&str, &str, &str, u64)]) -> RunContext<()> {
+async fn ctx_with_artifacts(
+ entries: &[(&str, &str, &str, u64)],
+) -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
ctx_with_artifacts_and_config(entries, RunConfig::new("mw-test")).await
}
async fn ctx_with_artifacts_and_config(
entries: &[(&str, &str, &str, u64)],
config: RunConfig,
-) -> RunContext<()> {
+) -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
use tinyagents_harness::store::StoreRegistry;
let index = std::sync::Arc::new(
crate::agent::harness::tool_result_artifacts::ToolResultArtifactIndexStore::new(),
@@ -306,7 +320,11 @@ async fn ctx_with_artifacts_and_config(
crate::agent::harness::tool_result_artifacts::TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE,
index,
);
- RunContext::new(config, ()).with_stores(registry)
+ RunContext::new(
+ config,
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
+ .with_stores(registry)
}
/// Nothing offloaded → no message. The contents list must not spend context
@@ -411,7 +429,10 @@ async fn wrap_up_stops_restoring_at_the_input_budget() {
// Room for roughly one of them, not three.
1_200,
);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(2), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(2),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
ctx.limits.record_model_call().unwrap();
let mut request = ModelRequest {
@@ -592,7 +613,10 @@ async fn wrap_up_restoration_stays_bounded_when_no_window_is_advertised() {
.collect();
let (_toc, restore) = split_input_allowance(0);
let mw = FinalCallWrapUpMiddleware::new("CONCLUDE NOW", sink_with(&borrowed), restore);
- let mut ctx = RunContext::new(RunConfig::new("mw-test").with_max_model_calls(2), ());
+ let mut ctx = RunContext::new(
+ RunConfig::new("mw-test").with_max_model_calls(2),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ );
ctx.limits.record_model_call().unwrap();
ctx.limits.record_model_call().unwrap();
let mut request = ModelRequest {
diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs
index a4d940ecf1..801bbddf29 100644
--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs
@@ -63,8 +63,9 @@ use tinyagents_harness::subagent::SubAgent;
use tracing::{debug, info, warn};
use crate::agent::harness::definition::{AgentDefinition, PromptSource};
-use crate::agent::harness::fork_context::{current_parent, ParentExecutionContext};
+use crate::agent::harness::fork_context::ParentExecutionContext;
use crate::agent::harness::subagent_runner;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
/// A successful compression, carried by [`SummarizeOutcome::Summarized`].
///
@@ -188,7 +189,7 @@ pub trait PayloadSummarizer: Send + Sync {
/// pattern-matching it away.
async fn maybe_summarize_in_parent(
&self,
- parent_ctx: &RunContext<()>,
+ parent_ctx: &RunContext<OpenHumanRunContext>,
tool_name: &str,
parent_task_hint: Option<&str>,
raw: &str,
@@ -287,7 +288,7 @@ impl SubagentPayloadSummarizer {
impl PayloadSummarizer for SubagentPayloadSummarizer {
async fn maybe_summarize_in_parent(
&self,
- parent_ctx: &RunContext<()>,
+ parent_ctx: &RunContext<OpenHumanRunContext>,
tool_name: &str,
parent_task_hint: Option<&str>,
raw: &str,
@@ -321,7 +322,12 @@ impl PayloadSummarizer for SubagentPayloadSummarizer {
}
// Checked before the breaker: a summary we already have costs nothing,
// so a broken summarizer is no reason to withhold it.
- let cache_key = summary_cache_key(tool_name, parent_task_hint, raw);
+ let cache_key = summary_cache_key(
+ parent_ctx.thread_id().map(str::to_owned).as_deref(),
+ tool_name,
+ parent_task_hint,
+ raw,
+ );
if let Some(summary) = cached_summary(&cache_key) {
info!(
tool = tool_name,
@@ -365,10 +371,10 @@ impl PayloadSummarizer for SubagentPayloadSummarizer {
impl SubagentPayloadSummarizer {
async fn invoke_tinyagents_summarizer_in_parent(
&self,
- parent_ctx: &RunContext<()>,
+ parent_ctx: &RunContext<OpenHumanRunContext>,
prompt: String,
) -> Result<String> {
- let parent = current_parent().ok_or_else(|| {
+ let parent = parent_ctx.data.parent.clone().ok_or_else(|| {
anyhow!("payload summarizer cannot use invoke_in_parent without ParentExecutionContext")
})?;
let config_loaded = crate::config::Config::load_or_init().await;
@@ -395,7 +401,7 @@ impl SubagentPayloadSummarizer {
policy.unknown_tool = UnknownToolPolicy::ReturnToolError;
policy.invalid_args = InvalidArgsPolicy::ReturnToolError;
- let mut harness: AgentHarness<()> = AgentHarness::new();
+ let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
harness.with_policy(policy);
let provider_model = super::model::MaxTokensModel::new(
source.build_summarizer(&model, self.definition.temperature)?,
@@ -437,7 +443,13 @@ impl SubagentPayloadSummarizer {
// `max_turn_output_tokens` (already enforced independently by the
// `MaxTokensModel` wrapper above).
let run = child
- .invoke_with_events(&(), (), parent_ctx.depth(), prompt, &parent_ctx.events)
+ .invoke_with_events(
+ &(),
+ parent_ctx.data.child(),
+ parent_ctx.depth(),
+ prompt,
+ &parent_ctx.events,
+ )
.await?;
Ok(run.text().unwrap_or_default())
}
@@ -602,18 +614,14 @@ struct SummaryCache {
/// can drop exactly the facts another goal needs. Fields are length-prefixed
/// so no two different tuples hash the same byte stream.
fn summary_cache_key(
+ thread_id: Option<&str>,
tool_name: &str,
parent_task_hint: Option<&str>,
raw: &str,
) -> SummaryCacheKey {
- let thread = super::thread_context::current_thread_id().unwrap_or_default();
+ let thread = thread_id.unwrap_or_default();
let mut hasher = Sha256::new();
- for part in [
- thread.as_str(),
- tool_name,
- parent_task_hint.unwrap_or(""),
- raw,
- ] {
+ for part in [thread, tool_name, parent_task_hint.unwrap_or(""), raw] {
hasher.update((part.len() as u64).to_le_bytes());
hasher.update(part.as_bytes());
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
index 5dbb5091ed..4b302526e3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
@@ -43,8 +43,11 @@ fn dummy_definition() -> AgentDefinition {
const TEST_THRESHOLD_TOKENS: usize = 500_000;
const TEST_MAX_TOKENS: usize = 2_000_000;
-fn dummy_parent_ctx() -> RunContext<()> {
- RunContext::new(tinyagents_harness::context::RunConfig::new("test"), ())
+fn dummy_parent_ctx() -> RunContext<crate::agent::tinyagents::host::OpenHumanRunContext> {
+ RunContext::new(
+ tinyagents_harness::context::RunConfig::new("test"),
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
}
#[tokio::test]
@@ -221,7 +224,7 @@ async fn an_identical_payload_reuses_the_earlier_summary_instead_of_dispatching(
let raw = "identical payload for the reuse test ".repeat(64);
let hint = Some("reuse-test goal");
remember_summary(
- summary_cache_key("reuse_tool", hint, &raw),
+ summary_cache_key(None, "reuse_tool", hint, &raw),
"CACHED SUMMARY".to_string(),
);
@@ -248,7 +251,7 @@ async fn an_identical_payload_reuses_the_earlier_summary_instead_of_dispatching(
async fn a_summary_written_for_another_goal_is_not_reused() {
let raw = "payload shared across two goals ".repeat(64);
remember_summary(
- summary_cache_key("goal_tool", Some("goal A"), &raw),
+ summary_cache_key(None, "goal_tool", Some("goal A"), &raw),
"SUMMARY FOR GOAL A".to_string(),
);
@@ -267,7 +270,7 @@ async fn a_summary_written_for_another_goal_is_not_reused() {
fn a_successful_summary_is_remembered_for_reuse() {
let summarizer = low_threshold_summarizer();
let raw = "x".repeat(50_000);
- let key = summary_cache_key("size_tool", Some("size goal"), &raw);
+ let key = summary_cache_key(None, "size_tool", Some("size goal"), &raw);
let outcome = summarizer
.handle_summarizer_result(
diff --git a/crates/openhuman-core/src/agent/tinyagents/routes.rs b/crates/openhuman-core/src/agent/tinyagents/routes.rs
index 7fbf27ffe0..30df88efd3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/routes.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/routes.rs
@@ -122,17 +122,19 @@ impl RequiredCapabilitiesMiddleware {
}
#[async_trait]
-impl ModelMiddleware<()> for RequiredCapabilitiesMiddleware {
+impl ModelMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for RequiredCapabilitiesMiddleware
+{
fn name(&self) -> &str {
"openhuman.required_capabilities"
}
async fn wrap_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
mut request: ModelRequest,
- next: ModelHandler<'_, (), ()>,
+ next: ModelHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> tinyagents_harness::Result<MiddlewareModelOutcome> {
if request.required_capabilities.is_none() {
request = request.with_required_capabilities(self.required.clone());
@@ -193,17 +195,19 @@ impl FallbackObserverMiddleware {
}
#[async_trait]
-impl ModelMiddleware<()> for FallbackObserverMiddleware {
+impl ModelMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for FallbackObserverMiddleware
+{
fn name(&self) -> &str {
"openhuman.fallback_observer"
}
async fn wrap_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
request: ModelRequest,
- next: ModelHandler<'_, (), ()>,
+ next: ModelHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> tinyagents_harness::Result<MiddlewareModelOutcome> {
let outcome = next.run(ctx, state, request).await?;
let response = outcome.into_response();
@@ -250,17 +254,19 @@ impl UsageCarryMiddleware {
}
#[async_trait]
-impl ModelMiddleware<()> for UsageCarryMiddleware {
+impl ModelMiddleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for UsageCarryMiddleware
+{
fn name(&self) -> &str {
"openhuman.usage_carry"
}
async fn wrap_model(
&self,
- ctx: &mut RunContext<()>,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
state: &(),
request: ModelRequest,
- next: ModelHandler<'_, (), ()>,
+ next: ModelHandler<'_, (), crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> tinyagents_harness::Result<MiddlewareModelOutcome> {
let outcome = next.run(ctx, state, request).await?;
let response = outcome.into_response();
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
index c8fd373878..8e9d7eebd2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
@@ -16,7 +16,9 @@ use std::sync::Arc;
use anyhow::Result;
use futures::StreamExt;
use tinyagents_harness::agent_loop::AgentStreamItem;
-use tinyagents_harness::context::{RunConfig, RunContext};
+use tinyagents_harness::context::RunConfig;
+#[cfg(test)]
+use tinyagents_harness::context::RunContext;
use tinyagents_harness::events::EventSink;
use tinyagents_harness::store::StoreRegistry;
use tinyagents_registry::DiagnosticSeverity;
@@ -265,6 +267,7 @@ pub(crate) async fn run_turn_via_tinyagents_shared(
context_window,
early_exit_tools,
context_mw,
+ run_context.stop_hooks.clone(),
tool_policy,
routes::turn_required_capabilities(model),
deterministic_cacheable,
@@ -362,14 +365,10 @@ pub(crate) async fn run_turn_via_tinyagents_shared(
// bridge (streaming) and/or the model-call-cap pauser; the shared steering
// handle carries mid-flight, early-exit, and cap pauses.
let cancellation = run_context.cancellation.clone();
- // The OpenHuman carrier remains the entry boundary even while the current
- // harness middleware inventory is specialized to `()`. Map only the
- // canonical generic values here; the follow-up changes every middleware to
- // `OpenHumanRunContext` and replaces this bridge with `into_tinyagents`.
- let mut ctx = RunContext::new(config, ()).with_cancellation(cancellation.clone());
- if let Some(workspace) = run_context.workspace.clone() {
- ctx = ctx.with_workspace(workspace);
- }
+ let mut run_context = run_context;
+ run_context.tool_result_artifact_index = tool_result_artifact_index.clone();
+ run_context.tool_outcomes = Some(tool_outcome_sink.clone());
+ let mut ctx = run_context.clone().into_tinyagents(config);
// Assemble the run's store registry: the tool-result artifact index (when
// present) and — behind the default-ON session dual-write flag — the
// session KV store, so the harness carries a handle to the same
@@ -582,11 +581,9 @@ pub(crate) async fn run_turn_via_tinyagents_shared(
// nested inside its parent's drive future — leaving it inline on the stack
// overflows when the parent + child drives compose. Boxing keeps only a
// pointer on the stack at each level.
- // The generic model and middleware APIs still read thread/route scopes.
- // Re-establish the values from the owned carrier here rather than relying
- // on task-local inheritance from the root. This keeps detached/nested
- // drives attached to the intended thread and route slot until the generic
- // APIs accept `OpenHumanRunContext` directly.
+ // The route/thread/cancellation scopes remain for legacy tool/model APIs
+ // outside the typed TinyAgents surface. Their values come from the explicit
+ // carrier, so detached and nested drives retain the intended identity.
let run_thread_id = run_context.thread_id.clone().unwrap_or_default();
let run_route_slot = run_context.resolved_route.clone();
let run_result = crate::agent::tinyagents::with_route_slot(run_route_slot, async move {
diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.md
index dca258d471..bb03fd94e5 100644
--- a/gitbooks/developing/architecture/agent-harness.md
+++ b/gitbooks/developing/architecture/agent-harness.md
@@ -493,11 +493,12 @@ sub-agent turn seam. Roots snapshot their currently scoped origin, progress,
dispatch state, thread, route slot, cancellation token, and workspace grant,
then pass an owned context to the runner; a recursive sub-agent forks it with
`child()`, preserving shared cancellation/policy handles while isolating route
-observation and usage accounting. The TinyAgents middleware registry is still
-specialized to `RunContext<()>`, so the seam currently maps its canonical
-cancellation and workspace values into that runtime context. Deleting the
-legacy scopes and using `RunContext<OpenHumanRunContext>` throughout remains a
-follow-up once that registry is generic.
+observation and usage accounting. The shared runner creates
+`RunContext<OpenHumanRunContext>` through `into_tinyagents`, and the OpenHuman
+assembly and middleware registry consume that typed context directly. Route,
+thread, and cancellation scopes still surround the drive only for legacy
+tool/model APIs outside the typed harness boundary; their values are seeded
+from the carrier rather than rediscovered by the middleware.
`OpenHumanHostBundleFactory` is the B1 host composition point. It constructs
the context, definition, security, model, memory, budget, progress, learning,
diff --git a/scripts/ci/agent-runtime-boundary-baseline.json b/scripts/ci/agent-runtime-boundary-baseline.json
index a4c501dbb3..f81753b0e1 100644
--- a/scripts/ci/agent-runtime-boundary-baseline.json
+++ b/scripts/ci/agent-runtime-boundary-baseline.json
@@ -9,7 +9,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/harness/graph.rs",
- "line": 117,
+ "line": 122,
"text": "let outcome = run_turn_via_tinyagents_shared(",
"occurrence": 1
},
@@ -23,7 +23,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/harness/session/turn/graph.rs",
- "line": 115,
+ "line": 120,
"text": "run_turn_via_tinyagents_shared(",
"occurrence": 1
},
@@ -37,7 +37,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs",
- "line": 262,
+ "line": 270,
"text": "let run_result = Box::pin(run_turn_via_tinyagents_shared(",
"occurrence": 1
},
@@ -58,7 +58,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs",
- "line": 110,
+ "line": 111,
"text": "pub(super) fn assemble_turn_harness(",
"occurrence": 1
},
@@ -79,7 +79,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 30,
+ "line": 29,
"text": "use crate::agent::tinyagents::harness_assembly::{assemble_turn_harness, AssembledTurnHarness};",
"occurrence": 1
},
@@ -93,7 +93,7 @@
{
"rule": "openhuman-runtime-bridge",
"path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 256,
+ "line": 259,
"text": "} = assemble_turn_harness(",
"occurrence": 1
},
@@ -1280,6 +1280,55 @@
"text": "let current_thread_id_ref = crate::agent::tinyagents::thread_context::current_thread_id();",
"occurrence": 1
},
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 89,
+ "text": "context.origin = crate::agent::turn_origin::current();",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 90,
+ "text": "context.progress = crate::agent::progress_sink::current_progress_sink();",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 91,
+ "text": "context.dispatch = crate::agent::harness::turn_dispatch_guard::current();",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 92,
+ "text": "context.thread_id = crate::agent::tinyagents::thread_context::current_thread_id();",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 93,
+ "text": "if let Some(slot) = crate::agent::tinyagents::current_route_slot() {",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 96,
+ "text": "if let Some(cancellation) = crate::agent::tinyagents::current_run_cancellation() {",
+ "occurrence": 1
+ },
+ {
+ "rule": "openhuman-task-local",
+ "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",
+ "line": 99,
+ "text": "context.workspace = crate::agent::turn_workspace::current()",
+ "occurrence": 1
+ },
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/agent/tinyagents/mod.rs",
@@ -1315,27 +1364,6 @@
"text": "super::record_resolved_provider_route(&self.provider, &self.model);",
"occurrence": 1
},
- {
- "rule": "openhuman-task-local",
- "path": "crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs",
- "line": 66,
- "text": "use crate::agent::harness::fork_context::{current_parent, ParentExecutionContext};",
- "occurrence": 1
- },
- {
- "rule": "openhuman-task-local",
- "path": "crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs",
- "line": 371,
- "text": "let parent = current_parent().ok_or_else(|| {",
- "occurrence": 1
- },
- {
- "rule": "openhuman-task-local",
- "path": "crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs",
- "line": 609,
- "text": "let thread = super::thread_context::current_thread_id().unwrap_or_default();",
- "occurrence": 1
- },
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/agent/tinyagents/resolved_route.rs",
@@ -1486,29 +1514,22 @@
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 476,
- "text": ".then(crate::agent::harness::turn_dispatch_guard::current)",
- "occurrence": 1
- },
- {
- "rule": "openhuman-task-local",
- "path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 509,
- "text": "}) = crate::agent::turn_origin::current()",
+ "line": 589,
+ "text": "let run_result = crate::agent::tinyagents::with_route_slot(run_route_slot, async move {",
"occurrence": 1
},
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 530,
- "text": ".or_else(|| match crate::agent::turn_origin::current() {",
+ "line": 590,
+ "text": "crate::agent::tinyagents::thread_context::with_thread_id(run_thread_id, async move {",
"occurrence": 1
},
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",
- "line": 585,
- "text": "let run_result = with_run_cancellation(cancellation.clone(), async {",
+ "line": 591,
+ "text": "with_run_cancellation(cancellation.clone(), async {",
"occurrence": 1
},
{
@@ -1829,14 +1850,14 @@
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",
- "line": 447,
- "text": "fn with_thread_id(mut request: ModelRequest) -> ModelRequest {",
+ "line": 448,
+ "text": "fn with_thread_id(request: ModelRequest) -> ModelRequest {",
"occurrence": 1
},
{
"rule": "openhuman-task-local",
"path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",
- "line": 448,
+ "line": 449,
"text": "let Some(thread_id) = thread_context::current_thread_id() else {",
"occurrence": 1
},
@@ -2242,7 +2263,7 @@
{
"rule": "tinyagents-moved-symbol-alias",
"path": "vendor/tinyagents/crates/tinyagents-harness/src/tool/mod.rs",
- "line": 97,
+ "line": 106,
"text": "pub struct ToolRegistry<State: Send + Sync, Ctx: Send + Sync> {",
"occurrence": 1
},
@@ -2480,7 +2501,7 @@
{
"rule": "tinyagents-tool-calling-facade",
"path": "vendor/tinyagents/crates/tinyagents-harness/src/agent_loop/run_loop.rs",
- "line": 976,
+ "line": 963,
"text": "use tinytools_agent::dialect::{DialectResponse, ToolDialect, XmlDialect};",
"occurrence": 1
},