LangChain Integration
StateBase integrates seamlessly with LangChain to provide production-grade memory and state management for your LangChain agents.Why StateBase + LangChain?
LangChain’s built-in memory (e.g.,ConversationBufferMemory) is ephemeral and not production-ready:
| Feature | LangChain Memory | StateBase |
|---|---|---|
| Persistence | In-memory only | PostgreSQL + Redis |
| Rollback | ❌ Not supported | ✅ Time-travel to any turn |
| Audit Trail | ❌ No logging | ✅ Complete trace history |
| Multi-Session | ❌ Separate instances | ✅ Unified memory across sessions |
| Semantic Search | ❌ Basic retrieval | ✅ Vector-based memory search |
Installation
Basic Integration
Replace LangChain’s memory with StateBase:Custom Memory Class
Create a LangChain-compatible memory class:With LangChain Agents
Use StateBase with LangChain’s agent framework:Checkpointing Tool Calls
Checkpoint before expensive tool calls:Semantic Memory with LangChain
Combine LangChain’s retrieval with StateBase’s memory:Migration from LangChain Memory
Migrate existing LangChain memory to StateBase:Best Practices
✅ Do This
- Use StateBase for production (LangChain memory is for prototyping)
- Checkpoint before tool calls (enables retry without re-execution)
- Store user preferences in StateBase memory (cross-session persistence)
- Log all agent actions (full audit trail)
❌ Avoid This
- Don’t use ConversationBufferMemory in production (data loss risk)
- Don’t mix memory backends (pick StateBase or LangChain, not both)
- Don’t skip turn logging (you’ll need it for debugging)
Complete Example
Next Steps
- LangGraph Integration: Use StateBase with LangGraph
- Tool Calling Pattern: Advanced tool usage
- Migration Guide: Detailed migration steps
Key Takeaway: LangChain is great for prototyping. StateBase makes it production-ready.