Patterns & Recipes

Common patterns for building production-grade agent memory systems.

RAG pipeline with memory context

Augment LLM prompts with recalled memories for grounded responses. Store conversation history, recall relevant context before each generation:

# 1. Store a memory from conversation
curl -X POST http://localhost:3300/v1/memories \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "assistant",
    "content": "User prefers dark mode and concise responses",
    "importance": 0.8,
    "tags": ["preference"]
  }'

# 2. Before generating a response, recall relevant context
curl -X POST http://localhost:3300/v1/memories/recall \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "assistant",
    "query": "What does the user prefer?",
    "top_k": 5
  }'

# 3. Inject recalled memories into your system prompt
# system_prompt = f"Context from memory:\n{memories}\n\nRespond to the user."

Conversation memory

Store and recall multi-turn conversation context. Use sessions to group memories by conversation thread:

# Start a session
curl -X POST http://localhost:3300/v1/sessions \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "chat-agent", "metadata": {"user": "u_123", "channel": "web"}}'

# Store each turn with the session
curl -X POST http://localhost:3300/v1/memories \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "chat-agent",
    "session_id": "sess_abc123",
    "content": "User asked about billing. Explained monthly vs annual pricing.",
    "importance": 0.7,
    "memory_type": "episodic"
  }'

# End session with summary
curl -X POST http://localhost:3300/v1/sessions/sess_abc123/end \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"summary": "Discussed billing options. User chose annual plan."}'

Task memory with TTL

Short-lived memories that auto-expire. Use expires_at (Unix timestamp) for task-scoped context that shouldn't persist after completion:

curl -X POST http://localhost:3300/v1/memories \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "task-agent",
    "content": "Working on PR #123 — fixing auth middleware",
    "importance": 0.3,
    "expires_at": 1778800000,
    "tags": ["ephemeral", "task"],
    "metadata": {"pr": 123, "repo": "backend"}
  }'
Decay vs TTL — Decay gradually reduces importance over time (configurable strategy). TTL hard-deletes the memory at the timestamp. Use TTL for task context; use decay for long-term memories that should fade naturally.

Knowledge base construction

Build a structured knowledge base using entities and the knowledge graph. Store facts, extract entities, then link related knowledge:

# Store a fact with entity extraction enabled
curl -X POST http://localhost:3300/v1/memories \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "kb-builder",
    "content": "React 19 introduces use() hook for async data fetching. Released January 2025.",
    "importance": 0.9,
    "memory_type": "semantic",
    "tags": ["react", "frontend"]
  }'

# Extract entities from stored memories
curl -X POST http://localhost:3300/v1/entities/extract \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "kb-builder"}'

# Query the knowledge graph for related knowledge
curl -X POST http://localhost:3300/v1/knowledge/graph \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "kb-builder", "query": "React hooks", "depth": 2}'

Agent wake-up context

Load an agent's full context on startup using batch recall with filters. Common pattern for scheduled agents or those waking from idle:

# Recall high-importance recent memories
curl -X POST http://localhost:3300/v1/memories/recall/batch \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent",
    "min_importance": 0.7,
    "created_after": 1778000000,
    "tags": ["critical", "decision"]
  }'

# Also recall blockers and pending handoffs
curl -X POST http://localhost:3300/v1/memories/recall/batch \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent",
    "tags": ["blocker", "handoff"],
    "min_importance": 0.5
  }'

# Get agent stats to assess memory health
curl http://localhost:3300/v1/agents/my-agent/stats \
  -H "Authorization: Bearer $DAKERA_API_KEY"

Memory consolidation pipeline

Periodically merge redundant memories and deduplicate knowledge. Run this in a cron or after intensive sessions:

# Consolidate (merge similar memories)
curl -X POST http://localhost:3300/v1/knowledge/consolidate \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent"}'

# Deduplicate (remove exact/near duplicates)
curl -X POST http://localhost:3300/v1/knowledge/deduplicate \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent", "similarity_threshold": 0.95}'

# Summarize old memories into compressed form
curl -X POST http://localhost:3300/v1/knowledge/summarize \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent", "older_than_days": 30}'

Hybrid search patterns

Combine vector (semantic) and full-text (keyword) search for best results. Choose the mode based on your query type:

PatternModeWhen to use
Semantic recallrouting_mode: "vector"Meaning-based — "what does the user prefer?"
Keyword lookuprouting_mode: "bm25"Exact terms — error codes, IDs, names
Hybrid (default)routing_mode: "hybrid"Best of both — general-purpose recall
# Hybrid search with custom weights
curl -X POST http://localhost:3300/v1/memories/recall \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent",
    "query": "authentication error ERR_AUTH_401",
    "routing_mode": "hybrid",
    "top_k": 10
  }'

# Full-text search for exact terms
curl -X POST http://localhost:3300/v1/fulltext/search \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent", "query": "ERR_AUTH_401", "limit": 5}'

Cross-agent knowledge network

By default, agents are isolated. To share knowledge across agents, use the cross-agent knowledge network:

# Query memory across multiple agents
curl -X POST http://localhost:3300/v1/knowledge/network/cross-agent \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_ids": ["agent-a", "agent-b", "supervisor"],
    "query": "user preferences",
    "top_k": 5
  }'

# Link memories across agents in the knowledge graph
curl -X POST http://localhost:3300/v1/knowledge/graph/link \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "source_memory_id": "mem_abc",
    "target_memory_id": "mem_xyz",
    "edge_type": "RelatedTo",
    "weight": 0.9
  }'

Memory feedback loop

Use feedback to train the retrieval engine. Upvote useful memories, downvote irrelevant ones — Dakera uses this signal to improve future recall:

# Upvote a memory that was useful
curl -X POST http://localhost:3300/v1/memories/mem_abc/feedback \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"feedback_type": "upvote", "context": "Correctly recalled user preference"}'

# Downvote an irrelevant result
curl -X POST http://localhost:3300/v1/memories/mem_xyz/feedback \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"feedback_type": "downvote", "context": "Not relevant to current task"}'

# Get feedback summary for an agent
curl http://localhost:3300/v1/agents/my-agent/feedback/summary \
  -H "Authorization: Bearer $DAKERA_API_KEY"

Migration from Mem0 / Zep

Import existing memories from other memory systems. Dakera supports Mem0, Zep, JSONL, and CSV formats:

# Export from your current system to JSONL, then import
curl -X POST http://localhost:3300/v1/memories/import \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent",
    "format": "mem0",
    "data": [
      {"memory": "User prefers dark mode", "metadata": {"category": "preference"}},
      {"memory": "Last discussed billing on March 5", "metadata": {"category": "event"}}
    ]
  }'

# Export from Dakera (for backup or migration)
curl -X POST http://localhost:3300/v1/memories/export \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent", "format": "jsonl"}'
Supported formatsmem0, zep, jsonl, csv. Entity relationships and metadata are preserved during import.

Namespace isolation for multi-tenant apps

Use namespaces to isolate memory per tenant, team, or environment. Each namespace has its own API keys and memory space:

# Create a namespace for a tenant
curl -X POST http://localhost:3300/v1/namespaces \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "tenant-acme", "description": "Acme Corp workspace"}'

# Create a scoped API key for that namespace
curl -X POST http://localhost:3300/v1/namespaces/tenant-acme/keys \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "acme-prod-key", "permissions": ["read", "write"]}'

# Use the scoped key — only accesses tenant-acme memories
curl -X POST http://localhost:3300/v1/memories \
  -H "Authorization: Bearer $ACME_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "acme-bot", "content": "Acme user prefers metric units"}'

Real-time event streaming

Subscribe to memory lifecycle events via SSE (Server-Sent Events). Useful for dashboards, audit trails, and reactive agent architectures:

# Stream all memory events for an agent
curl -N http://localhost:3300/v1/events/stream?agent_id=my-agent \
  -H "Authorization: Bearer $DAKERA_API_KEY"

# Events arrive as SSE:
# data: {"event":"memory.created","memory_id":"mem_abc","agent_id":"my-agent","timestamp":1778800000}
# data: {"event":"memory.updated","memory_id":"mem_abc","field":"importance","old":0.5,"new":0.8}
# data: {"event":"memory.decayed","memory_id":"mem_xyz","new_importance":0.12}
# data: {"event":"memory.deleted","memory_id":"mem_xyz","reason":"expired"}

Audit logging & compliance

Track all memory operations for compliance. The audit API provides a queryable log of every create, read, update, and delete:

# Query audit log for a specific agent
curl -X POST http://localhost:3300/v1/audit/query \
  -H "Authorization: Bearer $DAKERA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent",
    "event_types": ["memory.created", "memory.deleted"],
    "start_time": 1778000000,
    "end_time": 1778800000,
    "limit": 100
  }'

Production deployment checklist

Before going live, verify these operational concerns:

CheckCommand / verification
Health endpointcurl http://host:3300/health{"status":"healthy"}
API key setDAKERA_ROOT_API_KEY is a strong, unique value
Persistent storageData volume mounted: -v dakera_data:/data
Backup configuredS3/MinIO backup: POST /v1/admin/backup/create
AutoPilot enabledDAKERA_AUTOPILOT=true — runs dedup + consolidation + decay
Entity extractionGLiNER model downloaded — check with /v1/entities/types
Namespace isolationCreate per-tenant namespaces; never share the root key
MonitoringGET /v1/admin/monitoring — verify metrics collection
Resource limitsSet DAKERA_HNSW_CACHE_MAX, Docker memory limits
TLS terminationUse a reverse proxy (nginx, Caddy) for HTTPS in production