Decide Keep, Update or Delete for Existing Memories

You are comparing new content against existing memories to decide how to consolidate them.

For each existing memory, choose one action:
- 'keep': The existing memory is still accurate and not redundant with the new content.
- 'update': The existing memory should be updated with new information. Provide the updated content.
- 'delete': The existing memory is outdated, superseded, or contradicted by the new content.

Also decide whether the new content should be inserted as a separate memory:
- insert_new=true: The new content adds information not fully captured by existing memories (even after updates).
- insert_new=false: The new content is fully captured by the existing memories (after any updates).

Be conservative: prefer 'keep' when unsure. Only 'update' or 'delete' when there is a clear contradiction, supersession, or redundancy.
Works with: Any chat LLM

Extract Reusable Memory Statements From a Conversation

You extract discrete, reusable memory statements from raw content (e.g. a task description and its result, or a conversation between a user and an assistant).

For the given content, output a list of memory statements. Each memory must:
- Be one clear sentence or short statement
- Be understandable without the original context
- Capture a decision, fact, outcome, preference, lesson, or observation worth remembering
- NOT be a vague summary or a restatement of the task description
- NOT duplicate the same idea in different words

When the content is a conversation, pay special attention to facts stated by the user (first-person statements). These personal facts are HIGH PRIORITY and must always be extracted:
- What the user did, bought, made, visited, attended, or completed
- Names of people, pets, places, brands, and specific items the user mentions
- Quantities, durations, dates, and measurements the user states
- Subordinate clauses and casual asides often contain important personal details (e.g. "by the way, it took me 4 hours" or "my Golden Retriever Max")

Preserve exact names and numbers — never generalize (e.g. keep "lavender gin fizz" not just "cocktail", keep "12 largemouth bass" not just "fish caught", keep "Golden Retriever" not just "dog").

Additional extraction rules:
- Presupposed facts: When the user reveals a fact indirectly in a question (e.g. "What collar suits a Golden Retriever like Max?" presupposes Max is a Golden Retriever), extract that fact as a separate memory.
- Date precision: Always preserve the full date including day-of-month when stated (e.g. "February 14th" not just "February", "March 5" not just "March").
- Life events in passing: When the user mentions a life event (birth, wedding, graduation, move, adoption) while discussing something else, extract the life event as its own memory (e.g. "my friend David had a baby boy named Jasper" is a birth fact, even if mentioned while planning to send congratulations).

If there is nothing worth remembering (e.g. empty result, no decisions or facts), return an empty list.
Output a JSON object with a single key "memories" whose value is a list of strings.
Works with: Any chat LLM

Turn a Task Into Memory Search Queries and a Time Filter

You analyze a query for searching memory.
Given the query and available scopes, output:
1. keywords: Key entities or keywords that can be used to filter by category.
2. suggested_scopes: Which available scopes are most relevant (empty for all).
3. complexity: 'simple' or 'complex'.
4. recall_queries: 1-3 short, targeted search phrases distilled from the query. Each should be a concise phrase optimized for semantic vector search. If the query is already short and focused, return it as-is in a single-item list. For long task descriptions, extract the distinct things worth searching for.
5. time_filter: If the query references a time period (like 'last week', 'yesterday', 'in January'), return an ISO 8601 date string for the earliest relevant date (e.g. '2026-02-01'). Return null if no time constraint is implied.
Works with: Any chat LLM

DeerFlow Memory: Consolidate Many Small Facts into Richer Ones

## Memory Consolidation

The following fact categories have accumulated many individual entries.
Review each group and identify facts that can be synthesized into a single,
richer consolidated fact that preserves all key information.

{consolidation_groups}

For each group, decide:
- CONSOLIDATE: Multiple facts can be merged into one richer fact.
  Specify the source fact IDs and the consolidated content.
- SKIP: Facts are distinct enough to remain separate.

Add consolidation decisions to "factsToConsolidate" in your output JSON.
Each entry: {"sourceIds": ["fact_id_1", "fact_id_2"], "consolidated": {"content": "...", "category": "...", "confidence": 0.9, "scope": "user|thread|project", "durability": "durable|temporary", "authority": "descriptive|transactional"}}

Rules:
- The consolidated fact must preserve ALL key details from source facts
- Only consolidate facts that describe the same aspect of the user
- Classify every consolidated fact. It is eligible only when it is user-scoped, durable, descriptive, and safe to inject into unrelated future threads.
- Confidence of consolidated fact = max of source confidences
- Be conservative - when in doubt, keep facts separate
- Maximum {max_groups} consolidation groups per cycle
Works with: Any chat LLM

DeerFlow Memory: Staleness Review (Keep, Remove or Extend Old Facts)

## Staleness Review

The following facts have reached their individual review window and may no longer
accurately reflect the user's current situation. Each entry shows a ``valid:Nd``
annotation - the number of days this fact was expected to remain valid before
re-evaluation. Use it to calibrate conservatism: a ``valid:30d`` fact was
considered volatile at creation; a ``valid:365d`` fact was considered stable.

<stale_facts>
{stale_facts}
</stale_facts>

For each fact, decide KEEP, REMOVE, or EXTEND:
- KEEP: Still likely valid - even if not mentioned in this conversation.
  Stable attributes (native language, core expertise, personality traits) often
  remain true indefinitely.
- REMOVE: Outdated, contradicted by recent context, or no longer relevant.
  Examples: tech-stack migrations, job changes, relocated offices, abandoned projects.
- EXTEND: Keep but recalibrate the review window (see below).

Add REMOVE decisions to "staleFactsToRemove" in your output JSON.
Each entry must be {"id": "fact_id", "reason": "brief explanation"}.
The reason should cite what signal in the conversation (or absence thereof)
supports the removal.

Optionally, for facts you KEEP and wish to recalibrate, add them to
"staleFactsToExtend" with the number of days from now before the next review:
{"id": "fact_id", "extend_by_days": 365, "reason": "brief explanation"}
Use this when the current window seems miscalibrated - e.g. a core skill marked
``valid:30d`` that is clearly stable, or a goal nearing completion whose window
should shrink. Omit facts whose current window already seems appropriate.

Be conservative - when in doubt, KEEP. Removing a valid fact is worse than
keeping a slightly stale one, because the next review cycle will re-evaluate it.
Works with: Any chat LLM

DeerFlow Memory: Extract User Facts from One Message (JSON)

Extract factual information about the user from this message.

Message:
{message}

Extract facts in this JSON format:
{
  "facts": [
    { "content": "...", "category": "preference|knowledge|context|behavior|cognitive|goal|correction", "confidence": 0.0-1.0 }
  ]
}

Categories:
- preference: User preferences (likes/dislikes, styles, tools)
- knowledge: User's expertise or knowledge areas
- context: Background context (location, job, projects)
- behavior: Behavioral patterns
- cognitive: Stable reasoning, response-structure, and collaboration habits
- goal: User's goals or objectives
- correction: Explicit corrections or mistakes to avoid repeating

Rules:
- Only extract clear, specific facts
- Confidence should reflect certainty (explicit statement = 0.9+, implied = 0.6-0.8)
- Skip vague or temporary information

Return ONLY valid JSON.
Works with: Any chat LLM