microsoft / microsoft/agent-framework

Feature: Cost/Token Circuit Breakers for Autonomous Loops

Open
#4,142 1 comment 0 reactions 1 assignee Claimed by @westey-m View on GitHub
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

**Is your feature request related to a problem? Please describe.**
As developers build autonomous loops (e.g., self-healing code agents), there is a significant risk of runaway costs due to infinite loops or hallucinations. Currently, limiting `max_iterations` is a proxy, but it doesn't account for token density or model cost variance.

**Describe the solution you'd like**
A first-class `CircuitBreaker` policy or middleware that can be attached to an Agent or Workflow.
- **Configurable Limits**: Set hard caps on `TotalTokens` or `EstimatedCost` per execution/session.
- **Stateful Tracking**: Accumulate usage across multiple turns in a workflow.
- **Fail-Safe**: If the limit is breached, the agent should halt immediately and return a safe error state (e.g., `CostLimitExceededException`), preventing further LLM calls.

**Describe alternatives you've considered**
- Manually tracking usage in every step of the workflow (error-prone and verbose).
- Setting strict `max_iterations` (imprecise; a single iteration with 128k context is different from 10 iterations of 1k).

**Additional context**
This feature is critical for "set and forget" autonomous scenarios in enterprise environments.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.