# `Jido.Composer.Context`
[🔗](https://github.com/lostbean/jido_composer/blob/main/lib/jido/composer/context.ex#L1)

Layered context struct separating ambient (read-only), working (mutable),
and fork functions (applied at agent boundaries).

Nodes never receive this struct directly — they get a flat map from
`to_flat_map/1`, with ambient data under the reserved `ambient_key/0` key.
Use `to_clean_map/1` when the result must be serializable (JSON, OTel, or
returned to callers) — it returns only the working data without the tuple key.

Note: When the same scope key is used in multiple `apply_result/3` calls
(e.g., an orchestrator calling the same tool twice), scalar values within
that scope are overwritten via deep merge. Tool authors who need to
accumulate results across invocations should read their prior output from
context and append explicitly.

# `fork_fn`

```elixir
@type fork_fn() :: {module(), atom(), list()}
```

# `t`

```elixir
@type t() :: %Jido.Composer.Context{
  ambient: map(),
  fork_fns: %{required(atom()) =&gt; fork_fn()},
  working: map()
}
```

# `ambient_key`

```elixir
@spec ambient_key() :: {module(), :ambient}
```

Returns the key used to carry ambient data in flat context maps.

# `apply_result`

```elixir
@spec apply_result(t(), atom(), map()) :: t()
```

# `fork_for_child`

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

# `from_serializable`

```elixir
@spec from_serializable(map()) :: t()
```

# `get_ambient`

```elixir
@spec get_ambient(t(), atom()) :: term()
```

# `new`

```elixir
@spec new(keyword()) :: t()
```

# `to_clean_map`

```elixir
@spec to_clean_map(t()) :: map()
```

Returns working data as a plain map without the internal ambient tuple key.

Use this instead of `to_flat_map/1` when the result will be returned to
callers, serialized to JSON, or used with OTel attributes — any context
where the `{module, :ambient}` tuple key would cause encoding failures.

# `to_flat_map`

```elixir
@spec to_flat_map(t()) :: map()
```

# `to_serializable`

```elixir
@spec to_serializable(t()) :: map()
```

---

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