pub enum AgentLoopError {
Llm(LlmError),
TurnCapExceeded {
max_turns: u32,
partial: Box<AgentOutput>,
},
Timeout {
timeout_secs: u64,
partial: Box<AgentOutput>,
},
Cancelled {
partial: Box<AgentOutput>,
},
StoppedBySignal {
partial: Box<AgentOutput>,
},
}Expand description
Failure modes of AgentLoop::run.
Why: Distinguishes a hard LLM failure from the two budget-exhaustion paths
so callers can decide whether to retry, surface partial output, or abort.
What: Llm wraps the underlying LlmError; TurnCapExceeded and Timeout
each carry the partial AgentOutput accumulated up to the point the limit
fired.
Test: Constructed and matched in agent_loop::tests.
Variants§
Llm(LlmError)
An LLM chat call failed (transport, API, or deserialisation error).
Why: Network/API failures are typically not recoverable within the loop;
the caller decides whether to retry the whole run.
What: Wraps the source LlmError.
TurnCapExceeded
The configured max_turns budget was exhausted before the model stopped.
Why: Long tool-call chains can loop without converging; capping turns
bounds cost. The partial transcript is still returned so the caller sees
how far the run got.
What: Carries the AgentOutput assembled from the turns that completed.
Note: the partial output is for INSPECTION / diagnostics ONLY. The cap
can fire mid-turn — e.g. on an assistant turn that requested tool calls
whose results were never appended — so the transcript may be internally
inconsistent (dangling tool calls, no final answer). It is NOT safe to
replay against an LLM or to resume from; treat it as a snapshot.
Fields
partial: Box<AgentOutput>Partial output accumulated before the cap fired.
Inspection/diagnostics only — see the variant note. May reflect an incomplete turn (e.g. tool calls without matching results); do NOT replay or resume from it.
Timeout
The wall-clock timeout elapsed before the loop finished.
Why: A model that stalls or a tool that hangs must not block the caller
indefinitely; the timeout bounds total latency.
What: Carries the configured timeout_secs and the partial AgentOutput
assembled before the deadline.
Note: the partial output is for INSPECTION / diagnostics ONLY. The
deadline can elapse at any point — including between an assistant turn’s
tool calls and their results — so the transcript may be internally
inconsistent (dangling tool calls, no final answer). It is NOT safe to
replay against an LLM or to resume from; treat it as a snapshot.
Fields
partial: Box<AgentOutput>Partial output accumulated before the deadline.
Inspection/diagnostics only — see the variant note. May reflect an incomplete turn (e.g. tool calls without matching results); do NOT replay or resume from it.
Cancelled
The loop’s with_cancel_flag cancellation flag was observed set
(#2056: session.cancel on an in-flight daemon-driven run).
Why: session.cancel must stop an in-flight task cooperatively rather
than aborting the process or leaking the background task. The flag is
checked once per turn boundary (before the next LLM call) — per the
vision spec §12 (11.6), cancellation is NOT instantaneous: a tool call
already in flight always completes first.
What: Carries the partial AgentOutput assembled before cancellation
was observed, for the same inspection-only purpose as the other two
abort variants.
Fields
partial: Box<AgentOutput>Partial output accumulated before cancellation was observed.
Inspection/diagnostics only — see the variant note on the other abort arms. Do NOT replay or resume from it.
StoppedBySignal
The loop’s with_stop_signal external stop condition was observed
true at a turn boundary (#2265 fix #5).
Why: A caller may know, independently of this loop’s own turn/timeout
budget, that continuing is pointless — e.g. run_task’s PM loop shares
a RedelegationCapSignal with the engineer-delegation retry decorator;
once that cap latches, every further delegate_to_agent call is a
guaranteed dead end, so burning the PM’s remaining turns issuing them
(previously bounded only by AgentLoopConfig::max_turns) wasted up to
7 turns per run in the bake-off L1 evidence for zero additional
engineer work. Checking the signal at the SAME turn boundary as the
(#2056) cancellation flag — before the next chat call, never
mid-tool-call — stops the loop the turn AFTER the condition becomes
true, without dropping any in-flight tool dispatch.
What: Carries the partial AgentOutput assembled before the signal
was observed, for the same inspection-only purpose as the other abort
variants.
Fields
partial: Box<AgentOutput>Partial output accumulated before the stop signal was observed.
Inspection/diagnostics only — see the variant note on the other abort arms. Do NOT replay or resume from it.
Trait Implementations§
Source§impl Debug for AgentLoopError
impl Debug for AgentLoopError
Source§impl Display for AgentLoopError
impl Display for AgentLoopError
Source§impl Error for AgentLoopError
impl Error for AgentLoopError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for AgentLoopError
impl !UnwindSafe for AgentLoopError
impl Freeze for AgentLoopError
impl Send for AgentLoopError
impl Sync for AgentLoopError
impl Unpin for AgentLoopError
impl UnsafeUnpin for AgentLoopError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more