Skip to content

ContextWorker

ContextWorker is the “Hands” of the ContextUnity ecosystem. It provides durable workflow infrastructure, scheduled jobs, and sub-agent execution — all built on Temporal.io.

Durable Workflows

Temporal.io workflows that survive restarts and failures, with automatic retries and state persistence.

Scheduled Jobs

Cron-based recurring tasks — harvesting, enrichment, catalog sync, data retention.

gRPC Service

Trigger and monitor workflows from other services via ContextUnit protocol.

Sub-Agent System

Isolated execution environments for agent-generated code with Brain recording.

Architecture

src/contextunity/worker/
├── __main__.py # Entrypoint
├── cli.py # CLI commands (Typer)
├── config.py # WorkerConfig (Pydantic settings)
├── service.py # gRPC WorkerService
├── server.py # gRPC server setup
├── schedules.py # Temporal schedule management
├── schemas.py # Request/response schemas
├── interceptors.py # gRPC interceptors
├── core/
│ ├── registry.py # WorkerRegistry, ModuleConfig, plugin discovery
│ ├── worker.py # Temporal client setup and worker creation
│ ├── worker_sdk.py # Worker SDK helpers
│ └── brain_token.py # Brain token utilities
├── engines/ # Pluggable execution backends
│ ├── base.py # BaseEngine protocol
│ ├── temporal_engine.py # Temporal workflow engine
│ └── huey_engine.py # Huey task queue engine
└── jobs/
├── orchestrator.py # Job orchestration
├── retention.py # Data retention policies
└── scrum_master.py # Automated task management

Key Design Principle

Worker contains NO business logic. It provides infrastructure only.

Business logic lives in domain packages:

  • Commerce harvesting → ContextCommerce (registers workflows)
  • AI enrichment → ContextRouter (runs agents)

Modules register themselves via the WorkerRegistry and are discovered at startup.