AgentWorker consumes jobs as soon as it is constructed. Registry keys must match names submitted by the producer. Missing entries fail the job with a named registry error.
Start a worker
Use the dependencies from the quickstart, plusnpm install openai. Set OPENAI_API_KEY, save this as worker.ts, and run npx tsx worker.ts. This worker matches the producer example.
worker.ts
start() remains available for compatibility but performs no work. concurrency defaults to 5. Set it deliberately according to provider quotas, tool limits, and available resources.
Register other work
UseteamRegistry for team jobs and workflowRegistry for workflow jobs. agentRegistry is required even for a worker that only handles other job types; pass {} in that case. See team jobs and the WorkerConfig reference.
The worker forwards the submitted session, user, and tenant fields to the run. Enqueue only host-authorized identity values. In-process Agent objects can serve concurrent jobs, so external stores and application callbacks must support the concurrency you choose.
Understand progress
For agent jobs, the worker listens torun.stream.chunk and increments a counter scoped to that run ID. It removes the listener when execution finishes and waits for outstanding progress writes. This counter does not estimate percent complete; a non-streaming model call may not produce chunk events.
bridgeEventBusToJob(eventBus, job, runId) is available for custom BullMQ workers. It counts matching chunks and logs matching tool.call events, then returns a cleanup function. Call that function in finally. The helper does not log tool.result, and the built-in worker uses its own progress listener rather than this helper.
Drain before closing dependencies
await worker.stop(timeoutMs) asks BullMQ to close the worker and waits for active jobs, with a default 30-second deadline. A timeout rejects with Worker drain timeout; it does not forcibly abort a provider or reverse side effects. Close Agents and their owned storage only after work has drained. Configure your process manager’s termination deadline to allow that sequence.