Documentation
¶
Overview ¶
Package runtime defines internal execution contracts for agent backends (Temporal, in-process, etc.). SDK users do not import this package; pkg/agent wires implementations. If a file also imports the standard library "runtime" package, alias one import (e.g. agentrt ".../internal/runtime").
Index ¶
- Constants
- type AgentConfig
- type AgentLLM
- type AgentLimits
- type AgentMemory
- type AgentRetrievers
- type AgentSession
- type AgentSpec
- type ExecutionConfig
- type ExecutionConfigs
- type ExecutionPolicies
- type ExecutionPolicy
- type LLMSampling
- type RetryPolicy
- type RunHandle
- type RunRequest
- type Runtime
- type StreamHandle
- type SubAgentSpec
- type WorkerRuntime
Constants ¶
const SubAgentToolParamQuery = "query"
SubAgentToolParamQuery is the tool/JSON parameter name for the query sent to a sub-agent.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶ added in v0.2.2
type AgentConfig struct {
LLM AgentLLM
ToolApprovalPolicy interfaces.AgentToolApprovalPolicy
Retrievers AgentRetrievers
Session AgentSession
Memory AgentMemory
Limits AgentLimits
ExecutionConfigs ExecutionConfigs
Hooks []hooks.HookGroup
}
AgentConfig is static agent wiring on the runtime at construction: LLM client, tool approval policy, session, limits, retriever config, exec overrides, and hooks.
type AgentLLM ¶
type AgentLLM struct {
Client interfaces.LLMClient
Sampling *LLMSampling
}
AgentLLM is the LLM client and sampling overrides for this run.
type AgentLimits ¶
AgentLimits caps iteration and wall-clock behavior for this run.
type AgentMemory ¶ added in v0.2.2
AgentMemory holds long-term memory configuration for recall and store.
type AgentRetrievers ¶ added in v0.1.11
type AgentRetrievers struct {
// Retrievers is the list of retriever instances registered with the agent.
Retrievers []interfaces.Retriever
// Mode is the retriever mode (agentic, prefetch, hybrid).
Mode types.RetrieverMode
}
AgentRetrievers holds the retriever instances and mode for prefetch and hybrid RAG.
type AgentSession ¶
type AgentSession struct {
Conversation interfaces.Conversation
ConversationSize int
ConversationSaveOnIteration bool
}
AgentSession is conversation storage and how many messages to include in LLM context.
type AgentSpec ¶
type AgentSpec struct {
// Name is a human-readable label (may include spaces). Runtimes may sanitize it when embedding in workflow IDs.
Name string
Description string
SystemPrompt string
ResponseFormat *interfaces.ResponseFormat
}
AgentSpec describes agent identity and structured-output preferences configured on the runtime.
type ExecutionConfig ¶ added in v0.2.5
ExecutionConfig is a partial override for timeout and retry budget on one agent loop operation. Zero Timeout or MaxAttempts mean "use SDK default" at resolve time; see ResolveExecutionPolicies.
func (ExecutionConfig) ToPolicy ¶ added in v0.2.5
func (c ExecutionConfig) ToPolicy() ExecutionPolicy
ToPolicy converts a merged ExecutionConfig into a fully populated ExecutionPolicy. MaxAttempts below 1 is clamped to 1 so the operation always runs at least once. Backoff is always DefaultRetryPolicy; user-facing ExecutionConfig does not expose backoff today.
type ExecutionConfigs ¶ added in v0.2.5
type ExecutionConfigs struct {
LLM ExecutionConfig
ToolAuth ExecutionConfig
ToolExecute ExecutionConfig
MCP ExecutionConfig
A2A ExecutionConfig
Retriever ExecutionConfig
Memory ExecutionConfig
Conversation ExecutionConfig
SubAgent ExecutionConfig
}
ExecutionConfigs holds per-operation execution overrides. Used as agent-level overrides on AgentConfig and as the SDK default bundle from [defaultExecutionConfigs].
type ExecutionPolicies ¶ added in v0.2.5
type ExecutionPolicies struct {
LLM ExecutionPolicy
ToolAuth ExecutionPolicy
ToolExecute ExecutionPolicy
MCP ExecutionPolicy
A2A ExecutionPolicy
Retriever ExecutionPolicy
Memory ExecutionPolicy
Conversation ExecutionPolicy
SubAgent ExecutionPolicy
}
ExecutionPolicies holds resolved policies for every loop operation.
func ResolveExecutionPolicies ¶ added in v0.2.5
func ResolveExecutionPolicies(execConfigs ExecutionConfigs) ExecutionPolicies
ResolveExecutionPolicies merges agent per-operation overrides onto SDK defaults and converts each operation to a fully populated ExecutionPolicy. This is the primary entry point used by runtimes at the start of each agent run.
type ExecutionPolicy ¶ added in v0.2.5
type ExecutionPolicy struct {
Timeout time.Duration
MaxAttempts int
Retry RetryPolicy
}
ExecutionPolicy is the resolved runtime shape for one agent loop operation (local [executeWithPolicy] or Temporal activity).
type LLMSampling ¶
type LLMSampling = types.LLMSampling
LLMSampling is the runtime package name for per-run sampling options. It aliases types.LLMSampling so callers share one shape today; a distinct runtime type may replace this alias if the public runtime API needs different fields later.
type RetryPolicy ¶ added in v0.2.5
type RetryPolicy struct {
InitialInterval time.Duration
BackoffCoefficient float64
MaximumInterval time.Duration
}
RetryPolicy controls backoff between retry attempts on a resolved ExecutionPolicy.
func DefaultRetryPolicy ¶ added in v0.2.5
func DefaultRetryPolicy() RetryPolicy
DefaultRetryPolicy returns the SDK backoff defaults applied by ExecutionConfig.ToPolicy.
type RunHandle ¶ added in v0.3.0
type RunHandle interface {
// ID returns the unique run identifier, stable across process restarts when the
// backend supports reconnect (e.g. Temporal workflow ID).
ID() string
// Status returns the current [types.RunStatus] of this run.
// Returns [ErrRunNotFound] when the underlying run is no longer known.
Status(ctx context.Context) (types.RunStatus, error)
// Cancel requests cancellation of this run.
// Returns [ErrRunAlreadyCompleted] when the run has already finished.
// Returns [ErrRunNotFound] when the underlying run is no longer known.
Cancel(ctx context.Context) error
// Get blocks until the run finishes and returns the result.
// Cancelling ctx unblocks Get but does NOT cancel the agent run itself —
// use [RunHandle.Cancel] for that.
Get(ctx context.Context) (*types.AgentRunResult, error)
// Done returns a channel that is closed when the run finishes (success or failure).
// Safe to call multiple times; always returns the same channel.
Done() <-chan struct{}
}
RunHandle is the per-run control surface returned by Runtime.Run or Runtime.GetRunHandle. Status, Cancel, Get, and Done operate on this run only — callers never pass a runID back into Runtime for those operations.
type RunRequest ¶ added in v0.3.0
type RunRequest struct {
UserPrompt string `json:"user_prompt"`
// ConversationID is the conversation session for this run. Empty means no conversation.
// Agent and worker must use the same ID when conversation is enabled.
ConversationID string `json:"conversation_id,omitempty"`
// EnableLLMStream requests token-level LLM streaming (Agent.Stream typically sets true;
// Agent.Run sets false). Distinct from agent-event streaming on [StreamHandle.Events].
EnableLLMStream bool `json:"enable_llm_stream"`
// EventTypes filters streamed agent events; empty means default (implementation-defined, often all types).
EventTypes []events.AgentEventType `json:"event_types,omitempty"`
SubAgents []*SubAgentSpec `json:"sub_agents,omitempty"`
MaxSubAgentDepth int `json:"max_sub_agent_depth"`
// Tools is the registry-resolved tool list for this run.
Tools []interfaces.Tool `json:"-"`
}
RunRequest carries one run request from Agent to Runtime. Run identity is not on the request; the runtime mints it and returns it via the handle's ID().
type Runtime ¶
type Runtime interface {
// Run starts one blocking-style agent run and returns a [RunHandle] immediately.
// The run continues asynchronously; use [RunHandle.Get] or [RunHandle.Done] to wait for
// completion, and [RunHandle.Status]/[RunHandle.Cancel] for lifecycle control.
// The runtime mints the run ID exposed by [RunHandle.ID]. When using conversation, set
// [RunRequest.ConversationID]; agent and worker must use the same ID. Agent identity
// lives on the runtime [AgentSpec] configured at construction. The agent package supplies
// approval via [RunRequest] when needed.
Run(ctx context.Context, req *RunRequest) (RunHandle, error)
// GetRunHandle returns a [RunHandle] for an existing run identified by runID
// (e.g. after a process restart). Use this instead of [Runtime.Run] when the run
// was already started. Live same-process reuse is handled at the agent layer
// (run registry); this method is for runtime-level reconnect.
// Returns [ErrRunNotFound] when runID is unknown or the runtime cannot recover
// a handle (e.g. LocalRuntime has no durable run tracking).
// Returns [ErrRunAlreadyCompleted] when the run has already finished.
GetRunHandle(ctx context.Context, runID string) (RunHandle, error)
// Stream starts one streaming agent run and returns a [StreamHandle] immediately.
// It does not subscribe to events; call [StreamHandle.Events] on the returned handle.
// The runtime mints the run ID exposed by [StreamHandle.ID]. For approvals (tool or
// delegation), subscribe via [StreamHandle.Events], handle CUSTOM events, then call
// [StreamHandle.Approve]. When using conversation, set [RunRequest.ConversationID] on the request.
Stream(ctx context.Context, req *RunRequest) (StreamHandle, error)
// OnApproval completes a pending stream approval by token. Prefer [StreamHandle.Approve].
// Returns [types.ErrApprovalAlreadyResolved] when the token was already completed.
//
// Deprecated: Use [StreamHandle.Approve] on the handle from [Runtime.Stream] or
// [Runtime.GetStreamHandle] instead. This method will be removed in v0.4.0.
OnApproval(ctx context.Context, approvalToken string, status types.ApprovalStatus) error
// GetStreamHandle returns a [StreamHandle] for an existing streaming run identified by
// runID (e.g. after a process restart). Use this instead of [Runtime.Stream]
// when the run was already started; then call [StreamHandle.Events] (optionally with
// a non-zero fromOffset) to subscribe. Live same-process reuse is handled at the
// agent layer (stream registry); this method is for runtime-level reconnect.
// Returns [ErrStreamNotFound] when runID is unknown or the runtime cannot recover
// a stream handle (e.g. LocalRuntime has no durable stream tracking).
// Returns [ErrRunAlreadyCompleted] when the run has already finished.
// Returns [ErrStreamOffsetNotSupported] when the runtime cannot replay at the requested offset.
GetStreamHandle(ctx context.Context, runID string) (StreamHandle, error)
// Close releases runtime resources (connections, workers, background goroutines).
Close()
}
Runtime runs agent workloads against a backend.
Per-run lifecycle (status, cancel, wait-for-result, event subscription) lives on the handles returned by Runtime.Run / Runtime.GetRunHandle and Runtime.Stream / Runtime.GetStreamHandle — not on Runtime itself. Runtime starts or reconnects to runs and releases shared resources. Stream approvals go through StreamHandle.Approve; Runtime.OnApproval remains only for deprecated agent-level compat.
type StreamHandle ¶ added in v0.3.0
type StreamHandle interface {
// ID returns the unique run identifier, stable across process restarts when the
// backend supports reconnect (e.g. Temporal workflow ID).
ID() string
// Status returns the current [types.RunStatus] of this run.
// Returns [ErrRunNotFound] when the underlying run is no longer known.
Status(ctx context.Context) (types.RunStatus, error)
// Cancel requests cancellation of this run.
// Returns [ErrRunAlreadyCompleted] when the run has already finished.
// Returns [ErrRunNotFound] when the underlying run is no longer known.
Cancel(ctx context.Context) error
// Get blocks until the stream run finishes and returns the result.
// Cancelling ctx unblocks Get but does NOT cancel the agent run itself —
// use [StreamHandle.Cancel] for that.
Get(ctx context.Context) (*types.AgentRunResult, error)
// Done returns a channel that is closed when the stream run finishes (success or failure).
// Safe to call multiple times; always returns the same channel.
Done() <-chan struct{}
// Approve completes a tool approval request using the token from the approval event
// and the chosen status (e.g., [ApprovalStatusApproved] or [ApprovalStatusRejected]).
// Returns [ErrApprovalAlreadyResolved] when the token was already completed.
Approve(ctx context.Context, approvalToken string, status types.ApprovalStatus) error
// Events subscribes to this run's event stream starting at fromOffset.
// fromOffset == 0 means from the beginning of the run (first-time subscriber).
// fromOffset > 0 resumes after a crash or reconnect (Temporal only; LocalRuntime
// returns [ErrStreamOffsetNotSupported] for fromOffset > 0).
// Returns [ErrRunAlreadyCompleted] if the run has already finished.
// Returns [ErrRunNotFound] if the run is unknown.
// The channel is closed after the terminal lifecycle event (RUN_FINISHED / RUN_ERROR).
Events(ctx context.Context, fromOffset int64) (<-chan events.AgentEvent, error)
}
StreamHandle is the per-run control surface returned by Runtime.Stream or Runtime.GetStreamHandle. Status, Cancel, Get, Done, and Events operate on this run only — callers never pass a runID back into Runtime for those operations.
type SubAgentSpec ¶ added in v0.1.12
type SubAgentSpec struct {
Name string // human-readable agent name
ToolName string // tool name used to invoke this sub-agent (key in runtime route maps)
Runtime Runtime // the sub-agent's runtime instance
Children []*SubAgentSpec
// Tools is the registry-resolved tool list for this sub-agent at request time.
Tools []interfaces.Tool `json:"-"`
}
SubAgentSpec describes one sub-agent in the delegation tree passed from pkg/agent to a runtime. The runtime builds its own internal routing structures from this tree; no runtime-specific fields are present here. ToolName is the sanitised tool name derived from Name and used as the map key.
type WorkerRuntime ¶ added in v0.1.1
type WorkerRuntime interface {
Runtime
// Start begins polling; it typically blocks until Stop is called or ctx is cancelled.
Start(ctx context.Context) error
// Stop stops polling and releases worker resources.
Stop()
}
WorkerRuntime is Runtime plus optional in-process task-queue polling (e.g. Temporal worker). [AgentWorker] and embedded local workers type-assert Runtime to WorkerRuntime for Start/Stop; backends that only act as clients implement Runtime but not this interface.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package base provides the shared runtime struct and core execution methods used by both the local and temporal runtime backends.
|
Package base provides the shared runtime struct and core execution methods used by both the local and temporal runtime backends. |
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Package temporal contains helpers for integrating this SDK with go.temporal.io (client, worker, etc.).
|
Package temporal contains helpers for integrating this SDK with go.temporal.io (client, worker, etc.). |