Documentation
¶
Overview ¶
agent_with_reconnect demonstrates Agent.GetAgentStream: how to subscribe to a prior run's Temporal Workflow Streams event log from a saved offset, simulating a mid-run crash and recovery in a single process.
Single-process mode (default) ¶
No separate worker is needed. The embedded Temporal worker runs in the same process. Cancelling the Events context only closes the subscriber-side event channel — the Stream context (and Temporal workflow) keep running. Do not share one cancelable ctx for Stream and Events when simulating a subscriber crash. On reconnect, events from the saved offset are replayed and new events stream in live.
AGENT_RUNTIME=temporal go run . [prompt]
Separate worker mode (optional) ¶
Pass agent.DisableLocalWorker() and start the worker binary in a separate terminal to demonstrate the agent+worker split. See agent_with_worker and durable_agent for the full split-process story.
terminal 1: AGENT_RUNTIME=temporal go run ./worker terminal 2: AGENT_RUNTIME=temporal go run . [prompt]
Caller-side reconnect protocol ¶
- On Stream start, save runID alongside your correlation key (conversationID, request ID, …).
- Track the offset of each received event: ev.(interface{ Offset() (int64, bool) }).
- On process restart, call agent.GetAgentStream(ctx, savedRunID), then Events(ctx, agent.WithOffset(savedOffset)).
- Events at offset ≤ savedOffset are skipped; resume normal handling from new events.
- Clear the saved runID on RUN_FINISHED or RUN_ERROR.