# `ADK.LLM.CircuitBreaker`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/llm/circuit_breaker.ex#L1)

Simple circuit breaker for LLM calls using GenServer.

## States

  * `:closed` — Normal operation, calls pass through
  * `:open` — Too many failures, calls rejected with `{:error, :circuit_open}`
  * `:half_open` — Testing recovery, allows one call through

## Options

  * `:name` - GenServer name (default: `__MODULE__`)
  * `:failure_threshold` - Failures before opening (default: 5)
  * `:reset_timeout_ms` - Time in open state before half-open (default: 60_000)

## Examples

    {:ok, _} = ADK.LLM.CircuitBreaker.start_link(name: :llm_breaker)
    ADK.LLM.CircuitBreaker.call(:llm_breaker, fn -> some_llm_call() end)

# `t`

```elixir
@type t() :: %ADK.LLM.CircuitBreaker{
  failure_count: non_neg_integer(),
  failure_threshold: pos_integer(),
  opened_at: integer() | nil,
  reset_timeout_ms: pos_integer(),
  state: :closed | :open | :half_open
}
```

# `call`

```elixir
@spec call(GenServer.server(), (-&gt; {:ok, term()} | {:error, term()})) ::
  {:ok, term()} | {:error, term()}
```

Execute `fun` through the circuit breaker.

Returns `{:error, :circuit_open}` if the circuit is open.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_state`

```elixir
@spec get_state(GenServer.server()) :: :closed | :open | :half_open
```

Get the current state of the circuit breaker.

# `reset`

```elixir
@spec reset(GenServer.server()) :: :ok
```

Reset the circuit breaker to closed state.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the circuit breaker.

---

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