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
- Variables
- type AgentConfig
- type AgentLLM
- type AgentLimits
- type AgentMemory
- type AgentRetrievers
- type AgentSession
- type AgentSpec
- type EventBusRuntime
- type ExecuteRequest
- type ExecutionConfig
- type ExecutionConfigs
- type ExecutionPolicies
- type ExecutionPolicy
- type LLMSampling
- type RetryPolicy
- type Runtime
- type SubAgentSpec
- type WorkerRuntime
Constants ¶
const SubAgentToolParamQuery = "query"
SubAgentToolParamQuery is the tool/JSON parameter name for the query sent to a sub-agent.
Variables ¶
var ErrApprovalNotSupported = errors.New("runtime: approval not supported")
ErrApprovalNotSupported is returned by Runtime.Approve when the runtime does not use token-based approval.
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 EventBusRuntime ¶ added in v0.1.1
type EventBusRuntime interface {
Runtime
SetEventBus(eventbus eventbus.EventBus)
GetEventBus() eventbus.EventBus
}
EventBusRuntime extends Runtime with in-process event bus access for sub-agent delegation and streaming fan-in. SDK backends (e.g. Temporal) implement it; pkg/agent asserts to it when wiring the agent tree. Custom Runtime implementations need only implement Runtime unless they participate in that fan-in.
type ExecuteRequest ¶
type ExecuteRequest struct {
UserPrompt string `json:"user_prompt"`
// RunOptions is the per-call options forwarded from pkg/agent (e.g. conversation session). May be nil.
// Runtimes must use [base.GetConversationID] to safely extract the conversation ID rather than
// accessing the nested fields directly, so the nil-check is centralised.
RunOptions *types.AgentRunOptions `json:"run_options,omitempty"`
StreamingEnabled bool `json:"streaming_enabled"`
// EventTypes filters streamed 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:"-"`
ApprovalHandler types.ApprovalHandler `json:"approval_handler"`
}
ExecuteRequest carries one execution request from Agent to 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 Retries mean "use SDK default" at resolve time; see [ResolveExecPolicy].
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 Runtime ¶
type Runtime interface {
// Execute runs one execution and returns the result. The agent package supplies approval via ExecuteRequest when needed.
// Use WithTimeout or a context with deadline to avoid blocking.
// When using conversation, pass the conversation ID on the request; agent and worker must use the same ID.
// Agent identity lives on the runtime [AgentSpec] configured at construction.
Execute(ctx context.Context, req *ExecuteRequest) (*types.AgentRunResult, error)
// ExecuteStream starts the run and returns a channel of AgentEvent. Streams RUN_* lifecycle,
// streaming assistant/tool/reasoning events, and CUSTOM approvals until RUN_FINISHED or RUN_ERROR ends the stream.
// Delegated workflows may emit their own RUN_FINISHED; semantics for "root" completion are defined in pkg/agent.
// After the terminal lifecycle event the channel may stay open briefly, then closes.
// For approvals (tool or delegation), receive CUSTOM (AgentEventTypeCustom) events and use the agent
// package approval path (e.g. OnApproval with the token from the custom payload).
// When using conversation, pass the conversation ID on the request.
ExecuteStream(ctx context.Context, req *ExecuteRequest) (<-chan events.AgentEvent, error)
// Approve completes a pending tool approval when the runtime uses out-of-band approval
// (e.g. Temporal CompleteActivity). Returns ErrApprovalNotSupported if not applicable.
Approve(ctx context.Context, approvalToken string, status types.ApprovalStatus) error
// Close closes the runtime and releases resources.
Close()
}
Runtime executes agent runs against a backend.
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.). |