Spaces:
Sleeping
Sleeping
File size: 4,067 Bytes
9e7df56 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | # 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`
|