> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Queue examples

> Enqueue an agent run. A worker on Redis picks it up.

# Queue examples

Runnable file: [agentium-examples/queue/07-background-job.ts](https://github.com/agentiumOS/agentium-examples/blob/main/queue/07-background-job.ts).

Guide: [Queue](/queue/overview)

Needs Redis on `localhost:6379`.

```bash theme={null}
npm install @agentium/queue
```

***

## 1. Enqueue + worker

```typescript theme={null}
import { Agent, openai } from "@agentium/core";
import { AgentQueue, AgentWorker } from "@agentium/queue";

const reportAgent = new Agent({
  name: "report-gen",
  model: openai("gpt-4o"),
  instructions: "You write short reports with headings.",
});

const queue = new AgentQueue({
  connection: { host: "localhost", port: 6379 },
});

const { jobId } = await queue.enqueueAgentRun({
  agentName: "report-gen",
  input: "Q4 engineering report.",
  priority: 1,
  attempts: 3,
});

const worker = new AgentWorker({
  connection: { host: "localhost", port: 6379 },
  concurrency: 3,
  agentRegistry: { "report-gen": reportAgent },
});

worker.start();

queue.onCompleted((id, result) => {
  console.log(id, result.text.slice(0, 200));
});
```

The API process enqueues. The worker process runs the agent. Recurring jobs: [Schedules](/examples/scheduling).
