base

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package base provides the shared runtime struct and core execution methods used by both the local and temporal runtime backends. It has no dependency on any backend-specific SDK (no Temporal, no workflow/activity imports).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLLMSampling

func ApplyLLMSampling(s *types.LLMSampling, req *interfaces.LLMRequest)

ApplyLLMSampling copies non-zero sampling fields from s onto req. A nil sampling value is a no-op.

func CloneLLMUsage

func CloneLLMUsage(u *interfaces.LLMUsage) *interfaces.LLMUsage

CloneLLMUsage returns a shallow copy of u, or nil when u is nil.

func FindToolByName

func FindToolByName(tools []interfaces.Tool, toolName string) (interfaces.Tool, bool)

FindToolByName returns the first tool whose Name() matches toolName.

func FormatMemoryEntries added in v0.2.2

func FormatMemoryEntries(entries []interfaces.MemoryEntry) string

FormatMemoryEntries formats memories for injection into the LLM system prompt.

func FormatRetrieverDocs

func FormatRetrieverDocs(docs []interfaces.Document) string

FormatRetrieverDocs formats a list of documents for injection into the LLM system prompt. Each entry is rendered as "[N] content\n(source: s, score: 0.XX)\n\n".

func GetConversationID added in v0.2.0

func GetConversationID(req *runtime.ExecuteRequest) string

func MergeLLMUsage

func MergeLLMUsage(acc, add *interfaces.LLMUsage) *interfaces.LLMUsage

MergeLLMUsage accumulates add into acc and returns the result. Either argument may be nil; when both are nil, nil is returned.

func NewAgentTelemetry added in v0.2.2

func NewAgentTelemetry(startedAt time.Time) *types.AgentTelemetry

func SubAgentQuery

func SubAgentQuery(args map[string]any) string

SubAgentQuery extracts the query string from a sub-agent tool call's args map.

func SubAgentScope added in v0.2.2

func SubAgentScope(parent interfaces.MemoryScope, subAgentID string) interfaces.MemoryScope

SubAgentScope derives memory scope for a delegated sub-agent from the parent run scope.

Types

type AuthorizeResult

type AuthorizeResult struct {
	Allowed bool
	Reason  string
}

AuthorizeResult is the outcome of a programmatic tool authorization check. When Allowed is false, Reason carries the denial message for logging/events.

type ExecuteLLMInput added in v0.2.2

type ExecuteLLMInput struct {
	Logger           logger.Logger
	AgentName        string
	MessageID        string
	RunID            string
	Iteration        int
	Messages         []interfaces.Message
	SkipTools        bool
	MemoryContext    string
	RetrieverContext string
	Tools            []interfaces.Tool
	Emit             func(events.AgentEvent)
}

type ExecuteMemoryRecallInput added in v0.2.3

type ExecuteMemoryRecallInput struct {
	Logger    logger.Logger
	RunID     string
	Iteration int
	Scope     interfaces.MemoryScope
	Query     string
}

ExecuteMemoryRecallInput holds per-invocation inputs for Runtime.ExecuteMemoryRecall. RunID and Iteration populate hooks.RunMeta for memory load middleware hooks.

type ExecuteMemoryStoreInput added in v0.2.3

type ExecuteMemoryStoreInput struct {
	Logger    logger.Logger
	RunID     string
	Iteration int
	Scope     interfaces.MemoryScope
	Messages  []interfaces.Message
}

ExecuteMemoryStoreInput holds per-invocation inputs for Runtime.ExecuteMemoryStore. RunID and Iteration populate hooks.RunMeta for memory store middleware hooks.

type ExecuteRetrieversInput added in v0.2.3

type ExecuteRetrieversInput struct {
	Logger    logger.Logger
	RunID     string
	Iteration int
	Query     string
}

ExecuteRetrieversInput holds per-invocation inputs for Runtime.ExecuteRetrievers. RunID and Iteration populate hooks.RunMeta for retrieve middleware hooks.

type ExecuteToolInput added in v0.2.3

type ExecuteToolInput struct {
	Logger     logger.Logger
	Tools      []interfaces.Tool
	ToolName   string
	Args       map[string]any
	ToolCallID string
	RunID      string
	Iteration  int
}

ExecuteToolInput holds per-invocation inputs for Runtime.ExecuteTool. RunID and Iteration populate hooks.RunMeta for tool middleware hooks.

type LLMResult

type LLMResult struct {
	Content   string
	ToolCalls []ToolCallRequest
	Usage     *interfaces.LLMUsage
}

LLMResult is the result of a successful LLM call. Content holds the assistant text; ToolCalls holds any tool invocations resolved against the registered tools list (NeedsApproval pre-computed from the approval policy).

type MemoryResult added in v0.2.2

type MemoryResult struct {
	Context       string
	TotalRecalls  int64
	FailedRecalls int64
}

MemoryResult is the outcome of ExecuteMemoryRecall.

type RetrieverResult added in v0.2.2

type RetrieverResult struct {
	Context        string
	TotalSearches  int64
	FailedSearches int64
}

RetrieverResult is the outcome of ExecuteRetrievers (prefetch / hybrid pre-loop).

type Runtime

type Runtime struct {
	AgentSpec   runtime.AgentSpec
	AgentConfig runtime.AgentConfig
	Tracer      interfaces.Tracer
	Metrics     interfaces.Metrics
	// ToolExecutionMode controls whether tool calls in one LLM round are executed
	// in parallel or sequentially. Defaults to parallel when empty.
	ToolExecutionMode types.AgentToolExecutionMode
}

Runtime holds the execution inputs shared by all runtime backends. Local and Temporal runtimes embed this struct and call its methods directly.

func (*Runtime) AuthorizeTool

func (rt *Runtime) AuthorizeTool(ctx context.Context, log logger.Logger, tools []interfaces.Tool, toolName string, args map[string]any) (AuthorizeResult, error)

AuthorizeTool checks programmatic authorization for a tool before approval/execution. Tools that do not implement interfaces.ToolAuthorizer are allowed by default.

func (*Runtime) BuildLLMRequest

func (rt *Runtime) BuildLLMRequest(messages []interfaces.Message, skipTools bool, memoryContext, retrieverContext string, tools []interfaces.Tool) *interfaces.LLMRequest

BuildLLMRequest constructs an LLMRequest from the given messages and options. SystemMessage is the static system prompt only. When memoryContext or retrieverContext is non-empty each is prepended as a labeled user message (memory then RAG) before the conversation messages. Message content is sanitized for the LLM copy only; the caller's slice is not modified. tools is the per-run resolved tool list from runtime.ExecuteRequest or activity resolve.

func (*Runtime) ExecuteLLM

func (rt *Runtime) ExecuteLLM(ctx context.Context, input ExecuteLLMInput) (*LLMResult, error)

ExecuteLLM calls the LLM in non-streaming mode, records metrics and traces, emits TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END events, and returns LLMResult. messageID and agentName are used only for event construction; emit may be nil.

func (*Runtime) ExecuteLLMStream

func (rt *Runtime) ExecuteLLMStream(ctx context.Context, input ExecuteLLMInput) (*LLMResult, error)

ExecuteLLMStream calls the LLM in streaming mode. When the LLM client does not support streaming it falls back to Generate automatically. Delta events (text content, reasoning) are emitted via emit as chunks arrive; a final TEXT_MESSAGE_START/CONTENT/END triple is emitted for non-streaming fallback. emit may be nil.

func (*Runtime) ExecuteMemoryRecall added in v0.2.2

func (rt *Runtime) ExecuteMemoryRecall(ctx context.Context, input ExecuteMemoryRecallInput) (*MemoryResult, error)

ExecuteMemoryRecall loads scoped memories for query and returns formatted prompt context.

func (*Runtime) ExecuteMemoryStore added in v0.2.2

func (rt *Runtime) ExecuteMemoryStore(ctx context.Context, input ExecuteMemoryStoreInput) error

ExecuteMemoryStore extracts long-term memories from the run and persists them in scope.

func (*Runtime) ExecuteRetrievers

func (rt *Runtime) ExecuteRetrievers(ctx context.Context, input ExecuteRetrieversInput) (*RetrieverResult, error)

ExecuteRetrievers runs all configured retrievers in parallel for the given query and returns a combined document context string for injection into the LLM system prompt. Partial failures are logged and skipped; all retrievers failing returns an error.

func (*Runtime) ExecuteTool

func (rt *Runtime) ExecuteTool(ctx context.Context, input ExecuteToolInput, memScope interfaces.MemoryScope) (string, error)

ExecuteTool runs a tool with optional memory scope; save_memory on on-demand store routes to [StoreMemoryRecords]. Retriever tools use [Runtime.executeRetrieverTool] inside [Runtime.executeTool]. For types.ToolKindNative and types.ToolKindMCP tools, hooks.BeforeToolHook and

func (*Runtime) FetchConversationMessages

func (rt *Runtime) FetchConversationMessages(ctx context.Context, log logger.Logger, conversationID string) ([]interfaces.Message, error)

FetchConversationMessages loads prior messages from the conversation store. Returns an error when no conversation is configured or the store call fails.

func (*Runtime) MemoryConfigured added in v0.2.2

func (rt *Runtime) MemoryConfigured() bool

MemoryConfigured reports whether long-term memory is wired on the runtime.

func (*Runtime) MemoryStoreOnDemand added in v0.2.2

func (rt *Runtime) MemoryStoreOnDemand() bool

MemoryStoreOnDemand reports whether save_memory tool store is active.

func (*Runtime) RecallEnabled added in v0.2.2

func (rt *Runtime) RecallEnabled() bool

RecallEnabled reports whether the SDK should load memories before each run.

func (*Runtime) RequiresApproval

func (rt *Runtime) RequiresApproval(t interfaces.Tool) bool

RequiresApproval reports whether t requires human approval before execution. When no approval policy is configured the tool's own ApprovalRequired flag is used.

func (*Runtime) ResolveMemoryScope added in v0.2.2

func (rt *Runtime) ResolveMemoryScope(ctx context.Context) (interfaces.MemoryScope, error)

ResolveMemoryScope builds scope from the request context using configured resolvers.

func (*Runtime) RunEndMemoryStoreEnabled added in v0.2.2

func (rt *Runtime) RunEndMemoryStoreEnabled() bool

RunEndMemoryStoreEnabled reports whether run-end memory store runs (memory.StoreModeAlways).

func (*Runtime) StoreMemoryRecords added in v0.2.2

func (rt *Runtime) StoreMemoryRecords(ctx context.Context, input StoreMemoryRecordsInput) error

StoreMemoryRecords persists records through kind policy, dedup, TTL, and the memory backend.

type StoreMemoryRecordsInput added in v0.2.3

type StoreMemoryRecordsInput struct {
	Logger    logger.Logger
	RunID     string
	Iteration int
	Scope     interfaces.MemoryScope
	Records   []interfaces.MemoryRecord
}

StoreMemoryRecordsInput holds per-invocation inputs for Runtime.StoreMemoryRecords. RunID and Iteration populate hooks.RunMeta for memory store middleware hooks.

type ToolCallRequest

type ToolCallRequest struct {
	ToolCallID      string
	ToolName        string
	ToolDisplayName string
	ToolKind        types.ToolKind
	Args            map[string]any
	NeedsApproval   bool
}

ToolCallRequest describes one tool call returned by the LLM. NeedsApproval is pre-computed from the tool approval policy so orchestration loops (local agent loop, temporal workflow) do not need to re-evaluate the policy.

Jump to

Keyboard shortcuts

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