Spaces:
Sleeping
Sleeping
Priyansh Saxena commited on
Commit Β·
9e7df56
1
Parent(s): ac70217
docs: Add comprehensive LangChain 0.3.27 import reference guide
Browse files- IMPORT_FIXES.md +110 -0
IMPORT_FIXES.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Langchain 0.3.27 Import Fixes - Complete Reference
|
| 2 |
+
|
| 3 |
+
**Last Updated:** After multiple iterations of import corrections
|
| 4 |
+
**Status:** β
All critical imports validated for langchain 0.3.27
|
| 5 |
+
|
| 6 |
+
## Problem Summary
|
| 7 |
+
|
| 8 |
+
The web3-research-agent uses LangChain. Version 0.3.27 underwent major restructuring where:
|
| 9 |
+
1. Memory classes were moved to `langchain_classic` namespace
|
| 10 |
+
2. Tool base classes are in `langchain_core.tools`
|
| 11 |
+
3. LLM integrations remained in their respective packages
|
| 12 |
+
|
| 13 |
+
## Final Correct Imports (VERIFIED)
|
| 14 |
+
|
| 15 |
+
### 1. **Memory Imports** β
|
| 16 |
+
```python
|
| 17 |
+
# CORRECT (langchain_classic.memory):
|
| 18 |
+
from langchain_classic.memory import ConversationBufferWindowMemory
|
| 19 |
+
|
| 20 |
+
# WRONG (these don't exist in 0.3.27):
|
| 21 |
+
# β from langchain.memory import ConversationBufferWindowMemory
|
| 22 |
+
# β from langchain_community.memory import ConversationBufferWindowMemory
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
**Files Fixed:**
|
| 26 |
+
- `src/agent/memory_manager.py` (line 1)
|
| 27 |
+
- `src/agent/research_agent.py` (line 3)
|
| 28 |
+
|
| 29 |
+
### 2. **Tool Base Class** β
|
| 30 |
+
```python
|
| 31 |
+
# CORRECT (langchain_core.tools):
|
| 32 |
+
from langchain_core.tools import BaseTool
|
| 33 |
+
|
| 34 |
+
# WRONG:
|
| 35 |
+
# β from langchain_community.tools import BaseTool
|
| 36 |
+
# β from langchain.tools import BaseTool
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
**Files Using This:**
|
| 40 |
+
- `src/tools/base_tool.py` (line 3)
|
| 41 |
+
- `src/tools/chart_data_tool.py` (line 1)
|
| 42 |
+
- `src/tools/chart_creator_tool.py` (line 1)
|
| 43 |
+
|
| 44 |
+
### 3. **LLM Integrations** β
(Also Correct)
|
| 45 |
+
```python
|
| 46 |
+
# Google Generative AI (Gemini):
|
| 47 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 48 |
+
|
| 49 |
+
# Ollama (Local):
|
| 50 |
+
from langchain_community.llms import Ollama
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### 4. **Pydantic Models** β
|
| 54 |
+
```python
|
| 55 |
+
# All are correct Pydantic v2:
|
| 56 |
+
from pydantic import BaseModel, Field, PrivateAttr, field_validator
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
## All Langchain Imports in Codebase
|
| 60 |
+
|
| 61 |
+
| File | Import | Status |
|
| 62 |
+
|------|--------|--------|
|
| 63 |
+
| `src/agent/memory_manager.py` | `from langchain_classic.memory import ConversationBufferWindowMemory` | β
|
|
| 64 |
+
| `src/agent/research_agent.py` (L1) | `from langchain_google_genai import ChatGoogleGenerativeAI` | β
|
|
| 65 |
+
| `src/agent/research_agent.py` (L2) | `from langchain_community.llms import Ollama` | β
|
|
| 66 |
+
| `src/agent/research_agent.py` (L3) | `from langchain_classic.memory import ConversationBufferWindowMemory` | β
|
|
| 67 |
+
| `src/tools/base_tool.py` | `from langchain_core.tools import BaseTool` | β
|
|
| 68 |
+
| `src/tools/chart_data_tool.py` | `from langchain_core.tools import BaseTool` | β
|
|
| 69 |
+
| `src/tools/chart_creator_tool.py` | `from langchain_core.tools import BaseTool` | β
|
|
| 70 |
+
| `debug_gemini.py` | `from langchain_google_genai import ChatGoogleGenerativeAI` | β
|
|
| 71 |
+
|
| 72 |
+
## Requirements.txt Dependencies
|
| 73 |
+
|
| 74 |
+
**All packages confirmed in requirements.txt:**
|
| 75 |
+
```
|
| 76 |
+
langchain # Main package (includes langchain_classic)
|
| 77 |
+
langchain-google-genai # Google Generative AI (Gemini)
|
| 78 |
+
langchain-community # Community integrations (Ollama, etc.)
|
| 79 |
+
google-generativeai # Google AI API
|
| 80 |
+
pydantic # Data validation
|
| 81 |
+
... (other dependencies)
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## Why Langchain_classic?
|
| 85 |
+
|
| 86 |
+
In langchain 0.3.27:
|
| 87 |
+
- **Memory classes** moved to `langchain_classic` (backwards compatibility layer)
|
| 88 |
+
- These are marked `@deprecated(since="0.3.1", removal="1.0.0")`
|
| 89 |
+
- `langchain_classic` serves as a compatibility bridge
|
| 90 |
+
- Full migration would require replacing with `RunnableWithMessageHistory` (future work)
|
| 91 |
+
|
| 92 |
+
## Prevention Checklist
|
| 93 |
+
|
| 94 |
+
β
No imports from non-existent modules
|
| 95 |
+
β
All `BaseTool` imports from `langchain_core.tools`
|
| 96 |
+
β
All memory imports from `langchain_classic.memory`
|
| 97 |
+
β
All LLM integrations from correct packages
|
| 98 |
+
β
No circular imports detected
|
| 99 |
+
β
Pydantic v2 syntax used consistently
|
| 100 |
+
|
| 101 |
+
## Next Error Discovery Method
|
| 102 |
+
|
| 103 |
+
If new import errors occur:
|
| 104 |
+
1. Check error message for module path
|
| 105 |
+
2. Verify in [langchain GitHub](https://github.com/langchain-ai/langchain) - `libs/langchain/` folder
|
| 106 |
+
3. Look for `__init__.py` exports to find actual location
|
| 107 |
+
4. Never assume module is available under base `langchain` package - check `langchain_classic` or `langchain_core`
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
**Last Fix Commit:** `ac70217` - Fixed memory imports to use `langchain_classic`
|