martin-loop icon indicating copy to clipboard operation
martin-loop copied to clipboard

Soft time budget on LoopBudget (wall-clock limit for agent runs)

Open kuehnberger opened this issue 1 month ago • 0 comments

Gap

LoopBudget supports maxUsd and maxIterations as hard limits. The contract has maxWallClockMs, but it is only enforced as a hard abort — the child agent is killed when time expires. There is no soft time budget that signals "you are running long, wrap up" before the hard limit hits.

Use case

We frequently instruct agents with time-bounded tasks: "spend 20-30 minutes, run at least 2 iterations, up to 5 subagents, deepen the subject on re-run." Today:

  • maxWallClockMs: 1800000 kills the agent at 30 minutes with no warning and no receipts written.
  • There is no way to say "at 20 minutes start wrapping up" or "this iteration should take ~5 minutes".
  • extendSwarmBudgetLease handles fair-share across parallel agents, but has no time dimension — only budget units.

Proposal

Add softTimeLimitMs (and optionally expectedIterationMs) alongside the hard maxWallClockMs:

  • When softTimeLimitMs is reached, emit a soft_limit_warning event (or set a flag the agent loop can check) so the agent can finish the current iteration, write receipts and stop cleanly.
  • expectedIterationMs would be informational only — warn on drift, never abort.
  • Mirrors the existing softLimitUsd / softLimitTokens pattern.

Why this matters for us

Our governance model is time-first, not cost-first: we budget in wall-clock minutes and CPU/RAM rather than USD (most of our model capacity is small- to zero-cost tiers, so USD caps rarely bind). The min(child, parentRemaining) cap in live-runtime.ts:775 is exactly the invariant we need — a soft time budget would complement it by letting the agent exit gracefully instead of being killed mid-tool-call.

Code references

  • packages/contracts/src/swarm.ts — LoopBudget type, maxWallClockMs
  • packages/core/src/swarm/live-runtime.ts:775 — hard cap
  • packages/core/src/swarm/scheduler.ts — extendSwarmBudgetLease

Our context

We are evaluating MartinLoop as a governance layer for a multi-profile Hermes Agent fleet routed through our own OpenAI-compatible router. We would be glad to contribute tests or a prototype if there is interest.

kuehnberger avatar Oct 11 '26 01:10 kuehnberger