# `Omni.Context`
[🔗](https://github.com/aaronrussell/omni/blob/v2.0.0/lib/omni/context.ex#L1)

The context for a conversation with an LLM.

A context is what a text request sends: the second argument to
`Omni.generate_text/3` and `Omni.stream_text/3`. Both also take a string
or a list of messages and build the context for you.
[Contexts and messages](text-generation.md#contexts-and-messages) shows a
conversation carried over several turns.

```elixir
context = Omni.context(system: "You are a helpful assistant.", messages: [Omni.message("Hello!")])

{:ok, response} = Omni.generate_text("anthropic:claude-sonnet-5-5", context)
context = Omni.Context.push(context, response)
```

## Struct fields

- `:system` - the system prompt, or `nil`
- `:messages` - the conversation so far, as a list of `Omni.Message`
  structs, oldest first
- `:tools` - the `Omni.Tool` structs the model may use

# `t`

```elixir
@type t() :: %Omni.Context{
  messages: [Omni.Message.t()],
  system: String.t() | nil,
  tools: [Omni.Tool.t()]
}
```

System prompt, messages, and tools for a generation request.

# `new`

```elixir
@spec new(Enumerable.t() | String.t() | [Omni.Message.t()] | t()) :: t()
```

Creates a new context from a string, list of messages, keyword list, or map.

A string is a single user message. A list of messages is the message
history. A keyword list or map sets `:system`, `:messages` and `:tools`.
An existing context is returned as is.

# `push`

```elixir
@spec push(t(), Omni.Message.t() | [Omni.Message.t()] | Omni.Response.t()) :: t()
```

Appends messages to the context.

Takes one message, a list of messages, or an `Omni.Response`. A response
adds all of its `:messages`, which after a tool loop includes every tool
use and tool result along the way.

---

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