Skip to Content
AgentShield
Fundamentals

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.

BudgetKeyLimit per 60 s
Requestsagentshield:v1:rate:<agent>60 per agent
Tool callsagentshield:v1:tool:<agent>:<tool>30 per agent and tool
Tokensagentshield: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

LimitValueBehavior
Gateway request body1 MiB (configurable lower with GATEWAY_MAX_BODY_BYTES, never higher)400 validation_failed
Control plane JSON body256 KiB413
resource512 characters400
http.request JSON body argument256 KiB400
http.request response256 KiB default, 4 MiB maximumTruncated with truncated: true
Intelligence engine request1 MiBRefused 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_open and 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.

RuleTriggerSeverity
oversized_argumentsCanonical arguments larger than 4,096 byteslow
deny_burstThe fifth deny for an agent within ten minutesmedium

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.

Was this page helpful?

On this page