Skip to main content

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:

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


Key Takeaway: LangChain is great for prototyping. StateBase makes it production-ready.