835 MB
10,492 files
Updated 6 months ago
README.md

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

  1. Clone the repository
git clone <repository-url>
cd CA21_langchain_memory_agents
  1. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. 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

  1. Create agent class in src/agents/
  2. Implement agent interface
  3. Add memory integration
  4. Add tests for new agent
  5. Update documentation

Adding New Memory Types

  1. Create memory class in src/memory/
  2. Implement memory interface
  3. Add persistence capabilities
  4. Add tests for new memory
  5. 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
Total size
835 MB
Files
10,492
Last updated
Jun 17
Pre-warmed CDN
US EU US EU

Contributors