# `LlmCore.Agent.Components.BudgetGuard`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/agent/components/budget_guard.ex#L1)

Enforces iteration budget limits.

If the current iteration count has reached `max_iterations - 1` (i.e.
this is the last allowed iteration), halts the pipeline with an error
decision. Future extensions may add token budget and cost budget
enforcement.

Skips processing when the decision is already `:done` (no tool calls)
or when the pipeline is in error status.

Analogous to budget guard clauses in step-oriented loop executors:
that check recursion depth before proceeding.

# `call`

```elixir
@spec call(
  LlmCore.Agent.Context.t(),
  keyword()
) :: LlmCore.Agent.Context.t()
```

Checks iteration count against `max_iterations`.

## Parameters

  * `ctx` — `%Context{}` with `iteration` and `max_iterations`
  * `opts` — ALF stage options (unused)

## Returns

  * Unchanged context when within budget
  * Context with `status: :error` and `decision: {:error, :budget_exceeded}`
    when the iteration limit is reached

---

*Consult [api-reference.md](api-reference.md) for complete listing*
