Use agents for practical asynchronous state ownership such as telemetry aggregation or ordered local side-effect coordination, while choosing queues, executors, or databases for broader task systems.
Agents are most useful when you can name the state value they own. If the main problem is “run tasks somewhere,” an agent may be the wrong abstraction.
For Java engineers, the distinction is important. An executor owns threads. An agent owns state and happens to process state transitions asynchronously.
| Scenario | Fit | Reason |
|---|---|---|
| Aggregate local telemetry | Good | One state value receives serialized updates. |
| Maintain ordered in-memory audit events | Good | Order matters for one local collection. |
| Coordinate after an STM commit | Good | Agent sends inside STM are held until commit. |
| Process a durable job queue | Poor | Needs persistence, retries, and backpressure. |
| Return immediate API response data | Poor | Caller needs a result, not eventual state. |
| Coordinate several independent identities | Poor | Refs or another transaction boundary fit better. |
Use an agent when asynchronous state ownership is the central idea.
1(def telemetry
2 (agent {:requests 0
3 :errors 0}))
4
5(defn record [m ok?]
6 (-> m
7 (update :requests inc)
8 (update :errors
9 (fnil + 0)
10 (if ok? 0 1))))
11
12(defn record-request! [ok?]
13 (send telemetry record ok?))
The request thread does not wait for the metrics state to update. That is acceptable because telemetry is useful as an eventually updated local snapshot.
| Need | Prefer |
|---|---|
| Durable work after restart | Message broker, database queue, or job system. |
| Backpressure and stream processing | core.async channel, queue, or streaming system. |
| Immediate computed result | Future, promise, direct call, atom, or ref transaction. |
| Complex supervision | Dedicated worker framework or service architecture. |
| Multi-node shared state | External coordinated storage. |
Agents can be part of a production design, but they should not be the hidden foundation for durable background processing.
send or blocking-aware with send-off.