{"record":{"id":"fb369b569819f303","repo":"ComposioHQ/composio","slug":"provider-is-required-for-tool-router-please-initi-fb369b","errorCode":null,"errorMessage":"Provider is required for tool router. Please initialize ToolRouter with a provider.","messagePattern":"Provider is required for tool router\\. Please initialize ToolRouter with a provider\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/composio/core/models/tool_router_session.py","lineNumber":193,"sourceCode":"            inline_custom_tools_payload=self._inline_custom_tools_payload,\n        )\n\n    def tools(self, modifiers: t.Optional[\"Modifiers\"] = None) -> TToolCollection:\n        \"\"\"\n        Get provider-wrapped tools for execution with your AI framework.\n\n        Returns tools configured for this session, wrapped in the format expected\n        by your AI provider (OpenAI, Anthropic, LangChain, etc.).\n\n        When custom tools are bound to the session, execution of\n        COMPOSIO_MULTI_EXECUTE_TOOL is intercepted: local tools are executed\n        in-process, remote tools are sent to the backend.\n        \"\"\"\n        from composio.core.models.tools import Tools as ToolsModel\n        from composio.core.provider import AgenticProvider, NonAgenticProvider\n\n        if self._provider is None:\n            raise ValueError(\n                \"Provider is required for tool router. \"\n                \"Please initialize ToolRouter with a provider.\"\n            )\n\n        tools_model = ToolsModel(\n            client=self._client,\n            provider=self._provider,\n            dangerously_allow_auto_upload_download_files=self._auto_upload_download_files,\n            sensitive_file_upload_protection=self._sensitive_file_upload_protection,\n            file_upload_path_deny_segments=self._file_upload_path_deny_segments,\n            file_upload_dirs=self._file_upload_dirs,\n        )\n\n        router_tools = tools_model.get_raw_tool_router_meta_tools(\n            session_id=self.session_id,\n            modifiers=modifiers,\n        )\n        router_tools = self._add_preloaded_custom_tools(router_tools, modifiers)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/core/models/tool_router_session.py#L175-L211","documentation":"The ToolRouterSession.tools() method lazily builds a Tools model scoped to the session and requires an AgenticProvider/NonAgenticProvider. If the session's _provider is None (provider lost during serialization/deserialization or manual construction), a ValueError is raised before the ToolsModel is created.","triggerScenarios":"Calling session.tools() (often indirectly via session.result or the streaming result flow) on a session whose provider wasn't set — e.g. a session restored from stored state or created outside the normal ToolRouter path.","commonSituations":"Persisting a session ID and reconstructing a session object manually, mocks/fakes in tests that omit the provider.","solutions":["Recreate the session through the provider-configured ToolRouter (create/use) rather than constructing ToolRouterSession directly","Always call .result()/.tools() on the session object returned by router.create()/router.use()"],"exampleFix":"# before\nsession = ToolRouterSession(client=client, session_id=sid)\ntools = session.tools()\n\n# after\nrouter = ToolRouter(api_key=key, provider=provider)\nsession = router.get(sid)  # provider-carrying session\ntools = session.tools()","handlingStrategy":"validation","validationCode":"assert getattr(session, '_provider', None) is not None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call tools()/result() on sessions from router.create()/use()","Don't reconstruct ToolRouterSession manually"],"tags":["python","tool-router","session","provider"],"backgroundTag":"missing-required-parameter","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}