Agentic. LLM. Timeout
(agentic v0.4.0)
Copy Markdown
Adaptive HTTP receive-timeout for LLM gateway calls.
A fixed 120 s cut off slow-but-valid completions from heavy reasoning models
(e.g. kimi-for-coding, which can spend minutes thinking before emitting
visible output) → spurious :timeout classifications and retries that make an
agent crawl. This tracks a slowly-decaying peak of recent LLM call wall
durations and returns clamp(factor * peak, floor, ceiling), so the timeout
self-tunes to whatever the provider actually needs — generous when the model
is slow, tighter when it's fast — bounded at both ends. A run of timeouts
(whose elapsed ≈ the current timeout) ratchets the value up toward the ceiling.
Config (config :agentic, Agentic.LLM.Timeout, ...):
:floor_ms— minimum timeout, the base (default180_000= 3 min):ceiling_ms— maximum timeout (default600_000= 10 min):factor— multiple of the observed peak (default3.0):decay— per-observation decay of the peak (default0.97)
Reads go through a GenServer.call (microseconds, negligible beside a
multi-second LLM call) and fall back to floor_ms if the tracker isn't
running, so the gateway never breaks when agentic runs unsupervised.
Summary
Functions
Returns a specification to start this module under a supervisor.
Record a completed LLM call's wall duration (ms) so the timeout adapts.
The current adaptive receive-timeout, in milliseconds.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec observe(number()) :: :ok
Record a completed LLM call's wall duration (ms) so the timeout adapts.
@spec receive_timeout() :: pos_integer()
The current adaptive receive-timeout, in milliseconds.