Skip to content

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

agent: drop the turn's deliverable state at the end of the run, and log counts

killbill843f266b2ee1
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
index 94726e6bf0..4019b2ffbd 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
@@ -386,8 +386,8 @@ impl<C: Send + Sync> Middleware<(), C> for UnmetDeliverableMiddleware {
if !missing.is_empty() {
tracing::debug!(
band,
- missing = ?missing,
- "[unmet_deliverable] half-time note: requested path still absent"
+ missing = missing.len(),
+ "[unmet_deliverable] half-time note: requested paths still absent"
);
append_note(result, &half_time_note(&missing, &clock));
}
@@ -432,6 +432,20 @@ impl<C: Send + Sync> Middleware<(), C> for UnmetDeliverableMiddleware {
Ok(())
}
+ /// The turn is over: drop its state, whether it ended with an answer or an
+ /// error, so nothing is kept for a run that will not be seen again.
+ async fn after_agent(
+ &self,
+ ctx: &mut RunContext<C>,
+ _state: &(),
+ _run: &mut tinyagents_harness::middleware::AgentRun,
+ ) -> Result<()> {
+ if let Ok(mut runs) = self.runs.lock() {
+ runs.remove(&ctx.instance_id());
+ }
+ Ok(())
+ }
+
async fn on_error(&self, ctx: &mut RunContext<C>, _error: &TinyAgentsError) -> Result<()> {
if let Ok(mut runs) = self.runs.lock() {
runs.remove(&ctx.instance_id());
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
index da0b327c71..b79377d50d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
@@ -448,3 +448,45 @@ async fn a_late_first_observation_skips_the_half_time_note() {
"no half-time note after the late one"
);
}
+
+/// The turn's state is dropped when the run ends, so a long-lived harness
+/// keeps nothing for runs it will not see again.
+#[tokio::test]
+async fn the_runs_state_is_dropped_when_the_turn_ends() {
+ let missing = std::env::temp_dir().join(format!("oh-unmet-drop-{}.json", std::process::id()));
+ let _ = std::fs::remove_file(&missing);
+ let middleware = Arc::new(UnmetDeliverableMiddleware::new(None));
+ let mut harness: AgentHarness<()> = AgentHarness::new();
+ harness.register_model(
+ "mock",
+ Arc::new(ScriptedModel::new(vec![
+ tool_round("c0", "writer"),
+ tinyagents_harness::tinyinference_llm::model::ModelResponse::assistant(
+ "first answer".to_string(),
+ ),
+ tinyagents_harness::tinyinference_llm::model::ModelResponse::assistant(
+ "second answer".to_string(),
+ ),
+ ])),
+ );
+ harness.register_tool(Arc::new(FakeTool::returning("writer", "ok")));
+ harness.with_policy(RunPolicy {
+ limits: RunLimits::default()
+ .with_max_model_calls(20)
+ .with_max_tool_calls(20),
+ ..RunPolicy::default()
+ });
+ harness.push_middleware(Arc::clone(&middleware) as Arc<dyn Middleware<(), ()>>);
+ let run = harness
+ .invoke_default(
+ &(),
+ vec![Message::user(format!("write {}", missing.display()))],
+ )
+ .await
+ .expect("run succeeds");
+ assert_eq!(run.text().as_deref(), Some("second answer"));
+ assert!(
+ middleware.runs.lock().expect("lock").is_empty(),
+ "the finished run leaves no state behind"
+ );
+}