Agent rate limit strategy

From PranavNagrecha/AwesomeSalesforceSkills · View interactive version

Agent rate limit strategy is an AI agent skill from the GitHub repository PranavNagrecha/AwesomeSalesforceSkills. 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 Sales

How to use this skill

Skill file

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.

Recommended Workflow

  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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.