langchain-ai/deepagents · error · RuntimeError
agent invocation retry loop exited unexpectedly
Error message
agent invocation retry loop exited unexpectedly
What it means
_invoke_payload_with_retries loops retrying graph invocations and normally exits either by returning a result or by re-raising the last captured exception (last_exc). This RuntimeError is raised only if the loop ends with no result and no captured exception, which indicates an internal invariant violation (e.g. a break path that neither succeeded nor recorded an exception).
Source
Thrown at libs/talon/deepagents_talon/runtime.py:414
return await invoke(payload, config=config)
except asyncio.CancelledError:
raise
except Exception as exc:
if not _is_retryable(exc) or attempt + 1 >= self.max_retries:
raise
last_exc = exc
backoff = min(2**attempt, 10)
logger.warning(
"Retryable agent error in conversation %s; retrying in %ds: %s",
conversation_id,
backoff,
exc,
)
await asyncio.sleep(backoff)
if last_exc is not None:
raise last_exc
msg = "agent invocation retry loop exited unexpectedly"
raise RuntimeError(msg)
def _graph_invoke(self) -> Callable[..., Awaitable[object]]:
ainvoke = getattr(self._graph, "ainvoke", None)
if not callable(ainvoke):
msg = "Deep Agents graph does not expose async invocation"
raise TypeError(msg)
return cast("Callable[..., Awaitable[object]]", ainvoke)
async def _invoke_until_unblocked(
self,
content: ModelContent,
request: AgentRequest,
) -> object:
state = await self._invoke_with_retries(content, request.conversation_id)
for _ in range(DEFAULT_MAX_APPROVAL_ROUNDS):
interrupts = _interrupts_from_state(state)
if not interrupts:
return stateView on GitHub (pinned to a1af029e6e)
Solutions
- Report it to the library maintainers with a traceback and the runtime configuration
- Check for subclasses/monkeypatches of _invoke_payload_with_retries or its retry hooks that break the loop invariant
- Pin/upgrade to a version of the library where the retry loop is fixed
Defensive patterns
Strategy: retry
Try / catch
try:
reply = await runtime.invoke(request)
except RuntimeError as exc:
if "retry loop exited unexpectedly" in str(exc):
log.exception("runtime invariant violated; retrying once with fresh runtime")
runtime = rebuild_runtime()
await runtime.start()
reply = await runtime.invoke(request)
else:
raise Prevention
- Treat this as a bug: capture full tracebacks and report to maintainers
- Avoid monkeypatching or subclassing the retry internals
- Pin library versions and re-verify after upgrades
When it happens
Trigger: An internal edge case in the retry loop: the loop terminates without a successful payload and without last_exc being set. Not reachable through normal configuration.
Common situations: Effectively a bug guard; encountered after a library upgrade or custom subclassing that overrides retry hooks, or a corrupted retry configuration that skips the attempt body.
Related errors
- Local filesystem backend is unavailable.
- SDK {name} tool is unavailable.
- Received hook invocation interrupt without a HooksRuntime
- Unsupported hook event: {type(event).__name__}
- Unsupported hook-specific output: {type(specific).__name__}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/e347cfb1c044aa4c.
Report an issue: GitHub.