AgentWorker consumes jobs from the BullMQ queue and executes them using registered agents and workflows. Workers can run in the same process or as separate services.
Setup
{ host: string; port: number }
required
Redis connection details. Must match the producer’s connection.
string
default:"agentium:jobs"
Queue name to consume from. Must match the producer.
number
default:"5"
Number of jobs to process simultaneously.
Record<string, Agent>
required
Map of agent names to Agent instances. Names must match what the producer enqueues.
Record<string, Workflow>
Map of workflow names to Workflow instances.
How It Works
- Worker connects to Redis and listens for jobs on the configured queue
- When a job arrives, it looks up the agent/workflow by name in the registry
- Executes
agent.run()orworkflow.run()with the job’s input - Reports progress via BullMQ job progress updates
- Stores the result (or error) back to Redis for the producer to retrieve
With Workflows
Graceful Shutdown
stop() method waits for currently active jobs to complete before shutting down.
Event Bridging
ThebridgeEventBusToJob utility connects an agent’s EventBus to BullMQ’s job progress system, enabling real-time progress tracking:
run.stream.chunkupdates job progresstool.calladds to job logstool.resultadds to job logs
Scaling
Run multiple worker processes to scale horizontally. BullMQ handles job distribution automatically:concurrency jobs simultaneously. With 3 workers at concurrency 5, you can process 15 jobs in parallel.