Budgets and Limits
Per-agent request, tool-call, and token budgets, size limits, adapter deadlines, circuit breakers, and behavioral incidents.
Policy decides whether an action may run. Budgets and limits decide how much an authenticated agent can do in a period, and stop a looping or compromised agent before it reaches a tool. None of these controls consults a model.
Budgets
After the signature and nonce succeed, every authorize request charges three Redis counters in one atomic script. Each counter lives for a 60-second window that starts with its first increment.
| Budget | Key | Limit per 60 s |
|---|---|---|
| Requests | agentshield:v1:rate:<agent> | 60 per agent |
| Tool calls | agentshield:v1:tool:<agent>:<tool> | 30 per agent and tool |
| Tokens | agentshield:v1:tokens:<agent> | 100,000 per agent |
A token here is an estimate derived from the raw body: four bytes count as one token, rounded up, with a minimum of one. It is intentionally not a model tokenizer, so the budget does not depend on a component that is not allowed to authorize.
Crossing any limit returns:
HTTP 429
{ "error": { "code": "rate_limited", "message": "tool call limit exceeded", "request_id": "…" } }The message identifies the budget: request rate limit exceeded, tool call limit exceeded, or token budget exceeded. A rate-limited request records no decision and is not counted as a deny, because policy did not decide anything. If Redis is unavailable, the gateway returns 500 rather than skipping the check.
Budgets apply to authorize
Budgets are charged on authorize. Execute is bound to an existing decision and protected by idempotency and the circuit instead.
Size limits
| Limit | Value | Behavior |
|---|---|---|
| Gateway request body | 1 MiB (configurable lower with GATEWAY_MAX_BODY_BYTES, never higher) | 400 validation_failed |
| Control plane JSON body | 256 KiB | 413 |
resource | 512 characters | 400 |
http.request JSON body argument | 256 KiB | 400 |
http.request response | 256 KiB default, 4 MiB maximum | Truncated with truncated: true |
| Intelligence engine request | 1 MiB | Refused before reading |
Deadlines
Each adapter run has a deadline. The gateway default is 2 seconds. http.request uses its configured timeout: 5 seconds by default, up to 30. A deadline marks the execution failed with kind timeout. It does not allow a retry of the same decision.
Circuit breaker
Repeated adapter failures open a circuit per organization and tool:
- Five failures inside a 60-second window open the circuit for 30 seconds.
- While open, execute returns
503 circuit_openand the adapter is not called. The claim is rolled back, so the decision and any approval remain usable after the circuit closes. - A successful run resets the failure count.
- Validation rejections and unknown tools (
501) do not count as failures. A missing adapter is not a failing dependency.
Behavioral incidents
Two deterministic rules open security_incidents rows in the same transaction as the decision. They never change the outcome.
| Rule | Trigger | Severity |
|---|---|---|
oversized_arguments | Canonical arguments larger than 4,096 bytes | low |
deny_burst | The fifth deny for an agent within ten minutes | medium |
A deny_burst incident opens once per run of denies, not on every subsequent deny. Owners, admins, and auditors list incidents with GET /api/v1/incidents. See Incident investigation.
Tuning
The budget values, the circuit thresholds, and the incident rules are compile-time constants in runtime/gateway/internal/limits/limits.go. They are deliberately not runtime configuration, so a misconfigured environment variable cannot silently disable them. To change them, change the constants and their tests together.
Implementation references
Was this page helpful?
Tool Execution Lifecycle
How an authorized decision becomes exactly one adapter run. Claiming, argument binding, deadlines, completion, failure, and repeat calls.
Human Approvals
How require_approval holds a call for a person, how approvals are bound to the exact request, and how they are consumed exactly once.