Required infrastructure
Use a running Temporal service, 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.
Temporal workers
The high-level runtime pollsAgentWorkflowTaskQueue. Serve registers workflow/activity implementations for the configured agents on that queue. Keep worker deployments consistent with the histories they may replay. Changing workflow behavior needs a compatible deployment/versioning strategy.
Close stops the worker and closes the Temporal client owned by this runtime. Caller-supplied history and broker resources remain caller-owned.
This API runs agents. For explicit pkg/workflow graphs, use the separate Temporal workflow executor.
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.