local

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentLoopInput

type AgentLoopInput struct {
	UserPrompt       string
	ConversationID   string
	StreamingEnabled bool
	// Tools is the resolved tool list for this run.
	Tools []interfaces.Tool
	// ChannelName is the eventbus channel events are published to during this run.
	// Sub-agents receive the parent's ChannelName so their events go directly to the parent stream.
	// Empty = no event fanout.
	ChannelName string
	// EventTypes filters which events are published to ChannelName (same semantics as Temporal).
	// Empty = publish nothing; ["*"] = all types; a specific list = only those types.
	EventTypes []events.AgentEventType
	// ApprovalHandler is called when a tool requires human approval. May be nil (approval → unavailable).
	ApprovalHandler types.ApprovalHandler
	// SubAgentRoutes maps sub-agent tool name → local route. Built by the local runtime from
	// ExecuteRequest.SubAgents before executeAgentLoop is called. Mirrors AgentWorkflowInput.SubAgentRoutes.
	SubAgentRoutes map[string]subAgentRoute
	// SubAgentDepth is the current nesting depth (0 = top-level, 1 = direct sub-agent, etc.).
	SubAgentDepth int
	// MaxSubAgentDepth caps recursive delegation. Mirrors AgentWorkflowInput.MaxSubAgentDepth.
	MaxSubAgentDepth int
	// MemoryScope is resolved before the run and used for recall/store.
	MemoryScope interfaces.MemoryScope
	// RunID is the stable identifier for this agent run; passed to LLM hooks via [RunMeta].
	RunID string
	// BudgetTracker tracks per-run token and cost usage against the configured limits.
	// Nil when no budget is configured. Shared with nested subagent calls; subagent calls
	// set EnforceBudget=false so only the root run triggers OnExceeded.
	BudgetTracker *base.BudgetTracker
	// EnforceBudget controls whether the budget check runs after each LLM call.
	// True on root runs when WithBudget is configured; false on nested subagent calls
	// so the parent run's tracker accumulates child usage and enforces the limit.
	EnforceBudget bool
	// contains filtered or unexported fields
}

AgentLoopInput holds per-run execution inputs for one local agent run. Mirrors AgentWorkflowInput (Temporal) for in-process execution — same fields, same semantics. Static agent wiring lives on the runtime base.Runtime.AgentConfig; resolved tools are per-run on Tools.

type AgentLoopResult

type AgentLoopResult struct {
	Content   string
	LLMUsage  *interfaces.LLMUsage
	Telemetry *types.AgentTelemetry
}

AgentLoopResult is the outcome of a completed local agent run.

type LocalConfig added in v0.3.6

type LocalConfig struct {
	// Durability enables durable-go-backed execution. nil (the zero value, and the
	// implicit default when [WithLocalConfig] is never called) means true — local runtime
	// is durable by default. Set to a pointer to false (see [DurabilityOff] in
	// pkg/agent/runtime/local) to opt out and use the original pure in-memory execution path.
	Durability *bool

	// Engine, when set, is used as-is instead of constructing one from DataDir/knobs below.
	// The caller retains ownership: LocalRuntime.Close does not close a caller-supplied
	// Engine. Takes priority over every field below. Multiple agents/tasks may share one
	// Engine (see [durable.RegisterTask] — one taskID per agent name).
	Engine *durable.Engine

	// DataDir is the durable-go journal directory for an engine this runtime constructs
	// (ignored when Engine is set). Default: "./agent_data/<agent_name>" (sanitized for
	// use as a durable-go taskID), or "./agent_data/default" when the agent has no name.
	//
	// DataDir is exclusive-locked per OS process (in-process occupancy plus an OS flock) —
	// running more than one process/replica against the same DataDir will fail engine
	// construction for the second one (durable.ErrEngineLocked) or block up to LockTimeout.
	// Multi-replica deployments must set a distinct DataDir per instance (e.g. derived from
	// hostname or pod name).
	DataDir string

	// AutoPurgeAge is how long a Completed/Failed run is kept before automatic deletion.
	// Running and Waiting runs (e.g. a pending approval) are never purged regardless of age.
	// 0 uses the default (7 days). Negative disables auto-purge entirely.
	AutoPurgeAge time.Duration

	// AutoPurgeInterval is how often the purge sweep runs. 0 uses the default (1 hour).
	// Ignored when AutoPurgeAge is negative.
	AutoPurgeInterval time.Duration

	// MaxRetries is the default durable-go task retry count for this engine. 0 (default)
	// means a task body runs once; a step failure still stops task-level retries regardless
	// of this value (durable-go: step failures are not retried at the task level).
	MaxRetries int

	// Timeout bounds one run's total durable-go execution time. 0 means no timeout (the
	// durable-go default) — an un-cancelled run (or a step stuck waiting, e.g. an
	// approval nobody ever answers) can then run unbounded. Set this in production.
	Timeout time.Duration

	// LockTimeout bounds how long engine construction waits to acquire the DataDir OS
	// lock. 0 uses the durable-go default (2s).
	LockTimeout time.Duration
}

LocalConfig configures durable-go-backed execution for LocalRuntime. The zero value (and not calling WithLocalConfig at all) both mean the same thing: local runtime is durable by default, using an engine constructed from these (zero-value) defaults.

type LocalRuntime

type LocalRuntime struct {
	base.Runtime
	// contains filtered or unexported fields
}

LocalRuntime executes the agent loop in-process, embedding base.Runtime for shared core methods and holding local-specific fields (logger, eventbus).

func NewLocalRuntime

func NewLocalRuntime(opts ...Option) (*LocalRuntime, error)

NewLocalRuntime constructs a LocalRuntime from functional options.

func (*LocalRuntime) Close

func (rt *LocalRuntime) Close()

Close releases runtime resources. When this runtime owns the event bus ([ownsEventBus]), the bus is closed; shared buses from [setEventBus] are left alone. When this runtime constructed its durable-go engine ([ownsEngine]), the engine is closed too — that cancels every in-flight run on it, not just this agent's. A caller-supplied LocalConfig.Engine is never closed here; the caller owns it.

func (*LocalRuntime) GetRunHandle added in v0.3.0

func (rt *LocalRuntime) GetRunHandle(ctx context.Context, runID string) (sdkruntime.RunHandle, error)

GetRunHandle reconnects to runID.

Non-durable: always returns types.ErrRunNotFound — LocalRuntime tracks nothing durably; same-process live handles are managed by the agent run registry, and after a process crash there is nothing to reconnect to.

Durable (LocalConfig.Durability true, the default): looks up runID's persisted TaskInfo. A terminal run (Completed/Failed, including a cancelled run — see durable.ErrRunCancelled) returns types.ErrRunAlreadyCompleted; an unknown runID returns types.ErrRunNotFound. Otherwise re-drives it via durable.RunTask, which resumes from wherever it left off — fast-replaying already-completed steps (no LLM/tool re-calls) and continuing live from the first new step. Tools are rehydrated via ToolsResolver when set (nil otherwise — see durableExec); sub-agent delegation routes are not recoverable across a process restart on this interface (no request payload survives it) — a delegation tool call on a resumed run gets the existing "Sub-agent delegation not available for this runtime" fallback message.

func (*LocalRuntime) GetStreamHandle added in v0.3.0

func (rt *LocalRuntime) GetStreamHandle(ctx context.Context, runID string) (sdkruntime.StreamHandle, error)

GetStreamHandle reconnects to runID's stream.

Non-durable: always returns types.ErrStreamNotFound — LocalRuntime tracks nothing durably; same-process live handles are managed by the agent stream registry, and after a process crash there is nothing to reconnect to.

Durable (LocalConfig.Durability true, the default): looks up runID's persisted TaskInfo the same way LocalRuntime.GetRunHandle does (types.ErrStreamNotFound / types.ErrRunAlreadyCompleted in place of the Run-path sentinels). On success, subscribes a fresh channel, replays already-completed steps as one coarse events.AgentCustomEventNameStepReplayed event each (see replayStepHistory — step granularity only, never the original token-by-token stream; document this to callers), then re-drives the run via durable.RunTask so anything not yet done continues live on that same channel. See LocalRuntime.GetRunHandle for the tools/sub-agent-routes rehydration caveat, which applies identically here.

func (*LocalRuntime) OnApproval added in v0.3.1

func (rt *LocalRuntime) OnApproval(ctx context.Context, approvalToken string, status types.ApprovalStatus) error

OnApproval is a deprecated Runtime-interface wrapper around [LocalRuntime.approve]. Prefer sdkruntime.StreamHandle.Approve. Removed in v0.4.0.

func (*LocalRuntime) Run added in v0.3.0

Run starts the agent loop in a background goroutine and returns a sdkruntime.RunHandle immediately. Approval is handled inline via rt.approvalHandler (no out-of-band tokens). Use sdkruntime.RunHandle.Get or sdkruntime.RunHandle.Done to wait for completion.

func (*LocalRuntime) Stream added in v0.3.0

Stream starts the agent loop in a background goroutine and returns a sdkruntime.StreamHandle immediately. Subscribe via sdkruntime.StreamHandle.Events (offset 0 only on LocalRuntime). RUN_STARTED is emitted before the loop begins; RUN_FINISHED or RUN_ERROR closes the channel.

Cancelling ctx cancels the agent run. The context passed to sdkruntime.StreamHandle.Events is independent on Temporal; on LocalRuntime Events ignores that ctx (channel already open). Agent Limits.Timeout applies when ctx has no deadline.

type Option

type Option func(*LocalRuntime)

func WithAgentConfig added in v0.2.2

func WithAgentConfig(cfg sdkruntime.AgentConfig) Option

func WithAgentSpec

func WithAgentSpec(spec sdkruntime.AgentSpec) Option

func WithApprovalHandler added in v0.3.0

func WithApprovalHandler(fn types.ApprovalHandler) Option

WithApprovalHandler sets the Run-path approval callback (from agent WithApprovalHandler). Stream uses CUSTOM events + Approve instead.

func WithLocalConfig added in v0.3.6

func WithLocalConfig(cfg *LocalConfig) Option

WithLocalConfig sets durable-go execution configuration. Nil (or never calling this option) means the zero-value LocalConfig — durable by default. See LocalConfig for field semantics.

func WithLogger

func WithLogger(l logger.Logger) Option

func WithMetrics

func WithMetrics(metrics interfaces.Metrics) Option

func WithToolExecutionMode

func WithToolExecutionMode(mode types.AgentToolExecutionMode) Option

func WithToolsResolver added in v0.3.6

func WithToolsResolver(fn ToolsResolver) Option

WithToolsResolver sets the callback LocalRuntime.GetRunHandle / LocalRuntime.GetStreamHandle use to rebuild a resumed durable run's tool list. Optional — nil means a resumed run has no tools (LLM calls still work; tool calls the LLM attempts will run with an empty tool list).

func WithTracer

func WithTracer(tracer interfaces.Tracer) Option

type ToolsResolver added in v0.3.6

type ToolsResolver func(ctx context.Context) ([]interfaces.Tool, error)

ToolsResolver resolves the static tool list for a run with no live per-request Tools — used to rehydrate a resumed durable run after a process restart (see [LocalRuntime.toolsResolver]). Matches github.com/agenticenv/agent-sdk-go/pkg/agent/runtime.RuntimeParams.ToolsResolver.

Jump to

Keyboard shortcuts

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