Skip to content

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

fix(middleware/research_budget): clarify budget exhaustion behaviour

Steven Enamakelc8b767292e29
diff --git a/crates/openhuman-core/src/agent/tinyagents/README.md b/crates/openhuman-core/src/agent/tinyagents/README.md
index 90a7cffdf6..9521cb7eee 100644
--- a/crates/openhuman-core/src/agent/tinyagents/README.md
+++ b/crates/openhuman-core/src/agent/tinyagents/README.md
@@ -33,7 +33,7 @@ The adapter seam between OpenHuman and the vendored [`tinyagents`](../../../../.
| `journal.rs` | `TurnJournal` and `attach_turn_journal`: a crate `StoreEventJournal` over a JSONL append store plus a `HarnessStatusStore` writer (`FileStatusStore`, `mint_run_id` and the env-secret redaction seed are upstream in `tinyagents_harness::observability`) under `{workspace}/tinyagents_store`. Attached alongside the live `observability` bridge as an independent `EventSink` subscriber, wrapped in `RedactingSink`; best-effort and non-fatal. |
| `reaper.rs` | `reap_orphaned_runs`: workspace adapter over the upstream sweep (`tinyagents_harness::observability::reap_orphaned_runs`) that marks non-terminal runs `Cancelled` in the durable status store. The only writer over the status seam that `replay/` reads. |
| `middleware.rs` + `middleware/` | The named OpenHuman middleware stack. `turn_context.rs`: `TurnContextMiddleware` (bundles config and installs the enabled hooks), `TranscriptSnapshotMiddleware`/`TranscriptSnapshotSink`. `tool_output.rs`: `ToolOutputMiddleware` (per-result byte cap and optional payload summarizer). `approval.rs`: `ApprovalSecurityMiddleware`. `cli_rpc_only.rs`: `CliRpcOnlyMiddleware`. `tool_policy.rs`: the `ToolPolicyMiddleware` struct and impl (records blocks into `crate::tools::registry::denials`). `tool_outcome_capture.rs`: `ToolOutcomeCaptureMiddleware`. `embedder_hooks.rs`: `EmbedderToolHooksMiddleware`. `memory_protocol.rs`: the OpenHuman tool vocabulary (`memory_protocol_spec()`) for the upstream `MemoryProtocolMiddleware`. `cost_budget.rs`: `CostBudgetMiddleware`. `repeated_failure.rs`: `RepeatedToolFailureMiddleware` (class-specific recovery budgets before the next model call; equivalent failures share a stable resource scope even when arguments differ). `loop_guards.rs`: `TerminalInferenceFailure`. `credential_scrub.rs`: the browser confirmation-token exemption and `credential_scrub_middleware()`, which wires the harness `CredentialScrubMiddleware`. The generic context-ladder and loop-guard middleware live in `tinyagents-harness` (`middleware::library`) and are installed by `harness_context_ladder.rs` / `harness_assembly.rs`: `ImageAwareMessageTrimMiddleware`, `FinalCallWrapUpMiddleware` (host passes the `file_write`/`apply_patch` deliverable tools and `CLEARED_PLACEHOLDER`), `ArtifactIndexTocMiddleware` (issue #6014), `RepeatProgressMiddleware`/`RepeatEvictionObserver` (host passes the `wait_subagent` exemption), and `ArgRecoveryMiddleware`. |
-| `middleware/research_budget.rs` | Forces a top-level direct web research turn to answer after eight completed search or fetch calls. |
+| `middleware/research_budget.rs` | Withdraws the web tools from a top-level turn after eight successful search or fetch calls (forcing an answer only when no other tool remains), and notes once when consecutive web calls fail. |
| `model.rs` | Helpers and wrappers over native crate `ChatModel` values: message/response translation, usage merging, stream-delta forwarding, `MaxTokensModel`, `ProfileOverrideModel`. |
| `tools.rs` | `CanonicalSharedToolAdapter`: resolves an OpenHuman shared tool registry and forwards the canonical `tinytools::Tool` contract; `EarlyExitHook` pauses successful `ask_user_clarification`-style calls. |
| `routes.rs` | `WORKLOAD_ROUTE_TIERS` (the tier inventory projected into the model registry), `RequiredCapabilitiesMiddleware`, `FallbackObserverMiddleware`, `UsageCarryMiddleware`, and the per-model fallback policy. |
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 9434ec42b3..5d888f5ff8 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -586,10 +586,10 @@ pub(super) fn assemble_turn_harness(
&tool_outcome_sink,
);
- // Direct web lookup is for a bounded answer. Once enough search/fetch
- // results have returned, spend the next model call on synthesis rather
- // than another variation of the same query. Sub-agent runs keep their own
- // budgets and are not narrowed here.
+ // 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()));
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/research_budget.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/research_budget.rs
index f320ad5ef3..a563b3401e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/research_budget.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/research_budget.rs
@@ -23,9 +23,10 @@ use crate::agent::tinyagents::host::OpenHumanRunContext;
pub(super) const DIRECT_WEB_READ_LIMIT: usize = 8;
/// The instruction appended when the budget is spent and no non-web tool
-/// remains, so every tool is withdrawn. It says outright that tools are gone and a call will not run:
-/// told only to "answer", a native model with a transcript full of tool calls
-/// and no tool channel writes its next call as plain-text markup (DeepSeek V4's
+/// remains, so every tool is withdrawn. It says outright that tools are gone
+/// and a call will not run: told only to "answer", a native model with a
+/// transcript full of tool calls and no tool channel writes its next call as
+/// plain-text markup (DeepSeek V4's
/// `<|DSML|invoke …>`), which then stood as the turn's answer. Replaying a
/// bench request that hit this budget, the old wording leaked a call 6 times in
/// 8 and this wording 0 times in 8. The harness also withholds and re-prompts
@@ -40,7 +41,7 @@ pub(crate) const WEB_BUDGET_EXHAUSTED_INSTRUCTION: &str = "The direct web resear
const BLOCKED_AFTER_FAILURES: usize = 2;
/// The one-time note sent after [`BLOCKED_AFTER_FAILURES`] failed web calls in a
-/// row (403/429 walls, an offline sandbox).
+/// row (a blocked network, an offline sandbox).
pub(crate) const WEB_BLOCKED_NOTE: &str = "Web access looks blocked: the last web calls failed. Do not keep retrying web tools; continue the task with your other tools and the information already available.";
/// The direct web-read tools this budget governs: the `web_search` family
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_research_budget_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_research_budget_tests.rs
index a52b89f208..13a2a0f0ef 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_research_budget_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_research_budget_tests.rs
@@ -156,8 +156,8 @@ async fn a_spent_web_budget_releases_a_choice_pinned_to_a_web_tool() {
);
}
-/// #6959: a refused fetch (403, 429, an offline sandbox) read nothing, so it
-/// must not spend the budget.
+/// #6959: a failed web call (a blocked network, an offline sandbox) read
+/// nothing, so it must not spend the budget.
#[tokio::test]
async fn failed_web_reads_do_not_spend_the_budget() {
let mw = ResearchBudgetMiddleware::new();