Skip to main content

Memory

Multi-tiered memory system with short-term, long-term, entity, and user-specific memory.

Quick Start

Usage Forms Table

Presets & Options

URL Schemes

Precedence Ladder

Resolution Order: Instance > Config > Array > Dict > String > Bool > DefaultWhen you pass memory=, the resolver checks in this order:
  1. Instance - MemoryManager instance? Use as-is
  2. Config - MemoryConfig instance? Use as-is
  3. Array - ["preset", {"override": value}]? Apply overrides
  4. Dict - {"key": value}? Convert to config
  5. String - URL or preset? Parse URL or look up preset
  6. Bool - True? Use defaults. False? Disable

Memory Tiers

Classes

MemoryClient

Quality Scoring Functions

compute_quality_score

Calculate overall quality score from individual metrics.

calculate_quality_metrics

Use LLM to evaluate output quality against expectations.

Memory Tiers

1. Short-Term Memory (STM)

  • Purpose: Immediate context and active conversation
  • Storage: SQLite database (.praison/short_term.db)
  • Retention: Ephemeral, cleared between sessions
  • Use Cases: Current task context, recent interactions

2. Long-Term Memory (LTM)

  • Purpose: Persistent knowledge across sessions
  • Storage: SQLite + optional vector store
  • Retention: Permanent with quality filtering
  • Use Cases: Learned facts, important outcomes

3. Entity Memory

  • Purpose: Structured information about entities
  • Storage: Subset of LTM with special formatting
  • Format: Entity {name}({type}): {desc} | relationships: {relations}
  • Use Cases: People, organizations, locations

4. User Memory

  • Purpose: User-specific preferences and history
  • Storage: LTM with user_id filtering
  • Isolation: Strict user separation
  • Use Cases: Personalization, preferences

Configuration

Basic Configuration

Advanced Configuration with Graph Support

Graph Database Options

Neo4j Configuration

Memgraph Configuration

Quick Start

1
Install with memory support
2
Basic memory usage
3
Advanced graph memory

Configuration

Basic Configuration

Advanced Configuration

Memory Types

API Reference

Constructor

Core Methods

add()

Store information in memory with optional quality scoring.
Parameters:
  • text - Content to store
  • memory_type - Type: “short”, “long”, “entity”, or “user”
  • quality_score - Quality rating (0.0-1.0, auto-calculated if None)
  • metadata - Additional metadata
Search across all memory types for relevant information.
Returns list of:

update()

Update an existing memory entry.

delete()

Delete a specific memory entry.

Context Building

build_context_for_task()

Build formatted context for a specific task.
Example output:

get_context()

Get all memories formatted as context.

Quality Management

calculate_quality_score()

Calculate quality score for a memory entry.
Scoring factors:
  • Information density
  • Specificity
  • Relevance indicators
  • Entity mentions
  • Temporal relevance

get_quality_memories()

Retrieve only high-quality memories.

Utility Methods

get_memories()

Retrieve raw memories from storage.

clear()

Clear all memories of a specific type.
Options: “short”, “long”, “entity”, “user”, “all”

get_stats()

Get memory system statistics.
Returns:

Usage Examples

Basic Memory Operations

Quality-Based Storage

Entity Memory Management

Agent Integration

Graph-Enhanced Memory

Quality Metrics

Completeness (0-1)

How thoroughly the content addresses the requirements.

Relevance (0-1)

How well the content matches the expected output.

Clarity (0-1)

How clear and well-structured the content is.

Accuracy (0-1)

Factual correctness of the information.

Custom Weights

Best Practices

  1. Use Quality Filtering - Set appropriate min_quality thresholds
  2. Scope Memories - Use user_id and agent_id for proper isolation
  3. Regular Cleanup - Clear short-term memory between sessions
  4. Graph for Relationships - Use graph stores for complex entity relationships
  5. Monitor Storage - Check database sizes periodically
  6. Test Retrieval - Verify context building produces relevant results =======

Basic Memory Usage

Quality-Based Storage

Graph Memory Example

Multi-Agent Memory Sharing

Best Practices

Memory Type Selection

Short-term: Conversation context, temporary state Long-term: Facts, preferences, important information Entity: People, places, organizations, relationships User: Personal data, settings, history

Quality Management

  • Set appropriate quality thresholds (0.7-0.8 recommended)
  • Manually score critical information higher
  • Periodically review and clean low-quality memories
  • Use quality scores for retrieval filtering

Performance Optimization

  • Limit memory searches to necessary types
  • Use appropriate search limits
  • Clear short-term memory periodically
  • Index frequently accessed memories

Privacy & Security

  • Separate user memories by user_id
  • Avoid storing sensitive data in plain text
  • Implement access controls for shared memory
  • Regular cleanup of old user data

Provider Comparison

Troubleshooting

Common Issues:

Advanced Configuration

Custom Quality Scoring

Memory Middleware

Summary

The Memory module provides a comprehensive solution for agent memory management: Multi-tiered Architecture - Different memory types for different needs
Quality Management - Automatic scoring and filtering
Graph Support - Complex relationship mapping with Neo4j/Memgraph
Flexible Storage - Multiple backend options
Context Building - Automatic context generation for tasks
Perfect for building agents that:
  • Maintain conversation context
  • Remember user preferences
  • Track entity relationships
  • Build knowledge over time