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 ¶
This section is empty.
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 AgentExecution ¶
type AgentExecution struct {
LLM AgentLLM
Tools AgentTools
Session AgentSession
Limits AgentLimits
}
AgentExecution groups per-run execution inputs for custom Runtime implementations. Sub-structs stay stable so callers do not depend on a single flat blob that might be reshaped later. Temporal-backed runtimes typically use worker-local configuration for activities; this is a snapshot.
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 AgentSession ¶
type AgentSession struct {
Conversation interfaces.Conversation
ConversationSize int
}
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 for one run. It is attached to [ExecuteRequest.AgentSpec] so custom Runtime implementations can read name, prompts, and response format without importing pkg/agent.
type AgentTools ¶
type AgentTools struct {
Tools []interfaces.Tool
Registry interfaces.ToolRegistry
ApprovalPolicy interfaces.AgentToolApprovalPolicy
}
AgentTools is registered tools, optional registry, and approval policy for this run.
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
ConversationID string
StreamingEnabled bool
// EventTypes filters streamed events; empty means default (implementation-defined, often all types).
EventTypes []types.AgentEventType
SubAgentRoutes map[string]types.SubAgentRoute
MaxSubAgentDepth int
ApprovalHandler types.ApprovalHandler
// AgentSpec is identity and output-format metadata for this run (name, description, system prompt, response format).
AgentSpec *AgentSpec
// AgentExecution is LLM, tools, conversation, sampling, and policy for this run.
AgentExecution *AgentExecution
}
ExecuteRequest carries one execution request from Agent to Runtime.
AgentSpec and AgentExecution are populated by pkg/agent from its configuration so implementations can read identity (including agent name on AgentSpec.Name), prompts, LLM, tools, and policies for this run. Implementations may ignore fields they do not use.
type LLMSampling ¶
type LLMSampling struct {
Temperature *float64
MaxTokens int
TopP *float64
TopK *int
Reasoning *interfaces.LLMReasoning
}
LLMSampling holds per-run sampling overrides (temperature, max tokens, top-p/k, reasoning). Semantics match agent LLMSampling / internal types.LLMSampling.
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 is on req.AgentSpec.Name when AgentSpec is set.
Execute(ctx context.Context, req *ExecuteRequest) (*types.AgentResponse, error)
// ExecuteStream starts the run and returns a channel of AgentEvent. Events are streamed until
// AgentEventComplete from this agent (the root of the run). Complete events from delegated
// sub-agents are still delivered but do not close the stream. After that root complete, the
// channel may remain open until the implementation finishes the run (e.g. backend cleanup), then closes.
// For approvals (tool or delegation), receive AgentEventApproval and call the approval path
// provided by the agent package (e.g. OnApproval in streaming examples).
// When using conversation, pass the conversation ID on the request.
// Agent identity is on req.AgentSpec.Name when AgentSpec is set.
ExecuteStream(ctx context.Context, req *ExecuteRequest) (chan *types.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 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 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.). |