# `AgentCall.Context`
[🔗](https://github.com/gilbertwong96/agent_call/blob/main/lib/agent_call/context.ex#L1)

The caller-owned context policy types.

A `context:` option is a 2-arity function called before every model request,
after the step-budget check. It receives the current messages and an `info`
map, and returns a `decision/0`.

The policy owns the decision the library cannot make: token counting, the
model window, what to keep, whether to summarize, and whether to stop. The
library does none of it. A policy that raises, throws or exits, or returns
anything but a decision, is a configuration error, not a crash of the run.

Tool-call and tool-result pairing is the policy's responsibility too: the
loop sends the returned list as-is, and `LlmCall.complete/3` reports a broken
pairing as an `:llm` error.

# `decision`

```elixir
@type decision() ::
  {:cont, [LlmCall.Message.t()]}
  | {:cont, [LlmCall.Message.t()], [LlmCall.Request.tool_entry()] | nil}
  | {:stop, term()}
```

Replace the messages sent to the model, or stop before the request.

A policy may also replace the tool entries for this turn and every later one.
The entries are the same shape as `LlmCall.Request.tools`; an empty list is
legal and means the model is offered no tools. `nil` leaves the run's current
set alone.

# `info`

```elixir
@type info() :: %{
  step: pos_integer(),
  max_steps: pos_integer(),
  usage: LlmCall.Usage.t() | nil,
  request: LlmCall.Request.t()
}
```

What a policy knows before a request.

`usage` is the last response's own usage, `nil` on the first request and
`pending.last_usage` after a resume. `request.messages` is the first argument.

---

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