claw-reflect is the autonomous memory distillation engine in the ClawDB ecosystem. It ingests raw memories generated by agents, runs multi-stage reflection pipelines, updates long-term profiles, and continuously decays stale knowledge so retrieval quality stays high over time.
Raw memories
-> [Scorer -> Duplicate Collapser -> Contradiction Detector -> Summariser -> Preference Extractor -> Promoter]
-> AgentProfile + Scored Memories
<- Decay Engine
- Composite scoring computes importance, recency, and confidence.
- Duplicate collapse removes semantically redundant records.
- Contradiction detector flags conflicts for resolution.
- Summariser compresses session/message/context chunks.
- Preference extractor writes durable preferences.
- Promoter upgrades high-value memories.
- Decay engine lowers stale memory scores outside reflection runs.
Supported providers:
- Anthropic
- OpenAI-compatible APIs
- Ollama (local)
Set via environment:
REFLECT_LLM_PROVIDER=anthropic|openai|ollamaREFLECT_LLM_MODEL=<model-name>REFLECT_LLM_API_KEY=<key>(required except Ollama can use placeholder)REFLECT_LLM_BASE_URL=<optional endpoint override>
- Start stack:
docker-compose up --build- Ingest memories:
/Users/ginmax/claw-reflect/.venv/bin/python scripts/create_api_key.py \
--workspace-id 00000000-0000-0000-0000-000000000001 \
--label local-dev
curl -X POST http://localhost:8090/api/v1/reflect/memories \
-H 'X-Claw-Api-Key: <printed-key>' \
-H 'Content-Type: application/json' \
-d '{
"agent_id": "agent_1",
"batch_id": "batch_1",
"memories": [{
"id": "MEM0000000000000000000001",
"agent_id": "agent_1",
"content": "User prefers concise bullet points.",
"memory_type": "message",
"metadata": {"session_id": "s1"},
"tags": ["style"],
"created_at": "2026-05-02T00:00:00Z",
"updated_at": "2026-05-02T00:00:00Z"
}]
}'- Trigger reflection:
curl -X POST http://localhost:8090/api/v1/reflect/trigger \
-H 'X-Claw-Api-Key: <printed-key>' \
-H 'Content-Type: application/json' \
-d '{"agent_id":"agent_1","job_type":"full","options":{}}'All non-health API routes under /api/v1 require X-Claw-Api-Key.
Only GET /api/v1/health, GET /api/v1/ready, and GET /api/v1/metrics are intentionally unauthenticated.
Health:
GET /api/v1/healthGET /api/v1/readyGET /api/v1/metrics
Reflection:
POST /api/v1/reflect/triggerPOST /api/v1/reflect/trigger/dry-runPOST /api/v1/reflect/memoriesPOST /api/v1/reflect/score/{agent_id}POST /api/v1/reflect/decay/{agent_id}GET /api/v1/reflect/preview/{agent_id}
Jobs:
GET /api/v1/jobs/{job_id}GET /api/v1/jobsDELETE /api/v1/jobs/{job_id}GET /api/v1/jobs/scheduled
Profiles:
GET /api/v1/profiles/{agent_id}GET /api/v1/profiles/{agent_id}/preferencesPUT /api/v1/profiles/{agent_id}/preferences/{pref_id}GET /api/v1/profiles/{agent_id}/contradictionsPOST /api/v1/profiles/{agent_id}/contradictions/{contradiction_id}/resolveGET /api/v1/profiles/{agent_id}/memories
- Increase worker concurrency: set
--concurrencyonreflect-worker. - Horizontal scale: run multiple worker replicas behind same Redis broker.
- Keep
task_acks_late=trueandworker_prefetch_multiplier=1to reduce task loss and avoid hot-worker starvation. - Use queue routing by pipeline stage if throughput grows.
Exponential:
Linear:
Step:
Apply first matching threshold from configured steps:
(7, 0.9)(30, 0.6)(90, 0.3)(365, 0.05)
| Variable | Description | Example |
|---|---|---|
REFLECT_DATABASE_URL |
SQLAlchemy async DB URL | postgresql+asyncpg://<user>:<password>@postgres:5432/<db> |
REFLECT_REDIS_URL |
Redis broker/backend URL | redis://redis:6379/0 |
REFLECT_CELERY_CONCURRENCY |
Celery worker concurrency | 4 |
REFLECT_LLM_PROVIDER |
LLM provider name | anthropic |
REFLECT_LLM_MODEL |
Provider model identifier | claude-sonnet-4-20250514 |
REFLECT_LLM_API_KEY |
LLM API key secret | sk-... |
REFLECT_LLM_BASE_URL |
Custom provider endpoint | http://localhost:11434 |
REFLECT_LLM_MAX_TOKENS |
Max output tokens per call | 2048 |
REFLECT_LLM_TIMEOUT_SECS |
Request timeout | 30 |
REFLECT_LLM_MAX_RETRIES |
LLM retry attempts | 3 |
REFLECT_REFLECTION_BATCH_SIZE |
Pipeline batch size | 50 |
REFLECT_REFLECTION_INTERVAL_MINUTES |
Reflection schedule interval | 30 |
REFLECT_DECAY_INTERVAL_HOURS |
Decay schedule interval | 6 |
REFLECT_SCORE_REFRESH_INTERVAL_HOURS |
Score refresh interval | 12 |
REFLECT_IMPORTANCE_WEIGHT |
Composite importance weight | 0.4 |
REFLECT_RECENCY_WEIGHT |
Composite recency weight | 0.35 |
REFLECT_CONFIDENCE_WEIGHT |
Composite confidence weight | 0.25 |
REFLECT_DEFAULT_DECAY_POLICY |
Default decay policy | exponential |
REFLECT_DECAY_HALF_LIFE_DAYS |
Exponential half life | 30 |
REFLECT_ARCHIVE_THRESHOLD_SCORE |
Archive threshold | 0.05 |
REFLECT_MIN_SCORE_TO_KEEP |
Hard cleanup cutoff | 0.02 |
REFLECT_DUPLICATE_SIMILARITY_THRESHOLD |
Duplicate decision threshold | 0.92 |
REFLECT_API_HOST |
API bind host | 0.0.0.0 |
REFLECT_API_PORT |
API bind port | 8090 |
REFLECT_DEBUG |
Enables docs and debug settings | false |
REFLECT_LOG_LEVEL |
Log level | INFO |
REFLECT_LOG_FORMAT |
json or console |
json |