Skip to content

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

feat(agent): add budget notice thresholds to harness context ladder

Steven Enamakelcfc8a009692b
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 aa14a3682d..5205fe6b0c 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
@@ -22,6 +22,10 @@ use crate::agent::tinyagents::model::TurnChatModel;
use crate::agent::tinyagents::turn_outcome::ToolOutcomeSink;
/// Store `ToolResultArtifactIndexStore` is registered under on the run context.
+/// Fractions of a capped turn's model-call budget at which the model is told
+/// how many calls are left (#6958; `FinalCallWrapUpMiddleware::with_budget_notice`).
+const BUDGET_NOTICE_THRESHOLDS: [f64; 2] = [0.5, 0.8];
+
const ARTIFACT_INDEX_STORE: &str =
crate::agent::harness::tool_result_artifacts::TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE;
@@ -197,7 +201,11 @@ pub(super) fn install_context_ladder(
// file tool; `apply_patch` has a create mode). `shell` is left out
// on purpose: it can equally run a crawler.
.with_deliverable_tools(["file_write", "apply_patch"])
- .with_cleared_placeholder(crate::agent::context::CLEARED_PLACEHOLDER),
+ .with_cleared_placeholder(crate::agent::context::CLEARED_PLACEHOLDER)
+ // #6958: the model first heard about its budget on the
+ // penultimate call, too late for a multi-file change. Say how many
+ // calls are left at half and at 80% of the budget.
+ .with_budget_notice(BUDGET_NOTICE_THRESHOLDS),
)
});
let wrap_up_fired = wrap_up_mw.clone();
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index d63341283e..6954814737 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -1775,7 +1775,10 @@ async fn inference_agent_chat_reports_hit_cap_inner() {
let reply = result["result"]
.as_str()
.unwrap_or_else(|| panic!("the reply stays a string in `result`: {result}"));
- assert!(!reply.trim().is_empty(), "a capped turn still answers: {result}");
+ assert!(
+ !reply.trim().is_empty(),
+ "a capped turn still answers: {result}"
+ );
assert_eq!(
result["checkpoint"],
json!(reply),