Skip to main content
DeerFlow’s memory system enables agents to remember user preferences, context, and conversation history across sessions. The system automatically extracts, stores, and injects relevant facts into agent prompts.

Overview

The memory system provides:

Fact Extraction

Automatically extracts key facts from conversations using LLM analysis

Persistent Storage

Stores facts in JSON format with confidence scores and timestamps

Context Injection

Intelligently injects relevant facts into agent system prompts

Debounced Updates

Batches updates to reduce LLM calls and improve performance

Configuration

Memory is configured in the memory section of config.yaml:
config.yaml

Configuration Options

boolean
default:"true"
Whether to enable the memory system globally.Set to false to disable memory extraction and injection.
string
default:"memory.json"
Path to store memory data.Path Resolution:
  • Empty string ("") → {DEER_FLOW_HOME}/memory.json (default)
  • Relative path → {DEER_FLOW_HOME}/{storage_path}
  • Absolute path → Used as-is
Where DEER_FLOW_HOME is:
  1. DEER_FLOW_HOME environment variable, or
  2. .deer-flow/ in backend directory (dev mode), or
  3. ~/.deer-flow/ (default)
Migration Note: If you previously set storage_path: .deer-flow/memory.json, it will now resolve to {DEER_FLOW_HOME}/.deer-flow/memory.json. Use an absolute path to preserve the old location.
integer
default:"30"
Seconds to wait before processing queued memory updates.How it works:
  • Memory updates are queued during conversation
  • After debounce_seconds of inactivity, updates are batched and processed
  • Reduces LLM calls and API costs
Tuning:
  • Lower values (10-30s) → More frequent updates, higher costs
  • Higher values (60-300s) → Less frequent updates, lower costs
string
default:"null"
Model to use for memory extraction and updates.
  • null → Uses the default model (first in models list)
  • Specify model name → Uses that configured model
Recommendation: Use a lightweight, cost-effective model like gpt-4o-mini for memory operations.
integer
default:"100"
Maximum number of facts to store in memory.When the limit is reached:
  • Oldest facts (by timestamp) are removed first
  • Or lowest confidence facts if timestamps are equal
float
default:"0.7"
Minimum confidence score (0.0-1.0) required to store a fact.Facts with confidence below this threshold are discarded.Tuning:
  • Higher values (0.8-1.0) → Only high-confidence facts stored
  • Lower values (0.5-0.7) → More facts stored, potentially less accurate
boolean
default:"true"
Whether to inject memory facts into agent system prompts.Set to false to store facts without injecting them (passive mode).
integer
default:"2000"
Maximum tokens to use for memory injection in system prompts.Facts are prioritized by confidence and recency, then truncated to fit this limit.Tuning:
  • Lower values (500-1000) → Only highest priority facts injected
  • Higher values (2000-4000) → More comprehensive context

Storage Format

Memory is stored as JSON with the following structure:
memory.json

Fact Fields

  • content: The extracted fact as a natural language statement
  • confidence: Confidence score (0.0-1.0) assigned by the LLM
  • timestamp: ISO 8601 timestamp when the fact was extracted
  • source: Source of the fact (typically "conversation")

How Memory Works

1

Conversation Analysis

As the user interacts with the agent, conversation messages are analyzed for extractable facts.
2

Fact Extraction

The memory system uses an LLM to extract key facts:
  • User preferences and habits
  • Project information
  • Technical context
  • Personal details (when relevant)
3

Confidence Scoring

Each extracted fact is assigned a confidence score:
  • 0.9-1.0: Explicit statements (“I prefer X”)
  • 0.7-0.9: Strong inference (“I always use X”)
  • 0.5-0.7: Weak inference (“I might use X”)
  • Below 0.5: Discarded (below threshold)
4

Debounced Storage

Facts are queued and stored after debounce_seconds of inactivity to batch updates.
5

Fact Pruning

If max_facts is exceeded:
  • Sort facts by timestamp (oldest first)
  • Remove oldest facts until within limit
  • Optionally consider confidence scores
6

Context Injection

When injection_enabled is true:
  • Top facts (by confidence and recency) are selected
  • Facts are formatted and injected into the system prompt
  • Injection is truncated to max_injection_tokens

Memory Injection Format

When memory is injected into the agent’s system prompt:
The exact injection format is determined by the agent’s prompt template. The above is an example.

Configuration Examples

Minimal Memory (Cost-Optimized)

For minimal API usage:

Comprehensive Memory

For maximum context retention:

Memory Without Injection

Store facts but don’t inject them (for analysis only):

Custom Storage Location

Per-User Memory

For multi-tenant setups, use environment variables:

Programmatic Access

Access memory configuration in Python:

Update Configuration at Runtime

Best Practices

Memory operations don’t need powerful models. Use a cost-effective model:
  • Interactive applications: 30-60 seconds
  • Long-running tasks: 120-300 seconds
  • Cost-sensitive: Higher values
  • Personal assistant: 100-200 facts
  • Project-specific agent: 200-500 facts
  • Multi-user system: Separate memory files per user
Regularly check memory file size:
If too large, reduce max_facts or increase fact_confidence_threshold.
Memory files contain valuable context. Back them up regularly:

Memory Lifecycle

Troubleshooting

Check storage path and permissions:
Adjust fact_confidence_threshold:
Tune debounce_seconds:
Reduce max_injection_tokens:

Next Steps

Environment Variables

Configure environment variables

Agent Customization

Customize agent behavior