Priyansh Saxena commited on
Commit
9e7df56
Β·
1 Parent(s): ac70217

docs: Add comprehensive LangChain 0.3.27 import reference guide

Browse files
Files changed (1) hide show
  1. 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`