CA21: LangChain Memory Agents
๐ Overview
This project implements advanced LangChain-based memory agents that combine the power of LangChain with sophisticated memory systems. It features conversational memory, context-aware agents, and comprehensive memory management for AI applications.
๐ฏ Key Features
Core Capabilities
- LangChain Integration: Seamless integration with LangChain framework
- Memory Agents: AI agents with persistent memory capabilities
- Conversational Memory: Maintaining conversation context
- Context Awareness: Context-aware decision making
- Memory Management: Efficient memory storage and retrieval
Advanced Features
- Multi-Agent Systems: Multiple agents with shared memory
- Memory Persistence: Persistent memory across sessions
- Memory Compression: Compressing memory for efficiency
- Real-Time Processing: Real-time memory operations
- Comprehensive Analysis: Detailed memory system analysis
๐๏ธ System Architecture
1. LangChain Memory Pipeline
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Input โ โ LangChain โ โ Memory โ
โ Processing โโโโโถโ Processing โโโโโถโ Storage โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
2. Memory Agent Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LangChain Memory Agent โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโค
โ LangChain โ Memory โ Context โ Decision โ
โ Framework โ System โ Manager โ Engine โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
3. Multi-Agent Memory Framework
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Agent 1 โ โ Agent 2 โ โ Agent N โ
โ Memory โโโโโถโ Memory โโโโโถโ Memory โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
๐ Project Structure
CA21_langchain_memory_agents/
โโโ CA21.ipynb # Main Jupyter notebook
โโโ main.py # Main execution script
โโโ advanced_main.py # Advanced execution script
โโโ demo.py # Demonstration script
โโโ comprehensive_demo.py # Comprehensive demonstration
โโโ advanced_demo.py # Advanced demonstration
โโโ advanced_langchain_demo.py # Advanced LangChain demo
โโโ simple_demo.py # Simple demonstration
โโโ run_advanced.sh # Advanced execution script
โโโ run_all.sh # Run all demos
โโโ run_pipeline.sh # Pipeline execution
โโโ src/ # Source code
โ โโโ agents/ # LangChain agents
โ โ โโโ base_agent.py # Base LangChain agent
โ โ โโโ memory_agent.py # Memory-enabled agent
โ โ โโโ conversational_agent.py # Conversational agent
โ โ โโโ multi_agent.py # Multi-agent system
โ โโโ memory/ # Memory systems
โ โ โโโ conversation_memory.py # Conversation memory
โ โ โโโ context_memory.py # Context memory
โ โ โโโ persistent_memory.py # Persistent memory
โ โ โโโ shared_memory.py # Shared memory
โ โโโ langchain/ # LangChain components
โ โ โโโ chain_builder.py # Chain builder
โ โ โโโ prompt_templates.py # Prompt templates
โ โ โโโ tool_integration.py # Tool integration
โ โ โโโ workflow_orchestrator.py # Workflow orchestrator
โ โโโ analysis/ # Analysis tools
โ โ โโโ memory_analyzer.py # Memory analysis
โ โ โโโ performance_analyzer.py # Performance analysis
โ โ โโโ conversation_analyzer.py # Conversation analysis
โ โ โโโ agent_analyzer.py # Agent analysis
โ โโโ utils/ # Utility functions
โ โโโ visualization.py # Visualization tools
โ โโโ analysis.py # Analysis utilities
โ โโโ io_utils.py # I/O utilities
โโโ tests/ # Test files
โ โโโ test_agents.py # Agent tests
โ โโโ test_memory.py # Memory tests
โ โโโ test_langchain.py # LangChain tests
โ โโโ test_integration.py # Integration tests
โโโ config/ # Configuration files
โ โโโ agent_config.yaml # Agent configuration
โ โโโ memory_config.yaml # Memory configuration
โ โโโ langchain_config.yaml # LangChain configuration
โโโ data/ # Data files
โ โโโ conversations/ # Conversation data
โ โโโ memory/ # Memory data
โ โโโ results/ # Result data
โโโ results/ # Output results
โโโ requirements.txt # Python dependencies
โโโ run.sh # Execution script
โโโ README.md # This file
โโโ README_FINAL.md # Final documentation
๐ Quick Start
Prerequisites
- Python 3.8+
- LangChain library
- OpenAI API key (optional)
- Jupyter Notebook (optional)
Installation
- Clone the repository
git clone <repository-url>
cd CA21_langchain_memory_agents
- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Run the project
chmod +x run.sh
./run.sh
Manual Execution
# Run basic demo
python demo.py
# Run comprehensive demo
python comprehensive_demo.py
# Run advanced demo
python advanced_demo.py
# Run simple demo
python simple_demo.py
# Run all demos
chmod +x run_all.sh
./run_all.sh
# Run Jupyter notebook
jupyter notebook CA21.ipynb
๐ง Configuration
Agent Configuration
# config/agent_config.yaml
agent:
type: "memory_agent"
memory_enabled: true
context_window: 10
max_memory_size: 1000
langchain:
model: "gpt-3.5-turbo"
temperature: 0.7
max_tokens: 1000
Memory Configuration
# config/memory_config.yaml
memory:
conversation_memory:
enabled: true
max_conversations: 100
persistence: true
context_memory:
enabled: true
context_length: 5
compression: true
persistent_memory:
enabled: true
storage_path: "./data/memory"
format: "json"
LangChain Configuration
# config/langchain_config.yaml
langchain:
chains:
- type: "conversation"
memory: true
tools: ["search", "calculator"]
- type: "analysis"
memory: true
tools: ["analyzer", "visualizer"]
tools:
search:
type: "web_search"
enabled: true
calculator:
type: "math_calculator"
enabled: true
๐ Features & Capabilities
1. LangChain Integration
- Chain Building: Building LangChain chains
- Tool Integration: Integrating tools with chains
- Prompt Templates: Using prompt templates
- Workflow Orchestration: Orchestrating workflows
2. Memory Systems
- Conversation Memory: Maintaining conversation context
- Context Memory: Managing context information
- Persistent Memory: Persistent memory storage
- Shared Memory: Shared memory across agents
3. Agent Types
- Base Agent: Basic LangChain agent
- Memory Agent: Agent with memory capabilities
- Conversational Agent: Conversational agent
- Multi-Agent: Multi-agent system
4. Analysis Tools
- Memory Analysis: Analyzing memory usage
- Performance Analysis: Analyzing performance
- Conversation Analysis: Analyzing conversations
- Agent Analysis: Analyzing agent behavior
๐งช Agent Types
1. Memory Agents
- Persistent Memory: Memory that persists across sessions
- Context Awareness: Awareness of conversation context
- Memory Retrieval: Retrieving relevant memories
- Memory Updates: Updating memory based on interactions
2. Conversational Agents
- Natural Language: Natural language interaction
- Context Maintenance: Maintaining conversation context
- Response Generation: Generating contextual responses
- Memory Integration: Integrating memory into conversations
3. Multi-Agent Systems
- Agent Coordination: Coordinating multiple agents
- Shared Memory: Sharing memory across agents
- Communication: Inter-agent communication
- Collaboration: Collaborative problem solving
4. Specialized Agents
- Analysis Agent: Specialized in analysis tasks
- Search Agent: Specialized in search tasks
- Calculation Agent: Specialized in calculations
- Creative Agent: Specialized in creative tasks
๐ Usage Examples
Basic Memory Agent
from src.agents.memory_agent import MemoryAgent
# Initialize memory agent
agent = MemoryAgent(
memory_enabled=True,
context_window=10
)
# Start conversation
response = agent.chat("Hello, how are you?")
print(f"Agent response: {response}")
# Continue conversation
response = agent.chat("What did I just say?")
print(f"Agent response: {response}")
Conversational Agent
from src.agents.conversational_agent import ConversationalAgent
# Initialize conversational agent
conversational_agent = ConversationalAgent()
# Start conversation
conversation = conversational_agent.start_conversation()
# Add messages
conversation.add_message("user", "Tell me about AI")
response = conversation.get_response()
print(f"Response: {response}")
Multi-Agent System
from src.agents.multi_agent import MultiAgentSystem
# Initialize multi-agent system
multi_agent = MultiAgentSystem(
agents=["analyst", "researcher", "writer"],
shared_memory=True
)
# Process task
task = "Analyze the latest AI trends"
result = multi_agent.process_task(task)
print(f"Result: {result}")
Memory Analysis
from src.analysis.memory_analyzer import MemoryAnalyzer
# Initialize memory analyzer
analyzer = MemoryAnalyzer()
# Analyze memory usage
analysis = analyzer.analyze_memory(agent.memory)
print(f"Memory analysis: {analysis}")
๐ Advanced Features
1. Memory Compression
- Data Compression: Compressing memory data
- Lossless Compression: Maintaining data integrity
- Adaptive Compression: Adapting compression strategy
- Compression Optimization: Optimizing compression
2. Real-Time Processing
- Streaming Memory: Processing streaming data
- Real-Time Updates: Real-time memory updates
- Live Analysis: Live memory analysis
- Immediate Response: Immediate response to queries
3. Memory Persistence
- Session Persistence: Persisting across sessions
- Data Backup: Backing up memory data
- Recovery: Recovering from failures
- Migration: Migrating memory data
4. Advanced Analysis
- Memory Patterns: Analyzing memory patterns
- Usage Analytics: Analyzing memory usage
- Performance Metrics: Performance metrics
- Optimization Recommendations: Optimization recommendations
๐ ๏ธ Development
Adding New Agent Types
- Create agent class in
src/agents/ - Implement agent interface
- Add memory integration
- Add tests for new agent
- Update documentation
Adding New Memory Types
- Create memory class in
src/memory/ - Implement memory interface
- Add persistence capabilities
- Add tests for new memory
- Update documentation
Custom LangChain Integration
# Add custom LangChain integration
from src.langchain.base_integration import BaseLangChainIntegration
class CustomIntegration(BaseLangChainIntegration):
def __init__(self, config):
super().__init__(config)
def build_chain(self, components):
# Implement custom chain building
## ๐ Theoretical Background
- **Prompt Engineering**: Engineering prompts
- **Workflow Orchestration**: Orchestrating workflows
### Memory Systems
- **Memory Architecture**: Designing memory architectures
- **Memory Management**: Managing memory lifecycle
- **Memory Persistence**: Persisting memory data
- **Memory Analysis**: Analyzing memory usage
### Key Concepts
- **Agent Memory**: Memory for AI agents
- **Conversation Context**: Maintaining conversation context
- **Memory Persistence**: Persisting memory across sessions
- **Multi-Agent Coordination**: Coordinating multiple agents
## ๐ References
### Key Papers
- LangChain: https://python.langchain.com/
- Memory-Augmented Networks: https://arxiv.org/abs/1503.08895
- Conversational AI: https://arxiv.org/abs/2001.09977
### Resources
- LangChain Documentation: https://python.langchain.com/docs/
- Memory Systems: https://en.wikipedia.org/wiki/Memory_hierarchy
- AI Agents: https://en.wikipedia.org/wiki/Intelligent_agent
## ๐ Support
### Issues
- Report bugs via GitHub Issues
- Request features via GitHub Discussions
- Ask questions via GitHub Discussions
### Documentation
- API Documentation: `docs/api/`
- Tutorials: `docs/tutorials/`
- Examples: `examples/`
## ๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
## ๐ Acknowledgments
- LangChain development team
- Memory systems researchers
- AI agent researchers
- Open source libraries and frameworks
---
**Last Updated**: January 2025
**Version**: 1.0.0
**Maintainer**: AI Systems Course Team
Xet Storage Details
- Size:
- 14.7 kB
- Xet hash:
- 37e517c7cd5b7af967e62e480e22cc189f21e2d7607175f0590aecd542e8efb9
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.