Required infrastructure
Use a running Restate server, a shared stream broker such as Redis, and persistence reachable by every worker that can handle a conversation. File history and memory brokers are not distributed stores.Construct before serving
This setup assumesctx is cancelled at service shutdown, model is configured, and sharedHistory is your application’s conversation manager:
NewAgent registers its resolved configuration with the supplied runtime. WithRuntime accepts only the runtime; its broker comes from Runtime.StreamBroker(). Register every participating agent before calling Serve.
The runtime constructor returns an error and does not start workers in the background. Serve blocks until cancellation or failure. In a service hosting HTTP and workers together, supervise both and propagate startup errors; do not discard a Serve error in an unobserved goroutine.
Restate ingress and service address
The constructor’s endpoint is the Restate ingress used by callers. TheServe address is where your Go service listens for Restate invocations. They are different endpoints.
Start the service and register its reachable deployment URL with your Restate server before invoking it. Serve binds the agent workflow and background-task service using the SDK runtime implementation; it does not perform deployment registration with Restate for you.
The service uses unencrypted HTTP/2 on its listen address. Configure network exposure and proxy support accordingly. Close stops the service lifecycle; supplied broker/history resources remain caller-owned.
Invoke and observe
Call the sameagent.Run or agent.Execute APIs as local agents. A caller-only process can use the lower-level invocation runtime while worker configurations live in the service process. The high-level constructor is convenient when one process owns configuration and worker startup.
Both callers and workers must connect to the same broker for event delivery and stop signaling. Omitting the broker is an error; there is no implicit memory broker for a configured durable runtime.
Cancellation and retries
UseRun with a request context for caller-bound execution, or a streaming handle and Stop for a detached run. Stop flags travel through the shared broker to active operations. Middleware runs inside the durable activity/step and can repeat with it.
Pass only serializable state across execution boundaries. Keep database clients, MCP connectors, tools, and other dependencies on the worker, and pass per-run values through supported input/context mechanisms. Configure tracing in both the caller and worker processes.