types

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMCPTimeout       = 30 * time.Second
	DefaultMCPRetryAttempts = 3
)

Default MCP settings applied when fields are zero.

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

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

View Source
const SubAgentToolParamQuery = "query"

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

Variables

View Source
var ErrNotApprovalCustomEvent = errors.New("types: custom event is not a recognized approval kind")

ErrNotApprovalCustomEvent means the CUSTOM event name is not tool or delegation approval.

View Source
var ErrTemporalDialTimeout = errors.New("temporal dial timeout")

ErrTemporalDialTimeout is returned when the Temporal runtime cannot establish a gRPC connection before the internal deadline (see internal/runtime/temporal newTemporalClient).

View Source
var ErrTemporalNamespaceCheckTimeout = errors.New("temporal namespace check timeout")

ErrTemporalNamespaceCheckTimeout is returned when the Temporal namespace cannot be verified in time.

Functions

This section is empty.

Types

type AgentMode added in v0.1.3

type AgentMode string

AgentMode distinguishes how the agent is driven: human-in-the-loop versus self-directed runs. The string value is stable for configuration and fingerprints (see pkg/agent.WithAgentMode).

const (
	// AgentModeInteractive is the default: the agent expects user turns, approvals, or other
	// interactive signals between steps when the product requires them.
	AgentModeInteractive AgentMode = "interactive"
	// AgentModeAutonomous indicates a run where the agent proceeds without blocking on user input
	// for each step (subject to tool policy and limits).
	AgentModeAutonomous AgentMode = "autonomous"
)

type AgentRunAsyncResult added in v0.1.6

type AgentRunAsyncResult struct {
	Result *AgentRunResult
	Error  error
}

AgentRunAsyncResult is the single outcome from AgentRunAsync. After the channel closes, Err is non-nil on failure; otherwise Result is non-nil.

type AgentRunResult added in v0.1.6

type AgentRunResult 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 *LLMUsage `json:"usage,omitempty"`
}

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

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(Approved) or Rejected when ready.

type ApprovalRequest

type ApprovalRequest struct {
	Name    ApprovalRequestName `json:"name,omitempty"`
	Value   any                 `json:"value,omitempty"`
	Respond ApprovalSender      `json:"-"`
}

ApprovalRequest is one pending approval callback. Name + Value match CUSTOM semantics; Value is a ToolApprovalRequestValue or SubAgentDelegationApprovalRequestValue. Set Respond before invoking the handler (see PrepareApprovalFromCustomEvent).

func PrepareApprovalFromCustomEvent added in v0.1.6

func PrepareApprovalFromCustomEvent(ev *events.AgentCustomEvent) (req *ApprovalRequest, approvalToken string, err error)

PrepareApprovalFromCustomEvent parses a CUSTOM event and returns Name + Value as SDK types and the approval token for Temporal CompleteActivity. Respond is nil; the caller must set it before calling ApprovalHandler. Returns ErrNotApprovalCustomEvent when ev.Name is not tool or delegation approval.

type ApprovalRequestName added in v0.1.6

type ApprovalRequestName string

ApprovalRequestName classifies the approval payload.

const (
	ApprovalRequestNameTool     ApprovalRequestName = "tool_approval"
	ApprovalRequestNameSubAgent ApprovalRequestName = "sub_agent_delegation"
)

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 JSONSchema added in v0.1.2

type JSONSchema map[string]any

func (JSONSchema) MarshalJSON added in v0.1.2

func (s JSONSchema) MarshalJSON() ([]byte, error)

type LLMReasoning added in v0.1.2

type LLMReasoning struct {
	// Enabled requests reasoning/thinking where the provider supports it.
	// Anthropic: if true and BudgetTokens is 0, uses the minimum extended-thinking budget (1024 tokens).
	// OpenAI: does not infer reasoning_effort from Enabled alone (standard models reject that param).
	// Gemini: contributes to turning on thought output with IncludeThoughts.
	Enabled bool

	// Effort is a generic reasoning intensity: "none", "minimal", "low", "medium", "high", "xhigh".
	// OpenAI: sent as reasoning_effort only when non-empty; use only with reasoning-capable models.
	// Gemini: mapped to ThinkingLevel when recognized (low/medium/high/minimal), unless BudgetTokens > 0.
	// Anthropic: not used (use Enabled and BudgetTokens for extended thinking).
	Effort string

	// BudgetTokens is the token budget for internal reasoning / extended thinking.
	// Anthropic: extended thinking; must be >= 1024 when non-zero (values below are clamped).
	// Gemini: ThinkingBudget. If non-zero, Effort is not mapped to ThinkingLevel (API allows only one).
	// OpenAI: not used.
	BudgetTokens int
}

LLMReasoning configures reasoning/thinking in a provider-agnostic way. Each LLM client maps these fields to its API; fields that do not apply are ignored.

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; mapped per provider.
	Reasoning *LLMReasoning
}

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

type LLMUsage added in v0.1.2

type LLMUsage struct {
	PromptTokens       int64 `json:"prompt_tokens,omitempty"`
	CompletionTokens   int64 `json:"completion_tokens,omitempty"`
	TotalTokens        int64 `json:"total_tokens,omitempty"`
	CachedPromptTokens int64 `json:"cached_prompt_tokens,omitempty"`
	ReasoningTokens    int64 `json:"reasoning_tokens,omitempty"`
}

LLMUsage reports token counts from the provider for one completion. Values are best-effort: some fields may be zero when the API does not return them.

type MCPLoopback added in v0.1.2

type MCPLoopback struct {
	Transport any
}

MCPLoopback is test-only wiring: it holds a pre-built protocol transport as a dynamic value. External users should use pkg/mcp transport types (MCPStdio, MCPStreamableHTTP). MCPLoopback is not re-exported from pkg/mcp.

func (MCPLoopback) Kind added in v0.1.2

func (MCPLoopback) Validate added in v0.1.2

func (lb MCPLoopback) Validate() error

Validate ensures Transport is a non-nil sdkmcp.Transport.

type MCPStdio added in v0.1.2

type MCPStdio struct {
	Command string
	Args    []string
	Env     map[string]string
}

MCPStdio runs an MCP server as a subprocess (stdio).

func (MCPStdio) Kind added in v0.1.2

func (MCPStdio) Kind() MCPTransportType

func (MCPStdio) Validate added in v0.1.2

func (s MCPStdio) Validate() error

Validate ensures Command is set.

type MCPStreamableHTTP added in v0.1.2

type MCPStreamableHTTP struct {
	URL string
	// Token is a static bearer token when OAuthClientCreds is not used for auth.
	Token string
	// OAuthClientCreds configures OAuth2 client-credentials; when any OAuth field is set, Token must be empty and id/secret/token_url are required together.
	OAuthClientCreds *clientcredentials.Config
	Headers          map[string]string
	SkipTLSVerify    bool
}

MCPStreamableHTTP uses the streamable HTTP MCP transport.

Optional static bearer Token, or OAuthClientCreds for OAuth2 client credentials. Token and active OAuth client-credentials must not both be set; omit both for URL-only access (use Headers for custom auth headers such as API keys).

func (MCPStreamableHTTP) Kind added in v0.1.2

func (MCPStreamableHTTP) Validate added in v0.1.2

func (h MCPStreamableHTTP) Validate() error

Validate checks URL, rejects mixing Token with a populated OAuth client-credentials config, and rejects incomplete OAuth when any OAuth field is set.

type MCPToolFilter added in v0.1.2

type MCPToolFilter struct {
	AllowTools []string
	BlockTools []string
}

MCPToolFilter restricts which tools from Discover are registered (exact name match). Set either AllowTools (allow-list) or BlockTools (block-list), not both. MCPToolFilter.Validate checks constraints (call from config build, e.g. github.com/agenticenv/agent-sdk-go/pkg/mcp/client.BuildConfig). MCPToolFilter.Apply filters tool specs and assumes Validate already passed for non-empty filters.

func (MCPToolFilter) Apply added in v0.1.2

func (f MCPToolFilter) Apply(specs []ToolSpec) []ToolSpec

Apply returns filtered specs when AllowTools or BlockTools is non-empty; otherwise returns specs unchanged. For any non-empty list, the receiver must already satisfy MCPToolFilter.Validate (mutually exclusive lists).

func (MCPToolFilter) Validate added in v0.1.2

func (f MCPToolFilter) Validate() error

Validate returns an error if both AllowTools and BlockTools are set.

type MCPTransportConfig added in v0.1.2

type MCPTransportConfig interface {
	// Kind returns a stable transport id ("stdio", "streamable_http") for logging and routing.
	Kind() MCPTransportType
	// Validate checks the transport is usable before connect (the default MCP client calls this from NewClient).
	Validate() error
}

MCPTransportConfig describes how to reach one MCP server. Concrete types are MCPStdio, MCPStreamableHTTP, and MCPLoopback (tests).

type MCPTransportType added in v0.1.2

type MCPTransportType string
const (
	MCPTransportTypeStdio          MCPTransportType = "stdio"
	MCPTransportTypeStreamableHTTP MCPTransportType = "streamable_http"
)
const MCPTransportTypeLoopback MCPTransportType = "loopback"

MCPTransportTypeLoopback is only for in-repo tests (see MCPLoopback). Not exposed on the public agent API.

type SubAgentDelegationApprovalRequestValue added in v0.1.6

type SubAgentDelegationApprovalRequestValue struct {
	AgentName     string         `json:"agentName,omitempty"`
	SubAgentName  string         `json:"subAgentName,omitempty"`
	Args          map[string]any `json:"args,omitempty"`
	ApprovalToken string         `json:"approvalToken,omitempty"`
}

SubAgentDelegationApprovalRequestValue is the JSON payload for sub-agent delegation approval.

func DelegationApprovalFromEventValue added in v0.1.6

DelegationApprovalFromEventValue copies the CUSTOM delegation payload into an SDK approval value.

func ParseDelegationApproval added in v0.1.6

func ParseDelegationApproval(req *ApprovalRequest) (SubAgentDelegationApprovalRequestValue, error)

ParseDelegationApproval decodes Value for ApprovalRequestNameSubAgent.

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 ToolApprovalRequestValue added in v0.1.6

type ToolApprovalRequestValue struct {
	AgentName       string         `json:"agentName,omitempty"`
	ToolCallID      string         `json:"toolCallId,omitempty"`
	ToolName        string         `json:"toolName"`
	ToolDisplayName string         `json:"toolDisplayName,omitempty"`
	Args            map[string]any `json:"args,omitempty"`
	ApprovalToken   string         `json:"approvalToken,omitempty"`
}

ToolApprovalRequestValue is the JSON payload for tool approval (same wire shape as CUSTOM approval value).

func ParseToolApproval added in v0.1.6

func ParseToolApproval(req *ApprovalRequest) (ToolApprovalRequestValue, error)

ParseToolApproval decodes Value for ApprovalRequestNameTool (handles map[string]any from JSON).

func ToolApprovalFromEventValue added in v0.1.6

func ToolApprovalFromEventValue(ev events.AgentCustomEventApprovalValue) ToolApprovalRequestValue

ToolApprovalFromEventValue copies the CUSTOM approval payload into an SDK approval value.

type ToolSpec added in v0.1.2

type ToolSpec struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Parameters  JSONSchema `json:"parameters"`
}

ToolSpec is the schema sent to the LLM for tool selection. Convert from Tool via ToolToSpec.

Jump to

Keyboard shortcuts

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