langchain-ai/deepagents · error · RuntimeError
DeepAgentRuntime must be started before invoke
Error message
DeepAgentRuntime must be started before invoke
What it means
DeepAgentRuntime builds its agent graph lazily in start(); invoke() raises this RuntimeError when self._graph is still None, i.e. the runtime was constructed but never started. The graph cannot be invoked before the async startup completes.
Source
Thrown at libs/talon/deepagents_talon/runtime.py:329
result = cleanup()
if isinstance(result, Awaitable):
await result
async def invoke(self, request: AgentRequest) -> AgentResult:
"""Invoke the Deep Agents graph for one Talon request.
Args:
request: Agent request supplied by the Talon host.
Returns:
Final assistant text from the graph.
Raises:
RuntimeError: If the runtime has not been started.
"""
if self._graph is None:
msg = "DeepAgentRuntime must be started before invoke"
raise RuntimeError(msg)
token = _CRON_ORIGIN.set(_cron_origin_from_request(request))
try:
text = await self._invoke_until_text(request)
finally:
_CRON_ORIGIN.reset(token)
return AgentResult(text=text)
def _build_tools(self) -> list[BaseTool | Callable[..., object]]:
tools: list[BaseTool | Callable[..., object]] = []
if self.include_web_tools:
tools.extend([fetch_url, web_search])
if self.cron_store is not None:
cron = CronTools(store=self.cron_store, origin=_current_cron_origin)
tools.extend(cron.as_langchain_tools())
tools.extend(self.tools)
return tools
View on GitHub (pinned to a1af029e6e)
Solutions
- Call `await runtime.start()` once after construction and before any invoke
- If start() previously raised, fix the startup error and construct/start a fresh runtime rather than reusing the half-initialized one
- Wrap the start-then-invoke sequence in your app's lifecycle management (e.g. FastAPI lifespan) so it always runs
Example fix
// before runtime = DeepAgentRuntime(...) reply = await runtime.invoke(request) // after runtime = DeepAgentRuntime(...) await runtime.start() reply = await runtime.invoke(request)
Defensive patterns
Strategy: try-catch
Try / catch
try:
reply = await runtime.invoke(request)
except RuntimeError as exc:
if "must be started before invoke" in str(exc):
await runtime.start()
reply = await runtime.invoke(request)
else:
raise Prevention
- Always pair construction with `await runtime.start()` in a lifecycle hook (app startup, fixture setup)
- Never reuse a runtime after teardown; build a fresh one
- Wrap start+invoke in a small helper so callers cannot skip start
When it happens
Trigger: Calling `await runtime.invoke(request)` without first doing `await runtime.start()`, or calling invoke after an explicit teardown/stop that cleared the graph.
Common situations: Forgetting to await start() in a script or test fixture; a failed start() left the graph unset and a later retry calls invoke directly; reusing a runtime object after shutdown.
Related errors
- Local filesystem backend is unavailable.
- SDK {name} tool is unavailable.
- Server process is not running
- A workspace is required to start the remote agent.
- Session start stopped by hook
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/b8d6b2ca8b981261.
Report an issue: GitHub.