agents.memory_reorganizedΒΆ
Unified Memory System for Haive Agents.
This module provides a comprehensive, reorganized memory architecture that combines graph-based knowledge management, in-memory reorganization, and intelligent retrieval patterns for sophisticated AI agent memory capabilities.
- Core Architecture:
The memory system is built on three foundational pillars:
Graph-Based Memory: Uses Neo4j knowledge graphs for entity relationship modeling, semantic connections, and traversal-based retrieval patterns.
In-Memory Reorganization: Implements dynamic memory consolidation, importance scoring, and intelligent memory lifecycle management.
Multi-Modal Retrieval: Combines vector similarity, graph traversal, temporal relevance, and importance weighting for comprehensive recall.
System Components:
- Core Agents:
SimpleMemoryAgent: Basic memory operations with token awareness
ReactMemoryAgent: Reasoning loop with memory context integration
MultiMemoryAgent: Coordinated multi-agent memory management
LongTermMemoryAgent: Persistent memory with consolidation patterns
- Retrieval Systems:
GraphRAGRetriever: Graph RAG combining knowledge traversal with vector search
EnhancedMemoryRetriever: Self-query retriever with memory-aware context
QuickSearchAgent: Fast semantic search for immediate recall
ProSearchAgent: Deep search with relationship analysis
- Knowledge Management:
KGGeneratorAgent: Automatic knowledge graph construction
IntegratedMemorySystem: Unified coordination of memory subsystems
MemoryClassifier: LLM-based memory type classification
- Coordination & Orchestration:
MultiAgentCoordinator: Multi-agent memory coordination patterns
AgenticRAGCoordinator: RAG workflow orchestration
UnifiedMemoryAPI: Single interface for all memory operations
- Memory Types Supported:
SEMANTIC: Facts, concepts, definitions, general knowledge
EPISODIC: Specific events, personal experiences, conversations
PROCEDURAL: How-to knowledge, processes, workflows
CONTEXTUAL: Relationships between entities, social connections
PREFERENCE: User likes, dislikes, behavioral patterns
META: Self-awareness, learning patterns, thoughts about thinking
EMOTIONAL: Feelings, sentiments, emotional context
TEMPORAL: Time-based patterns, scheduling, temporal relationships
ERROR: Mistakes, corrections, error patterns for learning
FEEDBACK: User corrections, evaluations, system improvements
- Graph-Based Memory Features:
Entity-Relationship Modeling: Automatic extraction and linking
Semantic Traversal: Graph walks for contextual retrieval
Centrality Scoring: Importance based on graph position
Multi-Hop Reasoning: Complex relationship inference
Dynamic Graph Updates: Real-time knowledge graph evolution
- In-Memory Reorganization Capabilities:
Memory Consolidation: Merge similar memories, reduce redundancy
Importance Scoring: Multi-factor relevance calculation
Temporal Decay: Automatic importance adjustment over time
Access Pattern Learning: Adapt to user interaction patterns
Memory Lifecycle Management: Automatic archival and cleanup
Examples
Basic memory agent with automatic classification:
from haive.agents.memory_reorganized import SimpleMemoryAgent
# Create agent with automatic memory classification
agent = SimpleMemoryAgent(
name="assistant",
memory_config={
"enable_classification": True,
"store_type": "chroma"
}
)
# Store memory with automatic type detection
await agent.store_memory("I learned Python at university in 2020")
# -> Automatically classified as EPISODIC + EDUCATION
# Retrieve with memory-aware context
results = await agent.retrieve_memories("programming experience")
# -> Returns memories with relevance scores
Advanced Graph RAG retrieval:
from haive.agents.memory_reorganized.retrieval import GraphRAGRetriever
from haive.agents.memory_reorganized.knowledge import KGGeneratorAgent
# Setup Graph RAG with knowledge graph
kg_agent = KGGeneratorAgent(neo4j_config=neo4j_config)
retriever = GraphRAGRetriever(
kg_agent=kg_agent,
vector_store=chroma_store,
enable_graph_traversal=True
)
# Retrieve with graph context
result = await retriever.retrieve_memories(
"What's the relationship between Python and machine learning?"
)
print(f"Found {len(result.memories)} memories")
print(f"Explored {result.graph_nodes_explored} entities")
print(f"Relationship paths: {len(result.relationship_paths)}")
Integrated memory system with multi-modal retrieval:
from haive.agents.memory_reorganized.coordination import IntegratedMemorySystem
# Configure multi-modal memory system
memory_system = IntegratedMemorySystem(
mode="INTEGRATED", # Graph + Vector + Time-based
graph_config=graph_config,
vector_config=vector_config,
enable_consolidation=True,
enable_importance_scoring=True
)
# Store with automatic processing
await memory_system.store_memory(
"I prefer morning meetings because I'm most productive then",
user_context={"user_id": "alice", "timezone": "EST"}
)
# -> Classified as PREFERENCE + TEMPORAL
# -> Entities extracted: ["meetings", "morning"]
# -> Graph relationships created
# Query with intelligent routing
results = await memory_system.query_memory(
"scheduling preferences",
max_results=10,
include_graph_context=True
)
Multi-agent coordination with shared memory:
from haive.agents.memory_reorganized.coordination import MultiAgentCoordinator
from haive.agents.memory_reorganized import (
SimpleMemoryAgent, ReactMemoryAgent
)
# Create specialized memory agents
fact_agent = SimpleMemoryAgent(name="facts", memory_types=["SEMANTIC"])
conversation_agent = ReactMemoryAgent(
name="conversations",
memory_types=["EPISODIC", "EMOTIONAL"]
)
# Coordinate with shared memory store
coordinator = MultiAgentCoordinator(
agents=[fact_agent, conversation_agent],
shared_memory_store=shared_store,
routing_strategy="memory_type_aware"
)
# Route queries to appropriate agents
result = await coordinator.query(
"What did I learn about Python yesterday?"
# -> Routes to conversation_agent for EPISODIC recall
)
- Performance Characteristics:
Memory Storage: 100-1000 memories/second (depending on classification depth)
Graph Traversal: <50ms for 2-hop queries, <200ms for 3-hop queries
Vector Retrieval: <10ms for similarity search (1M+ vectors)
Classification: 50-200ms per memory (depending on LLM speed)
Consolidation: Background process, minimal impact on queries
- Integration Patterns:
Standalone Agents: Drop-in memory enhancement for existing agents
Pipeline Integration: Memory stages in LangGraph workflows
Multi-Agent Systems: Shared memory across agent teams
External Systems: Integration with LangMem, DeepSeek, custom stores
- Architecture Benefits:
Unified Interface: Single API for all memory operations
Modular Design: Mix and match components as needed
Scalable Storage: Support for enterprise-scale memory systems
Real-Time Learning: Continuous improvement from user interactions
Context Preservation: Maintain rich context across long conversations