ContextWorker is the Background Processing Engine of the ContextUnity ecosystem. Temporal is the primary durable workflow backend; Huey (engines/huey_engine.py) supports lightweight local/Redis queues when Temporal is unavailable.
Worker contains NO business logic. It provides infrastructure only.
- Durable Workflows — Temporal processes that survive restarts and failures
- Scheduled Jobs — cron-based recurring tasks registered by project manifests or plugins
- gRPC Service — trigger workflows from other services via ContextUnit protocol
- Orchestration — durable execution of registered tools and Router graphs
# Start gRPC service
export TEMPORAL_HOST="localhost:7233"
uv run python -m contextunity.worker
# Start Temporal worker
uv run python -m contextunity.worker --temporal
# Inspect schedules
uv run python -m contextunity.worker.schedules list
# Run tests
uv run --package contextunity-worker pytestsrc/contextunity/worker/
├── __main__.py # Entrypoint
├── cli.py # CLI commands (Typer)
├── config.py # WorkerConfig (Pydantic)
├── service.py # gRPC WorkerService (4 RPCs)
├── server.py # gRPC server bootstrap
├── schemas.py # Shared payload schemas
├── interceptors.py # Worker permission interceptor
├── schedules.py # Temporal schedule management
├── core/
│ ├── registry.py # WorkerRegistry, plugin discovery
│ ├── worker.py # Temporal client setup
│ ├── worker_sdk.py # Worker-side helper utilities
│ ├── brain_token.py # Brain token helpers
│ └── tenant_gate.py # Shared Worker tenant allowlist policy
├── engines/ # Pluggable execution backends
│ ├── temporal_engine.py # Temporal engine
│ └── huey_engine.py # Huey engine
└── jobs/
├── orchestrator.py # Generic local-tool / Router-graph orchestration
├── memory_synthesis.py # Phase 3 MemorySynthesisWorkflow entrypoint
├── memory_synthesis_contracts.py
├── memory_synthesis_extract.py
├── memory_synthesis_observer.py
├── memory_synthesis_runtime.py
└── retention.py # Fail-closed tombstone for the removed legacy job
| Variable | Default | Description |
|---|---|---|
TEMPORAL_HOST |
localhost:7233 |
Temporal server address |
TEMPORAL_NAMESPACE |
default |
Temporal namespace |
WORKER_PORT |
50052 |
gRPC server port |
CU_BRAIN_GRPC_URL |
localhost:50051 |
Brain gRPC endpoint |
WORKER_MODULES |
`` | Extra worker module import paths |
WORKER_ENGINE |
temporal |
Execution backend (temporal or huey) |
WORKER_TENANTS |
`` | Required comma-separated tenant allowlist for embedding jobs and Memory Synthesis writes |
WORKER_MEMORY_SYNTHESIS_ENABLED |
false |
Enables fail-closed MemorySynthesisWorkflow batches; embedding enrichment must also be enabled |
WORKER_MEMORY_SYNTHESIS_TRIGGER_MODE |
admin |
Allowed synthesis trigger: scheduled, threshold, or admin |
WORKER_MEMORY_SYNTHESIS_BATCH_SIZE |
100 |
Maximum old conversation records per synthesis batch |
WORKER_MEMORY_SYNTHESIS_SCHEDULE_CRON |
0 * * * * |
Temporal schedule used by scheduled and threshold modes |
WORKER_MEMORY_SYNTHESIS_THRESHOLD_CONVERSATION_RECORDS |
1000 |
Minimum Conversation History backlog before a threshold run proceeds |
WORKER_MEMORY_SYNTHESIS_DLQ_PATH |
.contextunity/dlq/memory_synthesis.jsonl |
Local DLQ-0 envelope path; runtime requests cannot override it |
WORKER_MEMORY_SYNTHESIS_ENQUEUE_CONCURRENCY |
4 |
Maximum concurrent BrainCell upsert/enqueue operations in one synthesis batch |
WORKER_MEMORY_SYNTHESIS_OBSERVABILITY_ENABLED |
false |
Enables one bounded Brain Execution Trace per admitted synthesis run |
WORKER_MEMORY_SYNTHESIS_UDB_ENABLED |
false |
Reports only failed/degraded synthesis runs to UDB; requires observability |
WORKER_MEMORY_SYNTHESIS_OBSERVER_MAX_ATTEMPTS |
2 |
Idempotent Trace/UDB delivery attempts, bounded to 1–3 |
WORKER_MEMORY_SYNTHESIS_MAX_TRACE_STEPS |
16 |
Closed lifecycle-step ceiling, bounded to 9–16 |
WORKER_EMBEDDING_ENRICHMENT_ENABLED |
false |
Enables durable Brain embedding job consumption and is required by Memory Synthesis |
LOG_LEVEL |
INFO |
Log level |
- Full Documentation: ContextWorker on Astro Site
- Agent Boundaries & Golden Paths: AGENTS.md
- Temporal Documentation: docs.temporal.io
This project is licensed under the terms specified in LICENSE.md.
Autonomous Worker jobs use the same bootstrap flow as Router registration.
Set CU_MANIFEST_PATH, CU_PROJECT_SECRET, CU_SHIELD_GRPC_URL, and an
explicit WORKER_TENANTS allowlist. Worker resolves project identity and
services.shield.enabled from the validated manifest, then exchanges the HMAC
bootstrap proof for a policy-bounded Shield Ed25519 session. Subsequent Brain
token attenuation and renewal use Shield. Missing manifest, configuration, or
policy fails closed.