Documentation
¶
Index ¶
- type AgentLoopInput
- type AgentLoopResult
- type LocalRuntime
- func (rt *LocalRuntime) Approve(_ context.Context, approvalToken string, status types.ApprovalStatus) error
- func (rt *LocalRuntime) Close()
- func (rt *LocalRuntime) GetRunHandle(_ context.Context, _ string) (sdkruntime.RunHandle, error)
- func (rt *LocalRuntime) GetStreamHandle(_ context.Context, _ string) (sdkruntime.StreamHandle, error)
- func (rt *LocalRuntime) Run(ctx context.Context, req *sdkruntime.RunRequest) (sdkruntime.RunHandle, error)
- func (rt *LocalRuntime) RunAgentLoop(ctx context.Context, input AgentLoopInput) (*AgentLoopResult, error)
- func (rt *LocalRuntime) Stream(ctx context.Context, req *sdkruntime.RunRequest) (sdkruntime.StreamHandle, error)
- type Option
- func WithAgentConfig(cfg sdkruntime.AgentConfig) Option
- func WithAgentSpec(spec sdkruntime.AgentSpec) Option
- func WithApprovalHandler(fn types.ApprovalHandler) Option
- func WithLogger(l logger.Logger) Option
- func WithMetrics(metrics interfaces.Metrics) Option
- func WithToolExecutionMode(mode types.AgentToolExecutionMode) Option
- func WithTracer(tracer interfaces.Tracer) Option
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 RunAgentLoop 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
}
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 LocalRuntime ¶
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) Approve ¶
func (rt *LocalRuntime) Approve(_ context.Context, approvalToken string, status types.ApprovalStatus) error
Approve resolves a pending tool approval registered during a streaming run. When a tool requires approval, executeSingleTool registers a token and blocks; the caller receives a CUSTOM event on the stream with that token and calls Approve to unblock. Returns types.ErrApprovalAlreadyResolved when the token is unknown or was already resolved (same sentinel as Temporal when CompleteActivity reports not found).
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.
func (*LocalRuntime) GetRunHandle ¶ added in v0.3.0
func (rt *LocalRuntime) GetRunHandle(_ context.Context, _ string) (sdkruntime.RunHandle, error)
GetRunHandle always returns types.ErrRunNotFound. LocalRuntime does not track runs durably; same-process live handles are managed by the agent run registry. After a process crash there is nothing to reconnect to. Never returns types.ErrRunAlreadyCompleted — Local cannot distinguish finished vs unknown; the agent run registry handles in-process terminal checks.
func (*LocalRuntime) GetStreamHandle ¶ added in v0.3.0
func (rt *LocalRuntime) GetStreamHandle(_ context.Context, _ string) (sdkruntime.StreamHandle, error)
GetStreamHandle always returns types.ErrStreamNotFound. LocalRuntime does not track streams durably; same-process live handles are managed by the agent stream registry. After a process crash there is nothing to reconnect to. Never returns types.ErrRunAlreadyCompleted — Local cannot distinguish finished vs unknown; the agent stream registry handles in-process terminal checks.
func (*LocalRuntime) Run ¶ added in v0.3.0
func (rt *LocalRuntime) Run(ctx context.Context, req *sdkruntime.RunRequest) (sdkruntime.RunHandle, error)
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) RunAgentLoop ¶
func (rt *LocalRuntime) RunAgentLoop(ctx context.Context, input AgentLoopInput) (*AgentLoopResult, error)
RunAgentLoop executes the full agent loop in-process using base.Runtime core methods. It mirrors the orchestration logic of AgentWorkflow but calls base methods directly instead of dispatching to Temporal activities. Events are published to rt.eventbus on input.ChannelName; callers subscribe to that channel.
func (*LocalRuntime) Stream ¶ added in v0.3.0
func (rt *LocalRuntime) Stream(ctx context.Context, req *sdkruntime.RunRequest) (sdkruntime.StreamHandle, error)
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 WithLogger ¶
func WithMetrics ¶
func WithMetrics(metrics interfaces.Metrics) Option
func WithToolExecutionMode ¶
func WithToolExecutionMode(mode types.AgentToolExecutionMode) Option
func WithTracer ¶
func WithTracer(tracer interfaces.Tracer) Option