# `MingaAgent.Event`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/event.ex#L1)

Provider-agnostic event types for agent communication.

These structs represent the events that flow from a provider (pi RPC,
direct API, etc.) to the `Agent.Session`. The session uses them to
update conversation state, status, and UI without knowing anything
about the underlying provider protocol.

# `agent_end`

```elixir
@type agent_end() :: %MingaAgent.Event.AgentEnd{usage: token_usage() | nil}
```

Agent has finished processing.

# `agent_start`

```elixir
@type agent_start() :: %MingaAgent.Event.AgentStart{}
```

Agent has started processing a prompt.

# `context_usage`

```elixir
@type context_usage() :: %MingaAgent.Event.ContextUsage{
  context_limit: non_neg_integer() | nil,
  estimated_tokens: non_neg_integer()
}
```

Pre-send estimated context usage.

# `error`

```elixir
@type error() :: %MingaAgent.Event.Error{message: String.t()}
```

An error occurred in the agent.

# `t`

```elixir
@type t() ::
  agent_start()
  | agent_end()
  | text_delta()
  | thinking_delta()
  | tool_start()
  | tool_update()
  | tool_end()
  | tool_approval()
  | tool_file_changed()
  | context_usage()
  | turn_limit_reached()
  | error()
```

Union of all agent event types.

# `text_delta`

```elixir
@type text_delta() :: %MingaAgent.Event.TextDelta{delta: String.t()}
```

A chunk of assistant response text.

# `thinking_delta`

```elixir
@type thinking_delta() :: %MingaAgent.Event.ThinkingDelta{delta: String.t()}
```

A chunk of the agent's internal reasoning.

# `token_usage`

```elixir
@type token_usage() :: MingaAgent.TurnUsage.t()
```

Token usage statistics from a completed response.

# `tool_approval`

```elixir
@type tool_approval() :: %MingaAgent.Event.ToolApproval{
  args: map(),
  name: String.t(),
  reply_to: pid(),
  tool_call_id: String.t()
}
```

A destructive tool call needs user approval before executing.

# `tool_end`

```elixir
@type tool_end() :: %MingaAgent.Event.ToolEnd{
  is_error: boolean(),
  name: String.t(),
  result: String.t(),
  tool_call_id: String.t()
}
```

A tool call has completed.

# `tool_file_changed`

```elixir
@type tool_file_changed() :: %MingaAgent.Event.ToolFileChanged{
  after_content: String.t(),
  before_content: String.t(),
  path: String.t(),
  tool_call_id: String.t()
}
```

A file-modifying tool captured before/after content for diff review.

# `tool_start`

```elixir
@type tool_start() :: %MingaAgent.Event.ToolStart{
  args: map(),
  name: String.t(),
  tool_call_id: String.t()
}
```

A tool call has started.

# `tool_update`

```elixir
@type tool_update() :: %MingaAgent.Event.ToolUpdate{
  name: String.t(),
  partial_result: String.t(),
  tool_call_id: String.t()
}
```

Partial progress on a running tool call.

# `turn_limit_reached`

```elixir
@type turn_limit_reached() :: %MingaAgent.Event.TurnLimitReached{
  current: non_neg_integer(),
  limit: pos_integer()
}
```

The agent reached its per-prompt turn limit.

---

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