> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent orchestration

> Check budgets between the steps of an agent run, and meter every model call inside it, in frameworks such as LangGraph.

An agent framework runs an agent as a series of steps: plan, call a model, call a tool, and so on. Stigg fits into a run in two places:

* **Every model call** inside the run goes through a [wrapped client](/documentation/ai-agents/llm-wrappers/overview), so it is checked and metered like any other call.
* **Between steps**, you check whether the agent still has budget for the next step, and decide what to do if it does not. Running out then becomes a normal path in the run, such as offering the customer more credits or asking an admin to raise a budget, instead of an error halfway through.

## Wrap the model client the framework uses

Create the model client with `stigg.wrap()`, and pass the wrapped client to the framework wherever it accepts one. Every model call the framework makes is then checked and metered, with no other changes. See [LLM and gateway wrappers](/documentation/ai-agents/llm-wrappers/overview).

## Check the budget between steps

Add a step that checks the budget before an expensive part of the run, and route on the result. In LangGraph, put the check in a node and route with a conditional edge:

```typescript theme={null}
async function creditGate(state) {
  const decision = await stigg.check(
    {
      customerId: state.customerId,
      entitlement: { currencyId: 'credits' },
      agentId: state.agentId,
      attributionKey: 'agentId',
    },
    5, // the credits the next step is expected to cost
  );
  return { hasAccess: decision.hasAccess, denial: decision.message };
}

graph
  .addNode('creditGate', creditGate)
  .addNode('offerCredits', offerCredits)
  .addConditionalEdges('creditGate', (s) => (s.hasAccess ? 'generate' : 'offerCredits'));
```

The check asks for the credits the next step is expected to cost, so a run does not start a step it cannot finish. See [Requested usage](/documentation/ai-agents/llm-wrappers/gating#requested-usage).

## Related

* [Agent governance](/documentation/ai-agents/agent-governance): give each agent its own budget.
* [Gating actions that are not model calls](/documentation/ai-agents/llm-wrappers/gating#gating-actions-that-are-not-model-calls): check and report tool calls.


## Related topics

- [Gating calls](/documentation/ai-agents/llm-wrappers/gating.md)
- [Welcome to Stigg](/documentation/getting-started/welcome-to-stigg.md)
- [Agent governance](/documentation/ai-agents/agent-governance.md)
- [Agent SDK](/api-and-sdks/references/sdk/backend/rest/agent-sdk.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.