{"record":{"id":"97837a6b8b244859","repo":"agentscope-ai/agentscope","slug":"feishu-channel-requires-lark-oapi-pip-install-l","errorCode":null,"errorMessage":"Feishu channel requires 'lark-oapi' (pip install lark-oapi).","messagePattern":"Feishu channel requires 'lark-oapi' \\(pip install lark-oapi\\)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/agentscope/app/channel/_feishu/_channel.py","lineNumber":283,"sourceCode":"                    ws_loop.call_soon_threadsafe(ws_loop.stop)\n                except RuntimeError:\n                    pass  # loop already closed\n            if self._ws_thread and self._ws_thread.is_alive():\n                self._ws_thread.join(timeout=5.0)\n            if self._http:\n                await self._http.aclose()\n                self._http = None\n\n    def _launch_ws_thread(self) -> threading.Thread:\n        \"\"\"Start the lark WS client on a daemon thread with its own loop.\n\n        Returns:\n            `threading.Thread`: The started WS thread (daemon).\n        \"\"\"\n        try:\n            import lark_oapi as lark\n        except ImportError as e:\n            raise ImportError(\n                \"Feishu channel requires 'lark-oapi' \"\n                \"(pip install lark-oapi).\",\n            ) from e\n\n        loop = self._loop\n        assert loop is not None  # set in start_listening before this runs\n\n        def on_message(data: \"P2ImMessageReceiveV1\") -> None:\n            \"\"\"Bridge an inbound message onto the app loop.\n\n            Args:\n                data (`P2ImMessageReceiveV1`): The SDK message event.\n            \"\"\"\n            asyncio.run_coroutine_threadsafe(self._on_message(data), loop)\n\n        def on_card_action(\n            data: \"P2CardActionTrigger\",\n        ) -> \"P2CardActionTriggerResponse\":","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/channel/_feishu/_channel.py#L265-L301","documentation":"ImportError raised inside _launch_ws_thread when starting the Feishu (Lark) channel's WebSocket listener: the optional dependency lark-oapi is not installed. The Feishu channel is an optional extra, so the SDK only imports lark_oapi lazily at listen time and converts the missing module into an actionable ImportError with the pip install hint.","triggerScenarios":"Calling start_listening() on a Feishu channel (or create_app with a Feishu channel that starts listening) in an environment where lark-oapi is not installed — e.g. agentscope installed without the feishu extra, a slim Docker image, or a fresh virtualenv.","commonSituations":"Installing the base package without extras (pip install agentscope vs agentscope[feishu]), CI environments with a trimmed dependency set, dependency pruning tools removing 'unused' optional deps.","solutions":["pip install lark-oapi (or install agentscope with the feishu extra, e.g. pip install 'agentscope[feishu]')","Add lark-oapi to your project's requirements/pyproject dependencies if you ship Feishu support","Verify with python -c \"import lark_oapi\" before starting the app","If Feishu is not needed, remove the Feishu channel from create_app(channels=[...]) so the listener never starts"],"exampleFix":"# before\npip install agentscope\napp = create_app(channels=[FeishuChannel])\n\n# after\npip install lark-oapi\napp = create_app(channels=[FeishuChannel])","handlingStrategy":"validation","validationCode":"try:\n    import lark_oapi  # noqa: F401\n    FEISHU_AVAILABLE = True\nexcept ImportError:\n    FEISHU_AVAILABLE = False\n\nif using_feishu and not FEISHU_AVAILABLE:\n    raise SystemExit(\"Install with: pip install lark-oapi\")","typeGuard":null,"tryCatchPattern":"try:\n    channel.start_listening()\nexcept ImportError as e:\n    if \"lark-oapi\" in str(e):\n        subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"lark-oapi\"])\n        channel.start_listening()","preventionTips":["Declare lark-oapi in your dependency manifest when Feishu is used","Add a startup dependency check for optional extras","Pin the extra in Docker/CI images that run Feishu channels"],"tags":["feishu","optional-dependency","import-error","websocket"],"backgroundTag":"missing-optional-dependency","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}