agent

command
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

  1. On Stream start, save runID alongside your correlation key (conversationID, request ID, …).
  2. Track the offset of each received event: ev.(interface{ Offset() (int64, bool) }).
  3. On process restart, call agent.GetAgentStream(ctx, savedRunID), then Events(ctx, agent.WithOffset(savedOffset)).
  4. Events at offset ≤ savedOffset are skipped; resume normal handling from new events.
  5. Clear the saved runID on RUN_FINISHED or RUN_ERROR.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL