{"record":{"id":"c2a318c4c66368b9","repo":"datawhalechina/hello-agents","slug":"hello-agents-pip-install-hello-agents-all","errorCode":null,"errorMessage":"请安装 hello-agents: pip install 'hello-agents[all]>=0.2.7'","messagePattern":"请安装 hello-agents: pip install 'hello-agents\\[all\\]>=0\\.2\\.7'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/core/llm_adapter.py","lineNumber":37,"sourceCode":"\n    def _init_llm(self):\n        \"\"\"初始化 HelloAgent LLM\"\"\"\n        try:\n            from hello_agents import HelloAgentsLLM\n\n            self.llm = HelloAgentsLLM(\n                model=self.config.llm.model_name,\n                api_key=self.config.llm.api_key,\n                base_url=self.config.llm.base_url,\n                temperature=self.config.llm.temperature,\n                max_tokens=self.config.llm.max_tokens,\n                timeout=self.config.llm.timeout\n            )\n\n            logger.info(f\"HelloAgent LLM 初始化成功: {self.config.llm.model_name}\")\n        except ImportError as e:\n            logger.error(f\"hello-agents 未安装: {str(e)}\")\n            raise ImportError(\"请安装 hello-agents: pip install 'hello-agents[all]>=0.2.7'\")\n        except Exception as e:\n            logger.error(f\"HelloAgent LLM 初始化失败: {str(e)}\")\n            raise\n    \n    def _format_messages(self, prompt: Union[str, List[dict]]) -> List[dict]:\n        if isinstance(prompt, str):\n            return [{\"role\": \"user\", \"content\": prompt}]\n        if isinstance(prompt, list):\n            return prompt\n        return [{\"role\": \"user\", \"content\": str(prompt)}]\n\n    async def ainvoke(self, prompt: Union[str, List[dict]], **kwargs) -> str:\n        try:\n            messages = self._format_messages(prompt)\n            response = await asyncio.to_thread(self.llm.invoke, messages, **kwargs)\n            return self._extract_text(response)\n        except Exception as e:\n            raise LLMException(f\"LLM 调用失败: {e}\")","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/core/llm_adapter.py#L19-L55","documentation":"ImportError raised by the LLM adapter when constructing HelloAgentsLLM fails because the hello-agents package is not importable. The adapter catches the original ImportError, logs it, and re-raises with install instructions pinned to hello-agents[all]>=0.2.7. It fires at initialization time, before any completion request is made.","triggerScenarios":"Instantiating the adapter/agent stack in an environment where 'import hello_agents' (or its sub-dependencies under the [all] extra) fails — package not installed, wrong virtualenv, or an extras dependency missing so the top-level import fails.","commonSituations":"Fresh clone without installing requirements; deploying with a minimal install that lacks the [all] extras (embedding/vector deps); running under a different interpreter than the one used to install packages.","solutions":["pip install 'hello-agents[all]>=0.2.7' in the SAME virtualenv/interpreter the backend runs under.","Verify with: python -c \"import hello_agents\" (or the exact module the traceback names) and check pip show hello-agents for the version.","Add the dependency to requirements.txt/pyproject so deploys install it automatically.","If the install exists but import still fails, read the logged original error — it may name a missing sub-dependency to install separately."],"exampleFix":"# before\npip install hello-agents  # missing [all] extras -> ImportError at runtime\n\n# after\npip install 'hello-agents[all]>=0.2.7'\npython -c \"import hello_agents; print(hello_agents.__version__)\"","handlingStrategy":"validation","validationCode":"try:\n    import hello_agents  # noqa: F401\nexcept ImportError:\n    sys.exit(\"missing dependency: pip install 'hello-agents[all]>=0.2.7'\")","typeGuard":null,"tryCatchPattern":"try:\n    adapter = LLMAdapter(config)\nexcept ImportError as e:\n    if \"hello-agents\" in str(e):\n        sys.exit(f\"install dependency: pip install 'hello-agents[all]>=0.2.7'\")\n    raise","preventionTips":["Pin 'hello-agents[all]>=0.2.7' in requirements.txt/pyproject so every env installs it.","Run a startup import smoke test in CI and deploy pipelines.","Confirm the active interpreter matches the env where dependencies were installed (which pip vs which python)."],"tags":["python","importerror","dependency","environment","llm"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}