# `ReqManagedAgents.Consolidate`
[🔗](https://github.com/cash-mckeeman/req_managed_agents/blob/v0.12.0/req_managed_agents/lib/req_managed_agents/consolidate.ex#L1)

Pure helpers for reconnect-with-consolidation.

The event stream has **no replay**: on (re)connect a consumer lists past events
and must (a) drop ones it already processed and (b) re-drive any tool call left
unanswered across the disconnect, or the session deadlocks waiting on it. These
functions are pure so the orchestration layer (e.g. `ReqManagedAgents.Session`)
or any custom loop can call them.

# `dedupe`

```elixir
@spec dedupe([map()], MapSet.t()) :: {[map()], MapSet.t()}
```

Split `events` into the ones not in `seen` and return the grown seen-set.

# `pending_requires_action`

```elixir
@spec pending_requires_action([map()]) :: map() | nil
```

Return the `stop_reason` map of the last `requires_action` idle event if it was
never followed by another terminal idle (i.e. still pending), else `nil`.

# `unanswered_tool_uses`

```elixir
@spec unanswered_tool_uses([map()]) :: [map()]
```

Return `agent.custom_tool_use` events that have no matching `user.custom_tool_result`.

---

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