# `Spectre.Context`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/types/context.ex#L1)

Per-turn runtime context.

Context is passed between runtime, router, prompt rendering, handlers, and
action execution. It keeps dependencies explicit without pushing the entire
host application into each function signature.

# `t`

```elixir
@type t() :: %Spectre.Context{
  agent: module(),
  assigns: map(),
  errors: [term()],
  halted?: boolean(),
  input: Spectre.Input.t(),
  memory: term(),
  opts: keyword(),
  route: Spectre.Route.t() | nil,
  state: Spectre.State.t(),
  traces: [term()]
}
```

# `halt`

```elixir
@spec halt(t()) :: t()
```

Marks the context as halted.

    ctx = Spectre.Context.halt(ctx)

# `lifecycle_run_id`

```elixir
@spec lifecycle_run_id(t() | map()) :: String.t() | nil
```

Returns the Run that owns lifecycle values staged through this context.

Subject-scoped `Spectre.Instance` calls opt into per-Run lifecycle
ownership. Stateless Runtime calls and conversation Sessions return `nil`
and keep the legacy single-lifecycle contract. Extension-owned Effect
builders should bind this value to every staged Effect and use the scoped
`Spectre.State` lifecycle queries with the same value.

# `put_error`

```elixir
@spec put_error(t(), term()) :: t()
```

Adds an error entry to the context.

    ctx = Spectre.Context.put_error(ctx, {:adapter_failed, reason})

# `put_trace`

```elixir
@spec put_trace(t(), term()) :: t()
```

Adds a trace entry to the context.

    ctx = Spectre.Context.put_trace(ctx, {:router, :accepted})

---

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