Summary
Add cost-based and time-based interruption controls for both the main agent and subagents. This allows users to set maximum cost thresholds or execution time limits and automatically interrupt agents when exceeded, preventing unexpected API bill spikes or runaway processes.
Current Behavior
- dreb displays real-time cost in the footer, but there's no automatic mechanism to stop execution based on cost
- Subagents have no timeout or cost limits
- Users must manually monitor and interrupt expensive or long-running operations
- There's no way to set per-session or per-agent cost/time budgets
Proposed Behavior
-
Global settings in ~/.dreb/agent/settings.json or .dreb/settings.json:
maxCostPerSession — stop the session if total API cost exceeds this threshold (e.g., "$5.00")
maxAgentDurationSeconds — maximum execution time for any single agent run before auto-interrupt
- Optional:
costWarningThreshold — show prominent warning when approaching the limit (e.g., at 80% of max)
-
Per-subagent limits in tool calls:
- Allow
maxCost and maxDuration parameters to subagent invocations
- Inherits from global settings if not specified
-
Behavior on interrupt:
- Clear message explaining which limit was hit and why
- Graceful abort with partial results preserved
- Session continues (user can take action)
- Cost/timer shown in footer with visual indicator
Acceptance Criteria
Technical Notes
Implementation hints:
- Track cumulative cost from all tool calls and LLM responses
- Use
setTimeout() or process timers for agent duration limits
- Cost calculation: use provider API response metadata (tokens) to estimate or track actual billed amounts
- Consider subagent processes spawned by
subagent tool — may need inter-process communication for time tracking
- Provide a hook for extensions to customize interrupt behavior
Relevant files:
packages/coding-agent/src/settings.ts — add new settings schema
packages/coding-agent/src/agent-loop.ts (or equivalent) — cost/time tracking logic
packages/coding-agent/docs/settings.md — documentation
packages/agent/src/subagent.ts (or equivalent) — pass limits to spawned agents
Related:
- Session cost display (footer) — already implemented, can be extended
- Retry logic (
retry setting) — separate concern but could interact with time limits
Labels
feature — new feature request
enhancement — improves existing behavior
agents — affects agent loop or subagent system
settings — configuration-related
Summary
Add cost-based and time-based interruption controls for both the main agent and subagents. This allows users to set maximum cost thresholds or execution time limits and automatically interrupt agents when exceeded, preventing unexpected API bill spikes or runaway processes.
Current Behavior
Proposed Behavior
Global settings in
~/.dreb/agent/settings.jsonor.dreb/settings.json:maxCostPerSession— stop the session if total API cost exceeds this threshold (e.g.,"$5.00")maxAgentDurationSeconds— maximum execution time for any single agent run before auto-interruptcostWarningThreshold— show prominent warning when approaching the limit (e.g., at 80% of max)Per-subagent limits in tool calls:
maxCostandmaxDurationparameters to subagent invocationsBehavior on interrupt:
Acceptance Criteria
maxCostPerSession,maxAgentDurationSeconds, and optionalcostWarningThresholdmaxCostandmaxDurationparamsTechnical Notes
Implementation hints:
setTimeout()or process timers for agent duration limitssubagenttool — may need inter-process communication for time trackingRelevant files:
packages/coding-agent/src/settings.ts— add new settings schemapackages/coding-agent/src/agent-loop.ts(or equivalent) — cost/time tracking logicpackages/coding-agent/docs/settings.md— documentationpackages/agent/src/subagent.ts(or equivalent) — pass limits to spawned agentsRelated:
retrysetting) — separate concern but could interact with time limitsLabels
feature— new feature requestenhancement— improves existing behavioragents— affects agent loop or subagent systemsettings— configuration-related