Documentation
¶
Overview ¶
Package run defines primitives for tracking agent run executions.
Core Concepts ¶
RunID (Infrastructure Layer):
- Represents a single durable workflow execution (e.g., Temporal WorkflowID)
- Used for workflow operations: replay, cancellation, history, observability
- Must be globally unique across all workflow executions
- Lifespan: From workflow start to completion (seconds to hours)
TurnID (Application Layer):
- Represents a conversational turn (user message → agent response)
- Used for conversation tracking, UI rendering, session timeline
- Unique within a session, groups events for display
- Lifespan: Logical grouping that may span multiple workflow executions
SessionID (Conversation Layer):
- Groups related runs/turns into a conversation or interaction thread
- Used for context accumulation across multiple turns
- Examples: chat session, research task, multi-step workflow
Relationship Examples:
Simple chat (1 turn = 1 run):
Session "chat-123"
└─ Turn "turn-1" → Run "chat-123-run-1"
└─ Turn "turn-2" → Run "chat-123-run-2"
Interrupted execution (1 turn = multiple runs):
Session "task-456"
└─ Turn "turn-1" → Run "task-456-run-1" (interrupted)
→ Run "task-456-run-1-resumed" (same turn, new workflow)
Streaming with tool discovery (1 turn = 1 run, multiple events):
Session "research-789"
└─ Turn "turn-1" → Run "research-789-run-1"
├─ Event seq=1: "Searching papers..."
├─ Event seq=2: "Fetching papers..."
└─ Event seq=3: "Analyzing..."
Index ¶
Constants ¶
const ( // StatusPending indicates the run has been accepted but not started yet. StatusPending Status = "pending" // StatusRunning indicates the run is actively executing. StatusRunning Status = "running" // StatusCompleted indicates the run finished successfully. StatusCompleted Status = "completed" // StatusFailed indicates the run failed permanently. StatusFailed Status = "failed" // StatusCanceled indicates the run was canceled externally. StatusCanceled Status = "canceled" // StatusPaused indicates execution is paused awaiting external intervention. StatusPaused Status = "paused" // PhasePrompted indicates that input has been received and the run is // about to begin planning. PhasePrompted Phase = "prompted" // PhasePlanning indicates that the planner is deciding whether and how to // call tools or answer directly. PhasePlanning Phase = "planning" // PhaseExecutingTools indicates that tools (including nested agents) are // currently executing. PhaseExecutingTools Phase = "executing_tools" // PhaseSynthesizing indicates that the planner is synthesizing a final // answer without scheduling additional tools. PhaseSynthesizing Phase = "synthesizing" // PhaseCompleted indicates the run has completed successfully. PhaseCompleted Phase = "completed" // PhaseFailed indicates the run has failed. PhaseFailed Phase = "failed" // PhaseCanceled indicates the run was canceled. PhaseCanceled Phase = "canceled" )
Variables ¶
var ( // ErrNotFound indicates the requested run does not exist. ErrNotFound = errors.New("run not found") )
Functions ¶
This section is empty.
Types ¶
type AwaitSnapshot ¶
type AwaitSnapshot struct {
// Kind identifies which await variant is active.
Kind string
// ID is the await correlation identifier.
ID string
// ToolName is the tool that triggered the await when applicable.
ToolName tools.Ident
// ToolCallID is the tool call that triggered the await when applicable.
ToolCallID string
// Question is the clarification question when awaiting clarification.
Question string
// Title is the confirmation title when awaiting confirmation.
Title string
// Prompt is the confirmation prompt when awaiting confirmation.
Prompt string
// ItemCount is the number of external tool items awaited.
ItemCount int
}
AwaitSnapshot describes the latest await state derived from run events.
type ChildRunLink ¶
type ChildRunLink struct {
// ToolName is the agent-tool identifier that started the child run.
ToolName tools.Ident
// ToolCallID is the parent tool call identifier.
ToolCallID string
// ChildRunID is the workflow run identifier of the nested agent execution.
ChildRunID string
// ChildAgentID identifies the agent that executed the child run.
ChildAgentID agent.Ident
}
ChildRunLink links a parent tool call to a nested agent run.
type Context ¶
type Context struct {
// RunID uniquely identifies the durable workflow run (infrastructure layer).
// This corresponds to the workflow engine's execution identifier (e.g.,
// Temporal WorkflowID). Used for workflow operations, replay, and observability.
RunID string
// ParentToolCallID identifies the parent tool call when this run represents a
// nested agent execution (agent-as-tool). Empty for top-level runs. Used to
// correlate ToolCallUpdated events and propagate parent-child relationships.
ParentToolCallID string
// ParentRunID identifies the run that scheduled this nested execution. Empty for
// top-level runs. When set, tool events emitted by this run can be attributed to
// the parent run for streaming/UI purposes.
ParentRunID string
// ParentAgentID identifies the agent that invoked this nested execution. Empty
// for top-level runs. When set alongside ParentRunID, tool events can retain the
// parent agent identity even though execution occurs in a child agent.
ParentAgentID agent.Ident
// SessionID associates related runs into a conversation or interaction thread.
// Multiple turns in a chat session share the same SessionID. Optional.
SessionID string
// TurnID identifies a conversational turn within a session (application layer).
// Optional. When set, groups all events produced during this turn for UI
// rendering and conversation tracking. Multiple runs may share the same TurnID
// if a turn requires pause/resume or retry with a new workflow execution.
// Format: typically "turn-1", "turn-2", etc. within a session.
TurnID string
// Tool identifies the fully-qualified tool name when this run is a nested
// agent-as-tool execution. For top-level runs (not invoked via a parent tool),
// Tool is empty. Planners may use this to select method-specific prompts.
// Format: "<service>.<toolset>.<tool>".
Tool tools.Ident
// ToolArgs carries the original JSON arguments for the parent tool when this run
// is an agent-as-tool execution. Nil for top-level runs. Nested agent planners
// can use this structured input to render method-specific prompts without
// reparsing free-form messages.
ToolArgs rawjson.Message
// Attempt counts how many times the run has been attempted/resumed.
Attempt int
// Labels carries caller-provided metadata (account, priority, etc.).
Labels map[string]string
// MaxDuration encodes the wall-clock budget remaining (string form for prompts/telemetry).
MaxDuration string
}
Context carries execution metadata for the current run invocation. It is passed through the system during workflow execution and contains the identifiers, labels, and constraints active for this specific invocation attempt.
type Handle ¶
type Handle struct {
// RunID uniquely identifies the durable workflow run.
RunID string
// AgentID identifies the agent that owns this run.
AgentID agent.Ident
// ParentRunID identifies the run that scheduled this run when used for
// nested agent-as-tool execution. Empty for top-level runs.
ParentRunID string
// ParentToolCallID identifies the parent tool call that created this
// run when used for nested agent-as-tool execution. Empty for
// top-level runs.
ParentToolCallID string
}
Handle is a lightweight handle to a run, used for linking parent and child runs in planner contracts and streaming surfaces. It intentionally omits transport/engine details and focuses on logical identity.
type Phase ¶
type Phase string
Phase represents a finer-grained lifecycle phase for a run. Phases track where a run is in its execution loop (prompted, planning, executing tools, synthesizing, or in a terminal state). Phases are intended for streaming/UX surfaces and do not replace Status, which is used for durable run metadata.
type Snapshot ¶
type Snapshot struct {
// RunID uniquely identifies the durable workflow run.
RunID string
// AgentID identifies the agent that owns the run.
AgentID agent.Ident
// SessionID groups related runs into a logical session.
SessionID string
// TurnID groups events for a single conversational turn.
TurnID string
// Status is the coarse-grained run lifecycle status derived from events.
Status Status
// Phase is the current execution phase derived from events.
Phase Phase
// StartedAt is the timestamp of the first observed run event.
StartedAt time.Time
// UpdatedAt is the timestamp of the last observed run event.
UpdatedAt time.Time
// LastAssistantMessage is the most recent assistant message emitted by the run.
LastAssistantMessage string
// Await describes the current await state when the run is paused awaiting input.
Await *AwaitSnapshot
// ToolCalls summarizes observed tool calls (scheduled, updated, completed).
ToolCalls []*ToolCallSnapshot
// ChildRuns links nested agent runs (agent-as-tool) started during this run.
ChildRuns []*ChildRunLink
}
Snapshot is a derived view of a run computed by replaying the run event log.
Snapshots are not stored directly; they are recomputed from the canonical append-only run log.
type ToolCallSnapshot ¶
type ToolCallSnapshot struct {
// ToolCallID uniquely identifies the tool invocation.
ToolCallID string
// ParentToolCallID identifies the parent tool call when this call is nested.
ParentToolCallID string
// ToolName identifies the executed tool.
ToolName tools.Ident
// ScheduledAt is the timestamp of the tool scheduling event.
ScheduledAt time.Time
// CompletedAt is the timestamp of the tool result event.
CompletedAt time.Time
// Duration is the tool execution duration when the result is observed.
Duration time.Duration
// ErrorSummary is a human-readable error message when the tool failed.
ErrorSummary string
// ExpectedChildrenTotal tracks the expected number of child tool calls for parent tools.
ExpectedChildrenTotal int
// ObservedChildrenTotal tracks how many direct child tool calls were observed as scheduled.
ObservedChildrenTotal int
}
ToolCallSnapshot summarizes the state of a tool invocation derived from events.