{"record":{"id":"b8d6b2ca8b981261","repo":"langchain-ai/deepagents","slug":"deepagentruntime-must-be-started-before-invoke","errorCode":null,"errorMessage":"DeepAgentRuntime must be started before invoke","messagePattern":"DeepAgentRuntime must be started before invoke","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/runtime.py","lineNumber":329,"sourceCode":"            result = cleanup()\n            if isinstance(result, Awaitable):\n                await result\n\n    async def invoke(self, request: AgentRequest) -> AgentResult:\n        \"\"\"Invoke the Deep Agents graph for one Talon request.\n\n        Args:\n            request: Agent request supplied by the Talon host.\n\n        Returns:\n            Final assistant text from the graph.\n\n        Raises:\n            RuntimeError: If the runtime has not been started.\n        \"\"\"\n        if self._graph is None:\n            msg = \"DeepAgentRuntime must be started before invoke\"\n            raise RuntimeError(msg)\n\n        token = _CRON_ORIGIN.set(_cron_origin_from_request(request))\n        try:\n            text = await self._invoke_until_text(request)\n        finally:\n            _CRON_ORIGIN.reset(token)\n        return AgentResult(text=text)\n\n    def _build_tools(self) -> list[BaseTool | Callable[..., object]]:\n        tools: list[BaseTool | Callable[..., object]] = []\n        if self.include_web_tools:\n            tools.extend([fetch_url, web_search])\n        if self.cron_store is not None:\n            cron = CronTools(store=self.cron_store, origin=_current_cron_origin)\n            tools.extend(cron.as_langchain_tools())\n        tools.extend(self.tools)\n        return tools\n","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/runtime.py#L311-L347","documentation":"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.","triggerScenarios":"Calling `await runtime.invoke(request)` without first doing `await runtime.start()`, or calling invoke after an explicit teardown/stop that cleared the graph.","commonSituations":"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.","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"],"exampleFix":"// before\nruntime = DeepAgentRuntime(...)\nreply = await runtime.invoke(request)\n// after\nruntime = DeepAgentRuntime(...)\nawait runtime.start()\nreply = await runtime.invoke(request)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    reply = await runtime.invoke(request)\nexcept RuntimeError as exc:\n    if \"must be started before invoke\" in str(exc):\n        await runtime.start()\n        reply = await runtime.invoke(request)\n    else:\n        raise","preventionTips":["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"],"tags":["lifecycle","async","runtime"],"backgroundTag":"not-initialized","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}