Skip to content

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

fix(tinyagents): preserve resolved route and delegate agent lifecycle hooks

Steven Enamakel467c02d06be7
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 2493d8018f..c069aed6b8 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -197,7 +197,9 @@ fn sync_owner_snapshot(
host.cached_input_tokens = snapshot.cached_input_tokens;
host.last_call_input_tokens = snapshot.last_call_input_tokens;
host.last_call_output_tokens = snapshot.last_call_output_tokens;
- host.resolved_route = snapshot.resolved_route;
+ if snapshot.resolved_route.is_some() {
+ host.resolved_route = snapshot.resolved_route;
+ }
host.model_calls = snapshot.model_calls;
host.tool_outcomes = snapshot.tool_outcomes;
}
@@ -269,9 +271,6 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
.as_ref()
.filter(|_| !response.served_from_cache)
{
- guard.input_tokens += usage.input_tokens;
- guard.output_tokens += usage.output_tokens;
- guard.cached_input_tokens += usage.cache_read_tokens;
let host_usage =
crate::inference::provider::model::usage_info_from_response(response)
.unwrap_or(
@@ -311,6 +310,27 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
}
Ok(())
}
+
+ async fn after_agent(
+ &self,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
+ state: &(),
+ run: &mut tinyagents_harness::middleware::AgentRun,
+ ) -> TaResult<()> {
+ self.owner.after_agent(ctx, state, run).await
+ }
+
+ async fn on_error(
+ &self,
+ ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
+ error: &tinyagents_harness::error::TinyAgentsError,
+ ) -> TaResult<()> {
+ <tinyagents_harness::middleware::library::TranscriptSnapshotMiddleware as Middleware<
+ (),
+ crate::agent::tinyagents::host::OpenHumanRunContext,
+ >>::on_error(&self.owner, ctx, error)
+ .await
+ }
}
impl TurnContextMiddleware {