Skip to main content
In this guide two agents, a drafter and a reviewer, share one team budget while each has a cap of its own. You will watch the drafter get stopped by its own cap while the reviewer keeps working, and then watch the team’s cap stop the reviewer even though it still has budget of its own. Before you start:
  • A Stigg server API key.
  • Governance enabled on your account.
  • A credit currency credits and a customer customer-acme with a credit grant much larger than the team budget, so the denials come from the budgets and not from an empty wallet. See Set up credits.
1

Create the entity types

Create two entity types in your environment, once:Do this in the Stigg app or through the API. See Setting up governance.
2

Create the team and its budget

Add the team-research entity to customer-acme with an assignment of 8 credits per month (P1M). See Setting up governance.In a real product, your customer’s admin usually sets the team budget through an interface you build.
3

Register the agents

Register each agent when it is created in your product. register() creates the entity, places it under the team, and writes its budget.
If admins will change agent budgets in the Stigg app, add apply: 'on-create' to the budget, so your code sets the initial budget and never overwrites theirs.
4

Wrap the client

  • The usage mapper reports to credits, the same currency the budgets are written against. Reporting raw token names here would not count against a credit budget.
  • ingestMode: 'sync' updates the budgets with each call, so the next check sees the spend.
  • Governance counts agent usage in whole units, so the amount of each call made as an agent is rounded up to a whole credit. A call of 400 tokens costs 1 credit.
5

Run the agents and handle denied access

agentId with attributionKey attributes each check and report to that agent, so Governance checks the agent, the team and the customer together.Expected output, abbreviated:
The drafter is stopped by its own cap and the reviewer is not affected. Later the reviewer is stopped by the team, with budget of its own still unspent, because the binding constraint is whichever level runs out first.
6

Respond to the right person

Use deniedBy and remedy to decide how to respond:Raise a budget by calling register() again with a new budget.limit, or in the Stigg app. Denials are never cached, so the next call goes through.
7

See it in Stigg

Open customer-acme in the Stigg app to see current usage and limits for the team and for each agent. To build the same view in your product, use the governance query API.

Going to production

  • Checks for an agent are never cached: each one asks Stigg, so a cap is enforced on the first call that exceeds it, even across several servers. See Caching and accuracy.
  • Decide what a call should do when a check cannot complete, with checkErrorAction. See Fallback strategy.
  • Start with budget: { entitlement, limit: null } to observe usage per agent before you enforce. See Observe-only rollout.