Skip to content

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

feat(tinyagents): add budget tracking and verify-before-finish checks

Steven Enamakelb82c08d1ef52
diff --git a/crates/openhuman-core/src/agent/tinyagents/budget.rs b/crates/openhuman-core/src/agent/tinyagents/budget.rs
index a711a539f6..68992cccd2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/budget.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/budget.rs
@@ -27,7 +27,7 @@ impl ModelBudget {
/// Apply the policy below retries and fallback selection.
pub(crate) fn wrap(&self, model: Arc<dyn ChatModel<()>>) -> Arc<dyn ChatModel<()>> {
Arc::new(tinyinference_llm::model::budget::BudgetedModel::new(
- Arc::new(super::budget_charge::GatewayChargeModel::new(model)),
+ Arc::new(tinyagents_harness::cost::GatewayChargeModel::new(model)),
self.ledger.clone(),
self.call,
))
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 9090c746fe..c7c27560d3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -35,6 +35,10 @@ use crate::agent::tinyagents::turn_policy::{
run_policy_for_provider, REPEATED_TOOL_FAILURE_THRESHOLD,
};
use crate::agent::tinyagents::verify_before_finish;
+use tinyagents_harness::middleware::{
+ install_unmet_deliverable, is_repeat_call_exempt, tool_sets_lookup, ResearchBudgetMiddleware,
+ ShellTurnBudget, TurnClockMiddleware, DIRECT_WEB_READ_LIMIT,
+};
use tinyagents_harness::store::InMemoryStore as ToolResultArtifactIndexStore;
use tinyinference_llm::model::ErrorSlotModel;
@@ -301,14 +305,22 @@ pub(super) fn assemble_turn_harness(
RepeatProgressMiddleware::new(
handle.clone(),
halt_summary.clone(),
- Arc::new(middleware::is_repeat_call_exempt),
+ Arc::new(is_repeat_call_exempt),
)
.with_read_only(Arc::new(move |name: &str| read_only_tools.contains(name)))
.with_cleared_placeholder(crate::agent::context::CLEARED_PLACEHOLDER),
)
});
// Time awareness (#6953); before the repeat guard so its notes land last.
- let shell_turn_budget = middleware::install_time_notes(&mut harness);
+ let turn_budget = harness
+ .policy()
+ .limits
+ .max_wall_clock_ms
+ .map(std::time::Duration::from_millis);
+ harness.push_middleware(Arc::new(TurnClockMiddleware::new(turn_budget)));
+ let shell_turn_budget =
+ ShellTurnBudget::with_max_timeout(turn_budget, tinytools_std::timeout::MAX_TIMEOUT_SECS);
+ harness.push_middleware(Arc::new(shell_turn_budget.notes()));
if let Some(mw) = &repeat_progress {
harness.push_middleware(mw.clone());
}
@@ -317,7 +329,7 @@ pub(super) fn assemble_turn_harness(
let repeated_failure = handle.as_ref().map(|handle| {
let (t, halt) = (REPEATED_TOOL_FAILURE_THRESHOLD, halt_summary.clone());
let mw = middleware::RepeatedToolFailureMiddleware::new(handle.clone(), t, halt);
- Arc::new(mw.with_tool_facts(middleware::tool_sets_lookup(tool_sets.clone())))
+ Arc::new(mw.with_tool_facts(tool_sets_lookup(tool_sets.clone())))
});
if let Some(mw) = &repeated_failure {
harness.push_middleware(mw.clone());
@@ -534,14 +546,22 @@ pub(super) fn assemble_turn_harness(
);
// The rungs above all *tell* the turn to produce its deliverable; this one
// looks, on the same scope as the requirements check.
- middleware::install_unmet_deliverable(&mut harness, is_subagent, agent_id);
+ if verify_before_finish::applies(is_subagent, agent_id) {
+ install_unmet_deliverable(&mut harness);
+ } else {
+ tracing::debug!(
+ is_subagent,
+ agent = agent_id.unwrap_or("<none>"),
+ "[unmet_deliverable] not installed for this turn"
+ );
+ }
// Direct web lookup is bounded. Once enough search/fetch results have
// returned, the web tools leave the request so the run works with what it
// has; a run with nothing but web tools answers instead. Sub-agent runs
// keep their own budgets and are not narrowed here.
if subagent_scope.is_none() {
- harness.push_middleware(Arc::new(middleware::ResearchBudgetMiddleware::new()));
+ harness.push_middleware(Arc::new(ResearchBudgetMiddleware::with_limit(DIRECT_WEB_READ_LIMIT)));
}
// SDK-owned tool-policy projection (issue #4249 / tinyagents-full-migration
// 01.1). Keep this narrow for now: enforce sandbox requirements declared by
diff --git a/crates/openhuman-core/src/agent/tinyagents/mod.rs b/crates/openhuman-core/src/agent/tinyagents/mod.rs
index 51a684df59..fc14194d1a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/mod.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/mod.rs
@@ -19,7 +19,6 @@
//! `ask_user_clarification` early-exit pause are all re-wired onto the
//! tinyagents harness.
-mod compaction_carry;
pub mod config;
mod context_wiring;
mod deadline_wind_down;
@@ -50,7 +49,6 @@ pub mod run_mode;
// multi-tenancy), so "bring your own summarizer" is the case this seam exists
// for rather than an exotic one.
pub mod budget;
-mod budget_charge;
pub mod payload_summarizer;
mod policy_denial;
pub(crate) mod reaper;
@@ -77,7 +75,7 @@ pub(crate) use crate::agent::message_convert::chat_message_to_message;
#[cfg(feature = "flows")]
pub(crate) use crate::agent::message_convert::ta_call_to_oh_call;
-pub(crate) use compaction_carry::{last_user_message, CompactionCarry};
+pub(crate) use tinyagents_harness::summarization::{last_user_message, CompactionCarry};
#[allow(unused_imports)] // Wired into the recall/retrieval facade in workstream 09.2.
pub(crate) use embeddings::ProviderEmbeddingModel;
pub(crate) use middleware::{
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
index 2aeace966e..da2f8de01a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
@@ -19,7 +19,7 @@ use tinyagents_harness::middleware::{
};
use tinyagents_harness::runtime::AgentHarness;
-use crate::agent::session_host::turn_checkpoint::wrap_harness_instruction;
+use tinyagents_harness::middleware::wrap_harness_instruction;
/// The only agent whose root turns are checked.
const ORCHESTRATOR_AGENT_ID: &str = "orchestrator";
@@ -84,7 +84,7 @@ pub(super) fn applies(is_subagent: bool, agent_definition_id: Option<&str>) -> b
/// Whether the turn's activity makes it a multi-step task worth checking.
pub(super) fn should_check(activity: &FinishActivity) -> bool {
- activity.tool_rounds >= MIN_TOOL_ROUNDS || activity.called(TODO_TOOL)
+ FinishActivity::rounds_or_called(MIN_TOOL_ROUNDS, TODO_TOOL)(activity)
}
/// The check, framed as harness text rather than a user message.