Spaces:
Sleeping
Sleeping
| # Langchain 0.3.27 Import Fixes - Complete Reference | |
| **Last Updated:** After multiple iterations of import corrections | |
| **Status:** β All critical imports validated for langchain 0.3.27 | |
| ## Problem Summary | |
| The web3-research-agent uses LangChain. Version 0.3.27 underwent major restructuring where: | |
| 1. Memory classes were moved to `langchain_classic` namespace | |
| 2. Tool base classes are in `langchain_core.tools` | |
| 3. LLM integrations remained in their respective packages | |
| ## Final Correct Imports (VERIFIED) | |
| ### 1. **Memory Imports** β | |
| ```python | |
| # CORRECT (langchain_classic.memory): | |
| from langchain_classic.memory import ConversationBufferWindowMemory | |
| # WRONG (these don't exist in 0.3.27): | |
| # β from langchain.memory import ConversationBufferWindowMemory | |
| # β from langchain_community.memory import ConversationBufferWindowMemory | |
| ``` | |
| **Files Fixed:** | |
| - `src/agent/memory_manager.py` (line 1) | |
| - `src/agent/research_agent.py` (line 3) | |
| ### 2. **Tool Base Class** β | |
| ```python | |
| # CORRECT (langchain_core.tools): | |
| from langchain_core.tools import BaseTool | |
| # WRONG: | |
| # β from langchain_community.tools import BaseTool | |
| # β from langchain.tools import BaseTool | |
| ``` | |
| **Files Using This:** | |
| - `src/tools/base_tool.py` (line 3) | |
| - `src/tools/chart_data_tool.py` (line 1) | |
| - `src/tools/chart_creator_tool.py` (line 1) | |
| ### 3. **LLM Integrations** β (Also Correct) | |
| ```python | |
| # Google Generative AI (Gemini): | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| # Ollama (Local): | |
| from langchain_community.llms import Ollama | |
| ``` | |
| ### 4. **Pydantic Models** β | |
| ```python | |
| # All are correct Pydantic v2: | |
| from pydantic import BaseModel, Field, PrivateAttr, field_validator | |
| ``` | |
| ## All Langchain Imports in Codebase | |
| | File | Import | Status | | |
| |------|--------|--------| | |
| | `src/agent/memory_manager.py` | `from langchain_classic.memory import ConversationBufferWindowMemory` | β | | |
| | `src/agent/research_agent.py` (L1) | `from langchain_google_genai import ChatGoogleGenerativeAI` | β | | |
| | `src/agent/research_agent.py` (L2) | `from langchain_community.llms import Ollama` | β | | |
| | `src/agent/research_agent.py` (L3) | `from langchain_classic.memory import ConversationBufferWindowMemory` | β | | |
| | `src/tools/base_tool.py` | `from langchain_core.tools import BaseTool` | β | | |
| | `src/tools/chart_data_tool.py` | `from langchain_core.tools import BaseTool` | β | | |
| | `src/tools/chart_creator_tool.py` | `from langchain_core.tools import BaseTool` | β | | |
| | `debug_gemini.py` | `from langchain_google_genai import ChatGoogleGenerativeAI` | β | | |
| ## Requirements.txt Dependencies | |
| **All packages confirmed in requirements.txt:** | |
| ``` | |
| langchain # Main package (includes langchain_classic) | |
| langchain-google-genai # Google Generative AI (Gemini) | |
| langchain-community # Community integrations (Ollama, etc.) | |
| google-generativeai # Google AI API | |
| pydantic # Data validation | |
| ... (other dependencies) | |
| ``` | |
| ## Why Langchain_classic? | |
| In langchain 0.3.27: | |
| - **Memory classes** moved to `langchain_classic` (backwards compatibility layer) | |
| - These are marked `@deprecated(since="0.3.1", removal="1.0.0")` | |
| - `langchain_classic` serves as a compatibility bridge | |
| - Full migration would require replacing with `RunnableWithMessageHistory` (future work) | |
| ## Prevention Checklist | |
| β No imports from non-existent modules | |
| β All `BaseTool` imports from `langchain_core.tools` | |
| β All memory imports from `langchain_classic.memory` | |
| β All LLM integrations from correct packages | |
| β No circular imports detected | |
| β Pydantic v2 syntax used consistently | |
| ## Next Error Discovery Method | |
| If new import errors occur: | |
| 1. Check error message for module path | |
| 2. Verify in [langchain GitHub](https://github.com/langchain-ai/langchain) - `libs/langchain/` folder | |
| 3. Look for `__init__.py` exports to find actual location | |
| 4. Never assume module is available under base `langchain` package - check `langchain_classic` or `langchain_core` | |
| --- | |
| **Last Fix Commit:** `ac70217` - Fixed memory imports to use `langchain_classic` | |