agent

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAgentAlreadyRunning = errors.New("agent already has an active run")

ErrAgentAlreadyRunning is returned when Run, RunAsync, or RunStream is called while a run is already in progress.

View Source
var ErrSubAgentToolNotExecutable = errors.New("sub-agent tool must be executed via workflow, not Execute()")

ErrSubAgentToolNotExecutable is returned by SubAgentTool.Execute. Normal runs delegate via AgentWorkflow child workflows; Execute() is only for misconfigured or direct activity calls.

Functions

func AllowlistToolApprovalPolicy

func AllowlistToolApprovalPolicy(toolNames ...string) interfaces.AgentToolApprovalPolicy

AllowlistToolApprovalPolicy allows only the listed tools without approval; all others require approval.

func AutoToolApprovalPolicy

func AutoToolApprovalPolicy() interfaces.AgentToolApprovalPolicy

AutoToolApprovalPolicy allows all tools without approval. Use when you trust the agent.

func NewSubAgentTool

func NewSubAgentTool(sub *Agent) interfaces.Tool

NewSubAgentTool wraps a sub-agent as a tool for the parent LLM. Name is derived from the sub-agent's Name when set; otherwise a stable default is used. Returns nil if sub is nil; callers should skip nil tools.

func SubAgentToolName

func SubAgentToolName(a *Agent) string

SubAgentToolName returns the tool name the parent LLM and workflow routing use for this sub-agent. Single source: NewSubAgentTool, validateToolsAndSubAgentNames, and buildSubAgentRoutes must use this (or Name() on the tool).

Display names are not used verbatim: runs of non-alphanumeric ASCII become a single underscore; leading/trailing underscores are trimmed. An empty or all-symbol name falls back to subagent_<Agent.ID> so the name stays stable and API-safe.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent runs LLM-backed workflows via Temporal. It holds agentConfig and client-side state (agentChannel, event worker). Uses AgentWorker for run workflow execution.

func NewAgent

func NewAgent(opts ...Option) (*Agent, error)

NewAgent creates an Agent with the given options. Event worker is started lazily when RunStream is called or when approvals are needed.

func (*Agent) AgentEventWorkflow

func (a *Agent) AgentEventWorkflow(ctx workflow.Context) error

AgentEventWorkflow is one per agent. Receives events and approval requests via workflow updates. Each update includes runID so events are published to per-run channels (agent_event_{runID}, approval_{runID}). Completes only when it receives the "complete" signal (on agent Close).

func (*Agent) Close

func (a *Agent) Close()

Close stops workers, terminates the active run if any, signals the event workflow to complete, waits for it to finish, then closes the Temporal client. Only one run can be active per agent.

func (*Agent) EventPublishActivity

func (a *Agent) EventPublishActivity(ctx context.Context, channel string, event *AgentEvent) error

EventPublishActivity publishes an event to the given channel (agent_event_<main-workflow-id>).

func (*Agent) OnApproval

func (a *Agent) OnApproval(ctx context.Context, approvalToken string, status ApprovalStatus) error

OnApproval completes a tool approval when using RunStream. Pass the string from ev.Approval (see the streaming examples) along with the chosen status.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, input string, conversationID string) (*AgentResponse, error)

Run starts the agent workflow and returns the result. Use WithApprovalHandler when tools require approval (Run only; handler uses req.Respond). RunStream uses AgentEventApproval + OnApproval. Use WithTimeout or a context with deadline to avoid blocking. When using WithConversation, pass the conversation ID (runtime id from user/session); agent and worker use the same ID.

func (*Agent) RunAsync

func (a *Agent) RunAsync(ctx context.Context, input string, conversationID string) (resultCh <-chan RunAsyncResult, approvalCh <-chan *ApprovalRequest, err error)

RunAsync starts the run in a goroutine and returns two channels:

  • resultCh: receives exactly one RunAsyncResult, then closes.
  • approvalCh: receives each pending tool approval; call req.Respond. Channel closes when the run ends.

For each approval, call req.Respond(Approved|Rejected) exactly once.

WithApprovalHandler is temporarily replaced for the duration of the run; restore happens when the run finishes. If tools do not require approval, approvalCh is still closed immediately with no values.

func (*Agent) RunStream

func (a *Agent) RunStream(ctx context.Context, input string, conversationID string) (chan *AgentEvent, error)

RunStream 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 stays open until the root workflow run finishes on Temporal (there is often more work after the event, e.g. post-sub-agent activities), then closes. For approvals (tool or delegation), receive AgentEventApproval and call OnApproval as in the streaming examples. When using WithConversation, pass the conversation ID.

type AgentEvent

type AgentEvent struct {
	Type       AgentEventType         `json:"type"`
	AgentName  string                 `json:"agent_name,omitempty"`
	Content    string                 `json:"content,omitempty"`
	ToolCall   *ToolCallEvent         `json:"tool_call,omitempty"`
	Approval   *ApprovalEvent         `json:"approval,omitempty"` // for AgentEventApproval
	Error      error                  `json:"error,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	Timestamp  time.Time              `json:"timestamp"`
	WorkflowID string                 `json:"workflow_id,omitempty"` // run workflow ID; for correlation only
}

AgentEvent is published to subscribers when the agent produces output or errors. AgentName identifies which agent in a delegation tree emitted the event (main or sub-agent). RunStream uses it so AgentEventComplete from a sub-agent does not close the root stream. For AgentEventApproval, the requesting agent is also on AgentName (not duplicated on Approval).

type AgentEventType

type AgentEventType string

AgentEventType is the type of agent events

const (
	AgentEventContent       AgentEventType = "content"
	AgentEventContentDelta  AgentEventType = "content_delta" // partial token stream
	AgentEventThinking      AgentEventType = "thinking"
	AgentEventThinkingDelta AgentEventType = "thinking_delta" // Anthropic extended thinking stream
	AgentEventToolCall      AgentEventType = "tool_call"
	AgentEventToolResult    AgentEventType = "tool_result"
	AgentEventApproval      AgentEventType = "approval"
	AgentEventError         AgentEventType = "error"
	AgentEventComplete      AgentEventType = "complete"
)

type AgentEventUpdate

type AgentEventUpdate struct {
	AgentName        string      `json:"agent_name"`
	LocalChannelName string      `json:"local_channel_name,omitempty"`
	Event            *AgentEvent `json:"event"`
}

AgentEventUpdate is the payload for agent-event updates when using one event workflow per agent. AgentName is the name of the agent that emitted the event (main agent or a sub-agent). LocalChannelName is the in-process pub/sub channel name (agent_event_<main-workflow-id>) all nodes in the delegation tree publish to.

type AgentLLMInput

type AgentLLMInput struct {
	ConversationID string               `json:"conversation_id,omitempty"`
	Messages       []interfaces.Message `json:"messages,omitempty"`
	SkipTools      bool                 `json:"skip_tools,omitempty"`
}

AgentLLMInput is the input to AgentLLMActivity. When ConversationID is set, activity fetches messages from store. UserPrompt is passed directly; no message construction in workflow. Messages used only for non-conversation multi-turn.

type AgentLLMResult

type AgentLLMResult struct {
	Content   string            `json:"content"`
	ToolCalls []ToolCallRequest `json:"tool_calls"`
}

AgentLLMResult is the return value of AgentLLMActivity. Workflow uses it to decide: return content or execute tools.

type AgentLLMStreamInput

type AgentLLMStreamInput struct {
	ConversationID   string               `json:"conversation_id,omitempty"`
	Messages         []interfaces.Message `json:"messages,omitempty"`
	EventWorkflowID  string               `json:"event_workflow_id,omitempty"`
	LocalChannelName string               `json:"local_channel_name,omitempty"`
	SkipTools        bool                 `json:"skip_tools,omitempty"`
}

AgentLLMStreamInput is the input to AgentLLMStreamActivity.

type AgentResponse

type AgentResponse struct {
	Content   string         `json:"content"`
	AgentName string         `json:"agent_name"`
	Model     string         `json:"model"`
	Metadata  map[string]any `json:"metadata"`
}

AgentResponse is the return value of AgentRun.Get / AgentWorkflow.

type AgentTool

type AgentTool interface {
	interfaces.Tool
	// SubAgent returns the sub-agent this tool delegates to.
	SubAgent() *Agent
}

AgentTool marks a tool that represents sub-agent delegation (child AgentWorkflow), not normal Tool.Execute.

AgentWorkflow chooses delegation vs AgentToolExecuteActivity using SubAgentRoutes keyed by tool name, not by asserting AgentTool in workflow code. AgentTool is still used elsewhere (e.g. toolApprovalMetadata walks toolsList() and asserts AgentTool to set delegation fields on approval events).

type AgentToolApprovalInput

type AgentToolApprovalInput struct {
	ToolName         string         `json:"tool_name"`
	Args             map[string]any `json:"args"`
	ToolCallID       string         `json:"tool_call_id"`
	EventWorkflowID  string         `json:"event_workflow_id"`
	LocalChannelName string         `json:"local_channel_name,omitempty"`
}

type AgentToolExecuteInput

type AgentToolExecuteInput struct {
	ToolName       string               `json:"tool_name"`
	Args           map[string]any       `json:"args"`
	ConversationID string               `json:"conversation_id,omitempty"`
	Messages       []interfaces.Message `json:"messages,omitempty"`
	ToolCallID     string               `json:"tool_call_id,omitempty"`
}

AgentToolExecuteInput is the input to AgentToolExecuteActivity.

type AgentWorker

type AgentWorker struct {
	// contains filtered or unexported fields
}

AgentWorker runs the Temporal worker for an agent. It owns run worker creation and registration of workflows and activities from agent_workflow.go.

func NewAgentWorker

func NewAgentWorker(opts ...Option) (*AgentWorker, error)

NewAgentWorker creates an AgentWorker that polls and executes agent workflows. Same options as NewAgent. Use when the agent is created with DisableWorker().

func NewAgentWorkerDefault

func NewAgentWorkerDefault() *AgentWorker

NewAgentWorkerDefault returns an AgentWorker for workflow type identification (ExecuteWorkflow). Used by Agent when no local worker.

func (*AgentWorker) AddConversationMessagesActivity

func (aw *AgentWorker) AddConversationMessagesActivity(ctx context.Context, conversationID string, messages []interfaces.Message) error

AddConversationMessagesActivity adds messages to the conversation memory.

func (*AgentWorker) AgentLLMActivity

func (aw *AgentWorker) AgentLLMActivity(ctx context.Context, input AgentLLMInput) (*AgentLLMResult, error)

AgentLLMActivity calls the LLM and returns content plus any tool calls. When input.ConversationID is set, fetches from store and adds assistant message on completion.

func (*AgentWorker) AgentLLMStreamActivity

func (aw *AgentWorker) AgentLLMStreamActivity(ctx context.Context, input AgentLLMStreamInput) (*AgentLLMResult, error)

AgentLLMStreamActivity streams LLM response tokens and emits content_delta/thinking_delta events. When input.ConversationID is set, fetches messages from conversation and prepends to workflow messages.

func (*AgentWorker) AgentToolApprovalActivity

func (aw *AgentWorker) AgentToolApprovalActivity(ctx context.Context, input AgentToolApprovalInput) (ApprovalStatus, error)

AgentToolApprovalActivity blocks until the driver completes it via CompleteActivity. Sends approval request as AgentEventApproval on event channel (same channel for Run and RunStream).

func (*AgentWorker) AgentToolExecuteActivity

func (aw *AgentWorker) AgentToolExecuteActivity(ctx context.Context, input AgentToolExecuteInput) (string, error)

AgentToolExecuteActivity executes a tool by name and adds tool message to conversation when ConversationID is set.

func (*AgentWorker) AgentWorkflow

func (aw *AgentWorker) AgentWorkflow(ctx workflow.Context, input AgentWorkflowInput) (*AgentResponse, error)

AgentWorkflow runs the agent loop: LLM → tool calls → approval/execute → feed results back to LLM → repeat. Stops when LLM returns no tool calls, or max iterations reached. When Input.EventWorkflowID is set, sends agent events and approval requests to the event workflow.

func (*AgentWorker) Close

func (aw *AgentWorker) Close()

Close stops the worker and closes the Temporal client. Call when AgentWorker is the top-level object (standalone process). Does not close the client when it was provided via WithTemporalClient (caller owns the lifecycle).

func (*AgentWorker) SendAgentEventUpdateActivity

func (aw *AgentWorker) SendAgentEventUpdateActivity(ctx context.Context, eventWorkflowID string, upd *AgentEventUpdate) error

SendAgentEventUpdateActivity sends event: via event workflow when eventWorkflowID is set; else in-memory agentChannel.

func (*AgentWorker) Start

func (aw *AgentWorker) Start() error

Start starts the worker (blocks until Stop is called).

type AgentWorkflowInput

type AgentWorkflowInput struct {
	UserPrompt       string                   `json:"user_prompt,omitempty"`
	EventWorkflowID  string                   `json:"event_workflow_id,omitempty"`
	LocalChannelName string                   `json:"local_channel_name,omitempty"`
	StreamingEnabled bool                     `json:"streaming_enabled,omitempty"`
	ConversationID   string                   `json:"conversation_id,omitempty"`
	EventTypes       []AgentEventType         `json:"event_types,omitempty"`
	SubAgentDepth    int                      `json:"sub_agent_depth,omitempty"`
	SubAgentRoutes   map[string]SubAgentRoute `json:"sub_agent_routes,omitempty"`
}

AgentWorkflowInput is the input to AgentWorkflow. EventWorkflowID is set when streaming or approval is used. StreamingEnabled enables partial content streaming (from WithStream). ConversationID is set when conversation is used; workflow fetches messages and writes assistant/tool via activities. SubAgentDepth is 0 for a top-level user run; each child workflow increments it (runtime cap vs maxSubAgentDepth). SubAgentRoutes maps sub-agent tool name -> route; built from WithSubAgents when the run starts. LocalChannelName is the in-process pub/sub channel name used for in-memory event fan-in across the delegation tree. Set once at the top level (agent_event_<main-workflow-id>) and propagated unchanged to all sub-agents. Contrast with EventWorkflowID which is used for out-of-process (remote) routing. EventTypes is set by the SDK; a single "*" element means emit all event kinds (used for RunStream).

type ApprovalEvent

type ApprovalEvent struct {
	ToolCallID    string         `json:"tool_call_id,omitempty"`
	ToolName      string         `json:"tool_name"`
	Args          map[string]any `json:"args,omitempty"`
	ApprovalToken string         `json:"approval_token,omitempty"`
	// Kind is tool vs sub-agent delegation; use for UI copy.
	Kind ToolApprovalKind `json:"kind,omitempty"`
	// DelegateToName is set when Kind is delegation: display name of the target sub-agent.
	DelegateToName string `json:"delegate_to_name,omitempty"`
}

ApprovalEvent is the payload for AgentEventApproval (RunStream). The agent that requested approval is on AgentEvent.AgentName, not repeated here. Use with Agent.OnApproval when the user approves or rejects; see streaming examples.

type ApprovalHandler

type ApprovalHandler func(ctx context.Context, req *ApprovalRequest)

ApprovalHandler is called when a tool needs approval (Run with WithApprovalHandler). req.Respond is always set: call req.Respond(ApprovalStatusApproved) or Rejected when ready. The handler may return immediately after starting async work. Multiple invocations may run concurrently when tools are invoked in parallel.

type ApprovalRequest

type ApprovalRequest struct {
	ToolName string         `json:"tool_name"`
	Args     map[string]any `json:"args"`
	Respond  ApprovalSender `json:"-"`
	// Kind matches ApprovalEvent: distinguish normal tools from sub-agent delegation.
	Kind ToolApprovalKind `json:"kind,omitempty"`
	// AgentName is the agent running the workflow that requested approval.
	AgentName string `json:"agent_name,omitempty"`
	// DelegateToName is set for delegation: human-friendly target specialist name.
	DelegateToName string `json:"delegate_to_name,omitempty"`
}

ApprovalRequest describes a pending tool approval for Run and RunAsync. Respond is always set; call it once with ApprovalStatusApproved or ApprovalStatusRejected. For RunStream approvals, use OnApproval with the approval event payload instead.

type ApprovalSender

type ApprovalSender func(status ApprovalStatus) error

ApprovalSender sends an approval result. Call once per request. Safe for concurrent use— multiple approvals may be pending when tools run in parallel.

type ApprovalStatus

type ApprovalStatus string
const (
	ApprovalStatusNone     ApprovalStatus = "NONE"
	ApprovalStatusPending  ApprovalStatus = "PENDING"
	ApprovalStatusApproved ApprovalStatus = "APPROVED"
	ApprovalStatusRejected ApprovalStatus = "REJECTED"
)

type LLMSampling

type LLMSampling struct {
	Temperature *float64 // 0-2 OpenAI, 0-1 Anthropic
	MaxTokens   int      // 0 = provider default
	TopP        *float64 // 0-1; OpenAI only
	TopK        *int     // Anthropic only
}

LLMSampling holds per-agent LLM sampling overrides. nil/0 = provider default. One LLM client can serve multiple agents with different sampling.

type Option

type Option func(*agentConfig)

Option configures an agent. See agentConfig for which options apply to Agent vs AgentWorker.

func DisableWorker

func DisableWorker() Option

DisableWorker marks to skip local worker creation. Agent only. Use with NewAgentWorker.

func WithApprovalHandler

func WithApprovalHandler(fn ApprovalHandler) Option

WithApprovalHandler sets the approval callback for Run. Required when tools need approval. The callback receives req with req.Respond set; call req.Respond(Approved|Rejected). Agent only; RunStream uses OnApproval on events.

func WithApprovalTimeout

func WithApprovalTimeout(d time.Duration) Option

WithApprovalTimeout sets max wait per tool approval. Must be less than agent timeout. Agent only. When tools require approval, used for the approval activity; defaults to timeout-30s if unset. Capped at maxApprovalTimeout (31 days). Validation at build: approvalTimeout < timeout.

func WithConversation

func WithConversation(conv interfaces.Conversation) Option

WithConversation sets the conversation for message history. Applies to Agent and AgentWorker. The user creates the conversation (inmem or redis) and passes it to the agent. System messages are not stored; agent SystemPrompt is used for LLM calls.

Choose implementation based on deployment:

  • Single process: use inmem.NewInMemoryConversation
  • Remote workers: use redis.NewRedisConversation (in-memory cannot be used across processes)

The user owns the conversation lifecycle. Call Clear on the conversation when appropriate (e.g., when ending a session). The agent never calls Clear. Note: Agent and worker must use the same conversation and ID when using remote workers.

func WithConversationSize

func WithConversationSize(size int) Option

WithConversationSize sets the max messages to fetch for LLM context (default 20).

func WithDescription

func WithDescription(desc string) Option

WithDescription sets the agent description. Applies to Agent and AgentWorker.

func WithEnableRemoteWorkers

func WithEnableRemoteWorkers(enable bool) Option

WithEnableRemoteWorkers enables the event worker and event workflow. Agent only. Default false. When false (default): no event worker/workflow; approvals and events use agentChannel directly. When true: run event worker and event workflow; required when using NewAgentWorker (DisableWorker).

func WithInstanceId

func WithInstanceId(id string) Option

WithInstanceId sets the instance identifier. Applies to Agent and AgentWorker.

func WithLLMClient

func WithLLMClient(client interfaces.LLMClient) Option

WithLLMClient sets the LLM client. Applies to Agent and AgentWorker.

func WithLLMSampling

func WithLLMSampling(s *LLMSampling) Option

WithLLMSampling sets per-agent LLM sampling overrides. Applies to Agent and AgentWorker. When not set, LLM clients use their provider defaults. nil fields / 0 = provider default.

func WithLogLevel

func WithLogLevel(level string) Option

WithLogLevel sets the log level. Applies to Agent and AgentWorker.

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger sets the logger. Applies to Agent and AgentWorker.

func WithMaxIterations

func WithMaxIterations(n int) Option

WithMaxIterations sets the max number of LLM rounds. Applies to Agent and AgentWorker.

func WithMaxSubAgentDepth

func WithMaxSubAgentDepth(depth int) Option

WithMaxSubAgentDepth sets the maximum sub-agent nesting depth from this agent (direct children = 1). Default is 2 when unset or <= 0. Applies to Agent and AgentWorker.

func WithName

func WithName(name string) Option

WithName sets the agent name. Applies to Agent and AgentWorker.

func WithResponseFormat

func WithResponseFormat(rf *interfaces.ResponseFormat) Option

WithResponseFormat sets the LLM response format (e.g. JSON with schema). Applies to Agent and AgentWorker. When not set, the agent uses text-only output (no response_format override).

func WithStream

func WithStream(enable bool) Option

WithStream enables partial content streaming. Applies to Agent and AgentWorker.

func WithSubAgents

func WithSubAgents(subAgents ...*Agent) Option

WithSubAgents registers sub-agents. Each is exposed to the parent LLM as a tool (AgentTool). Execution is via workflow (child workflow), not Tool.Execute — see future workflow integration. The sub-agent graph is validated at agent build: no cycles, depth <= WithMaxSubAgentDepth (default 2).

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

WithSystemPrompt sets the system prompt. Applies to Agent and AgentWorker.

func WithTaskQueue

func WithTaskQueue(queue string) Option

WithTaskQueue sets the task queue name. Required when using WithTemporalClient. Ignored when using WithTemporalConfig (TaskQueue comes from TemporalConfig).

func WithTemporalClient

func WithTemporalClient(tc client.Client) Option

WithTemporalClient sets a pre-configured Temporal client. Use when you need TLS, API key auth, Temporal Cloud, or other connection options not supported by TemporalConfig. Requires WithTaskQueue. Use either WithTemporalConfig or WithTemporalClient, not both. The agent does not close the client when Close() is called; the caller owns the lifecycle.

func WithTemporalConfig

func WithTemporalConfig(cfg *TemporalConfig) Option

WithTemporalConfig sets the Temporal config. Applies to Agent and AgentWorker. Use either WithTemporalConfig or WithTemporalClient, not both.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets a maximum wait for Run and RunStream. Agent only. Ignored by AgentWorker.

func WithToolApprovalPolicy

func WithToolApprovalPolicy(policy interfaces.AgentToolApprovalPolicy) Option

WithToolApprovalPolicy sets when tools can run without approval. Applies to Agent and AgentWorker.

func WithToolRegistry

func WithToolRegistry(reg interfaces.ToolRegistry) Option

WithToolRegistry sets a tool registry. Applies to Agent and AgentWorker.

func WithTools

func WithTools(tools ...interfaces.Tool) Option

WithTools registers tools with the agent. Applies to Agent and AgentWorker.

type RequireAllToolApprovalPolicy

type RequireAllToolApprovalPolicy struct{}

RequireAllToolApprovalPolicy requires approval for every tool. Default when no policy is set.

func (RequireAllToolApprovalPolicy) RequiresApproval

type RunAsyncResult

type RunAsyncResult struct {
	Response *AgentResponse
	Err      error
}

RunAsyncResult is the single outcome from RunAsync. After the channel closes, Err is non-nil on failure; otherwise Response is non-nil.

type SubAgentRoute

type SubAgentRoute struct {
	TaskQueue   string                   `json:"task_queue"`
	ChildRoutes map[string]SubAgentRoute `json:"child_routes,omitempty"`
}

SubAgentRoute tells the workflow how to delegate to a sub-agent: child AgentWorkflow on TaskQueue, with nested routes for that sub-agent's own sub-agents (frozen at parent run start).

type TemporalConfig

type TemporalConfig struct {
	Host      string
	Port      int
	Namespace string
	TaskQueue string // Required. Full task queue name. Unique per agent.
}

TemporalConfig holds Temporal connection settings (Host, Port, Namespace) and the task queue name.

TaskQueue is required and must be unique per agent. Use different TaskQueues when running multiple agents in the same process (e.g. "my-agent-math", "my-agent-creative"). For multiple instances of the same agent (e.g. scaled pods), use WithInstanceId() so each instance gets a unique queue derived as {TaskQueue}-{InstanceId}.

When using DisableWorker, the agent and NewAgentWorker must use the same TaskQueue (and same InstanceId if set) so they pair correctly.

type ToolApprovalKind

type ToolApprovalKind string

ToolApprovalKind classifies what the user is approving (same event type for RunStream).

const (
	// ToolApprovalKindTool is a normal tool execution (default when Kind is empty for older payloads).
	ToolApprovalKindTool ToolApprovalKind = "tool"
	// ToolApprovalKindDelegation is approval to run a registered sub-agent (delegate).
	ToolApprovalKindDelegation ToolApprovalKind = "delegation"
)

type ToolCallEvent

type ToolCallEvent struct {
	ToolCallID string         `json:"tool_call_id,omitempty"`
	ToolName   string         `json:"tool_name"`
	Args       map[string]any `json:"args,omitempty"`
	Result     any            `json:"result,omitempty"`
	Status     ToolCallStatus `json:"status"`
}

type ToolCallRequest

type ToolCallRequest struct {
	ToolCallID    string         `json:"tool_call_id"` // from LLM; used to match tool results
	ToolName      string         `json:"tool_name"`
	Args          map[string]any `json:"args"`
	NeedsApproval bool           `json:"needs_approval"`
}

ToolCallRequest is a tool invocation with approval flag. NeedsApproval is set by AgentLLMActivity.

type ToolCallStatus

type ToolCallStatus string
const (
	ToolCallStatusPending   ToolCallStatus = "pending"
	ToolCallStatusRunning   ToolCallStatus = "running"
	ToolCallStatusCompleted ToolCallStatus = "completed"
	ToolCallStatusFailed    ToolCallStatus = "failed"
)

Jump to

Keyboard shortcuts

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