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

# Durable deployment architecture

> Compare a single-JVM quickstart with production deployments that dispatch Turns and execute tools using RocketMQ or SSE and HTTP.

The local quickstart runs the application, Brain, and an offline model in one JVM. In production, you can scale Agent API, Brain, and Hands workers independently. The two production topologies differ in how a Brain receives a Turn and how Hands receives a tool command and returns its result.

| Deployment | Turn scheduling | Tool execution | User events |
| - | - | - | - |
| Local quickstart | The embedded DurableRuntime schedules Turns from LocalBackend | The example uses an offline model and runs in one JVM | The application subscribes through the Java Session API |
| Production with RocketMQ | The submitter publishes a readiness message. A Brain consumes it and claims the Turn in PostgreSQL | RocketMQ topics carry commands, controls, and execution updates | Agent API streams committed events from PostgreSQL and live previews from Redis |
| Production with SSE and HTTP | Brain discovers due work in PostgreSQL and claims the Turn | Hands opens a command stream and posts receipts and results over HTTP | Agent API uses the same public SSE endpoint and event sources |

The production diagrams show separate services with cross-instance previews enabled. A Service is a reachable endpoint. Depending on your deployment, a Kubernetes Service, gateway, or internal load balancer can provide that endpoint.

## Local quickstart

![The application calls DurableRuntime in the same JVM. The runtime drives a ReActAgent with an offline model and persists state through LocalBackend.](https://mintcdn.com/agent-scope/M2nTP3DRF-47AUCE/imgs/durable-deployment/local-en.svg?fit=max\&auto=format\&n=M2nTP3DRF-47AUCE\&q=85\&s=181b9dba3360c135242c338ed3eac58e)

Run the following command from the repository root with **JDK 17 or later, Maven, and Bash**. The example uses a deterministic offline model. SQLite and the file object store share a temporary data directory.

```sh theme={null}
bash agentscope-examples/durable/integrated/quickstart/run.sh
```

The script starts Spring Boot twice with the same directory and request ID. Both runs print the same Turn ID and `status=SUCCEEDED`. The first prints `modelInvocations=1` and the second prints `0` because the runtime finds the completed Turn after restart. The example receives event callbacks in the JVM. A separate HTTP example hosts the API role and exposes `POST /api` and `GET /events`. [Run the examples](https://java.agentscope.io/dev/en/docs/harness/durable.md#run-the-examples)

## Production with RocketMQ

![Agent API publishes Turn readiness to RocketMQ. Brain and Hands exchange commands and updates through RocketMQ. Redis carries previews to the API and PostgreSQL delivers committed events.](https://mintcdn.com/agent-scope/M2nTP3DRF-47AUCE/imgs/durable-deployment/production-mq-en.svg?fit=max\&auto=format\&n=M2nTP3DRF-47AUCE\&q=85\&s=b0fb8287ee66d820e405acf2d29dc5ca)

**Turn scheduling.** The submitter writes the Turn to PostgreSQL. After the transaction commits, `RocketMqTurnScheduler` publishes a readiness message. Configure its publisher on API-only hosts as well. A Brain consumes the message, checks the Turn revision and dispatch generation, and acquires the lease in a database transaction. Durable dispatch records allow workers to recover missed publications and take over expired leases.

**Tool execution.** Brain uses `RocketMqRemoteExecutor` to publish a tool call to the command topic. Hands uses `RocketMqWorker` to record acceptance before acknowledging the command. It publishes progress and results to the updates topic. Brain deduplicates each update and commits it before acknowledging the message. The control topic carries cancellation and status requests. The execution ledger and the final update tell the caller when the tool has finished.

**Broker configuration.** Deploy a LiteTopic-capable broker and Cluster Proxy. Point both Brain and Hands at the gRPC Proxy endpoint. In the same deployment namespace, create a NORMAL topic for ready Turns, LITE parent topics for Turn signals and owner notifications, and LITE parent topics for Hands commands, controls, and updates. Configure their consumer groups. Replicas in one Hands pool share its command consumer group and execution ledger. Clients receive Session events through the public API. [Topics, consumer groups, and scheduler configuration](https://java.agentscope.io/dev/en/docs/harness/durable.md#rocketmq-execution)

## Production with SSE and HTTP

![Brain claims ready Turns in PostgreSQL. Hands opens an SSE connection to the private Brain endpoint and posts receipts and results. Users receive committed events and previews through Agent API.](https://mintcdn.com/agent-scope/x5WyP-f7D5yQvSIJ/imgs/durable-deployment/production-no-mq-en.svg?fit=max\&auto=format\&n=x5WyP-f7D5yQvSIJ\&q=85\&s=60812c3584dde69ce812ca0ec0e2a6e6)

**Turn scheduling.** Agent API commits the request and Turn to PostgreSQL. Brain replicas share a SessionBackend, discover due work in its ready index, and compete for leases. If a Brain fails, another replica can resume from durable state.

**Tool execution.** Register `SseHandsExecutor` on Brain. Mount the private Hands handler on Brain or on a host that shares its SessionBackend. Give the worker pool a stable address for that endpoint. Each `SseHandsWorker` opens one outbound command stream and can serve several Sessions concurrently. The following paths are relative to the private endpoint.

| Request | Direction | Purpose |
| - | - | - |
| `GET commands/stream` | Hands opens the connection. Brain sends commands to Hands | Deliver durable commands. If a worker connects late or loses its stream, a command that lacks a receipt can be redelivered after its delivery lease expires |
| `POST receipts` | Hands to Brain | Confirm durable acceptance. Hands deduplicates commands by execution ID |
| `POST events` | Hands to Brain | Report execution updates and results. Hands can resend recorded updates until Brain confirms them |

Authenticate the worker pool and authorize access to each Session. Disable proxy response buffering for SSE and reserve capacity for result POSTs alongside long-lived streams. Brain replicas share their ledger, and replicas in the same Hands pool share theirs. Both ledgers can use one PostgreSQL instance. The two-process repository example uses loopback HTTP and local storage to exercise this protocol. [Worker-initiated SSE configuration](https://java.agentscope.io/dev/en/docs/harness/durable.md#worker-initiated-sse)

## User SSE and infrastructure in production

Users connect to Agent API. For example, API A may hold a user's connection while Brain B runs inference. A delivers both kinds of events on that one SSE connection. An authorized client can reconnect through another API replica.

| Content | From Brain B to API A | Recovery |
| - | - | - |
| Model text deltas | Brain publishes through `RedisLiveEvents`. API subscribes to the deployment's Redis Pub/Sub channel, filters by Session, and forwards previews to connections that requested them | Delivery is best effort. Preview frames have no resume cursor. The committed message replaces the partial preview |
| Complete messages, tool results, and status changes | Brain commits the event and its Session commit index. PostgreSQL sends the event and commit watermark through `NOTIFY`. API receives them on its `LISTEN` connection and fans out in memory by Session | A durable cursor lets clients catch up. A watermark can reveal a missing final event. When the database listener reconnects, the API checks the tail of each active Session |

Give each API instance a dedicated PostgreSQL listener connection, either direct or through a session-mode pool. Configure every reader and writer with `sessionEventPush` and the same deployment-specific 32-byte key. Healthy connections consume notifications in memory. Initial cursor setup, reconnections, sequence gaps, and oversized notification payloads trigger reads from storage. Sessions created before push was enabled continue to use polling. In both diagrams, Redis carries live previews across processes. [Preview transport configuration](https://java.agentscope.io/dev/en/docs/harness/durable.md#preview-transport-for-separate-hosts) · [PostgreSQL event push](https://java.agentscope.io/dev/en/docs/harness/durable.md#push-committed-events-over-postgresql)

**Inference, sandboxes, and storage.** Brain calls a model gateway or inference provider. Hands resolves the sandbox binding for each Session and runs tools in its workspace, so a worker can serve multiple isolated sandboxes. The sandbox provider supplies the execution environment and workspace storage. To prewarm a sandbox when a Session is created, connect Session admission to the preparation task. The host can run the dispatcher in-process or separately. Workspace volume or snapshot recovery and idle reclamation depend on the platform and provider. External object storage is optional for large checkpoints and artifacts. The Hands SSE transport uses bounded inline payloads. [Persistent sandbox bindings](https://java.agentscope.io/dev/en/docs/harness/durable.md#persistent-sandbox-bindings)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.