types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxApprovalTimeout = 31 * 24 * time.Hour

maxApprovalTimeout caps how long a single approval wait may last in the runtime.

View Source
const SubAgentToolParamQuery = "query"

SubAgentToolParamQuery is the tool/JSON parameter name for the query sent to a sub-agent.

Variables

This section is empty.

Functions

This section is empty.

Types

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"`
	// Usage is set on AgentEventComplete for the root agent: aggregated token usage for the run.
	Usage      *interfaces.LLMUsage `json:"usage,omitempty"`
	Timestamp  time.Time            `json:"timestamp"`
	WorkflowID string               `json:"workflow_id,omitempty"` // optional run identifier for correlation (implementation-defined)
}

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). Stream 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 identifies a streamed agent event kind.

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"
)
const AgentEventAll AgentEventType = "*"

AgentEventAll is the EventTypes sentinel meaning "emit every event type" (JSON "*").

type AgentResponse

type AgentResponse struct {
	Content   string         `json:"content"`
	AgentName string         `json:"agent_name"`
	Model     string         `json:"model"`
	Metadata  map[string]any `json:"metadata"`
	// Usage is the sum of token usage across all LLM calls in this run (when reported by the provider).
	Usage *interfaces.LLMUsage `json:"usage,omitempty"`
}

AgentResponse is the structured result of a completed run (content, model, metadata).

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.
	SubAgentName string `json:"sub_agent_name,omitempty"`
}

ApprovalEvent is the payload for AgentEventApproval (Stream). 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 that requested approval for the current run.
	AgentName string `json:"agent_name,omitempty"`
	// SubAgentName is set for delegation: human-friendly target specialist name.
	SubAgentName string `json:"sub_agent_name,omitempty"`
}

ApprovalRequest describes a pending tool approval for Run and RunAsync. Respond is always set; call it once with ApprovalStatusApproved or ApprovalStatusRejected. For Stream 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"
	// ApprovalStatusUnavailable means the approval request could not be delivered (e.g. event stream down). It is not a user rejection.
	ApprovalStatusUnavailable ApprovalStatus = "UNAVAILABLE"
)

type LLMSampling

type LLMSampling struct {
	Temperature *float64 // 0-2 OpenAI, 0-1 Anthropic; also Gemini
	MaxTokens   int      // 0 = provider default
	TopP        *float64 // 0-1; OpenAI and Gemini (not Anthropic)
	TopK        *int     // Anthropic only
	// Reasoning: optional generic reasoning/thinking (see interfaces.LLMReasoning); mapped per provider.
	Reasoning *interfaces.LLMReasoning
}

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

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 {
	Name             string                   `json:"name"`
	TaskQueue        string                   `json:"task_queue"`
	ChildRoutes      map[string]SubAgentRoute `json:"child_routes,omitempty"`
	AgentFingerprint string                   `json:"agent_fingerprint,omitempty"`
}

SubAgentRoute tells the runtime how to delegate to a sub-agent (child run on TaskQueue), with nested routes for that sub-agent's sub-agents (frozen at parent run start). AgentFingerprint is the agent config digest for that sub-agent (pkg/agent + temporal.ComputeAgentFingerprint) so the child worker can reject runs when its deployed config does not match the caller.

type ToolApprovalKind

type ToolApprovalKind string

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

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 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