SfSkills Domains Docs GitHub

Home / agentforce / agent-rate-limit-strategy

agent-rate-limit-strategy

Control LLM spend and Apex governor exposure for high-traffic Agentforce agents via per-user token budgets and graceful fallback when the budget is exhausted. NOT for reducing tokens per conversation in the first place — use agentforce/agentforce-cost-optimization. NOT for API rate-limiting of Salesforce REST endpoints — use integration/api-governance-and-rate-limits.

Open the skill folder on GitHub


Agent Rate Limit Strategy

Agentforce exposes internal LLM quotas indirectly — you hit them as platform 503s with no forward signal. This skill builds a client-side budget gate in front of the agent: per-user token ledger, CMDT-driven thresholds, and a graceful fallback when the budget is exhausted.

  1. Define budget: tokens/user/hour, tokens/tenant/day. Persist in Agent_Rate_Limit__mdt per-persona.
  2. In the channel entry point (LWC wrapper or Connect API), call a BudgetService.checkAndConsume(userId, estTokens) before dispatching to the agent.
  3. Log consumption via Platform Event Agent_Token_Consumed__e — the subscriber rolls into a User_Token_Ledger__c aggregate.
  4. When the budget is exhausted, render the fallback UX (human handoff / retry-after message) instead of calling the agent.
  5. Dashboard: p50/p95 consumption per persona, budget exhaustion count, tokens/turn — page SRE when exhaustion >1%.

Key Considerations

Worked Examples (see references/examples.md)

Common Gotchas (see references/gotchas.md)

Top LLM Anti-Patterns (full list in references/llm-anti-patterns.md)

Official Sources Used

Package files