Documentation
¶
Overview ¶
Package tools defines local tool registration, permission metadata, and authority-gated execution.
Registry is safe for concurrent definition reads and tool execution. Registration validates tool names, effects, permission modes, and reserved control names. Strictly safe read-only tools may omit Permission.Mode and are exposed as allowed tools. Mutating, destructive, open-world, shell, and network tools must declare explicit permission behavior. Host authorization is supplied through runtime.EffectAuthorizationGate; this package does not expose a standalone approval callback. PermissionDeny tools remain callable only as explicit host-side disabled tools and are not exposed to providers. Ordinary calls returned in one model batch execute concurrently; the model expresses dependencies by emitting dependent calls in later turns.
Index ¶
- Constants
- Variables
- func Array(items map[string]any, description string) map[string]any
- func Boolean(description string) map[string]any
- func Enum(values ...string) map[string]any
- func Integer(description string) map[string]any
- func InvalidArgumentsText(name string, err error) string
- func IsReservedName(name string) bool
- func NormalizeInputSchema(schema map[string]any) (map[string]any, error)
- func Nullable(schema map[string]any) map[string]any
- func Number(description string) map[string]any
- func PendingToolActivity(p PendingToolResult, base *observation.ActivityPresentation) *observation.ActivityPresentation
- func PendingToolResultMetadata(p PendingToolResult) map[string]any
- func PendingToolResultText(p PendingToolResult) string
- func StrictObject(properties map[string]any, required []string) map[string]any
- func String(description string) map[string]any
- func Validate(schema map[string]any, raw []byte) (map[string]any, error)
- func ValidateStructured(schema map[string]any, value any) error
- type ActivityUpdate
- type ArtifactRef
- type Definition
- type DispatchOptions
- type DispatchStart
- type Effect
- type EffectBatchPreflight
- type EffectDispatchRequest
- type EffectDispatcher
- type FullOutputPlan
- type Invocation
- type OutputPolicy
- type OutputProjection
- type OutputStrategy
- type PendingToolResult
- type PendingToolResultState
- type PermissionMode
- type PermissionRequest
- type PermissionResolver
- type PermissionSpec
- type Registry
- func (r *Registry) ActivityForCall(call ToolCall, opts DispatchOptions) (*observation.ActivityPresentation, error)
- func (r *Registry) Definition(name string) (Definition, bool)
- func (r *Registry) Definitions() []ToolDefinition
- func (r *Registry) Dispatch(ctx context.Context, call ToolCall, opts DispatchOptions) Result
- func (r *Registry) DispatchBatch(ctx context.Context, calls []ToolCall, opts DispatchOptions) []Result
- func (r *Registry) ExposedDefinitions() []ToolDefinition
- func (r *Registry) OutputPolicyFor(name string) OutputPolicy
- func (r *Registry) Register(t Tool) error
- type ResourceRef
- type Result
- type Tool
- type ToolActivityUpdate
- type ToolCall
- type ToolDefinition
Constants ¶
const ( DefaultToolVisibleMaxBytes = 64 * 1024 DefaultToolVisibleMaxLines = 0 DefaultToolOutputStrategy = OutputTail DefaultPreserveFull = true DefaultArtifactKind = "tool_output" DefaultArtifactMIME = "text/plain; charset=utf-8" )
const ( ControlAskUser = "ask_user" ControlTaskComplete = "task_complete" )
const ( AnnotationRepeatPolicy = "repeat_policy" AnnotationRepeatIdentityIgnoredArguments = "repeat_identity_ignored_arguments" RepeatPolicyPolling = "polling" ResultMetadataProgressToken = "progress_token" )
Variables ¶
var ErrDuplicate = errors.New("duplicate tool name")
var ErrEffectDispatcherRequired = errors.New("tool effect authority dispatcher is required")
var ErrInvalid = errors.New("invalid tool")
var ErrRejected = errors.New("tool call rejected")
var ErrSchema = errors.New("schema validation failed")
Functions ¶
func InvalidArgumentsText ¶
func IsReservedName ¶
func NormalizeInputSchema ¶
func PendingToolActivity ¶ added in v0.3.10
func PendingToolActivity(p PendingToolResult, base *observation.ActivityPresentation) *observation.ActivityPresentation
func PendingToolResultMetadata ¶ added in v0.3.10
func PendingToolResultMetadata(p PendingToolResult) map[string]any
func PendingToolResultText ¶ added in v0.3.10
func PendingToolResultText(p PendingToolResult) string
Types ¶
type ActivityUpdate ¶ added in v0.3.68
type ActivityUpdate struct {
Activity *observation.ActivityPresentation
Metadata map[string]any
}
type ArtifactRef ¶ added in v0.3.0
type Definition ¶
type Definition struct {
Name string
Title string
Description string
InputSchema map[string]any
OutputSchema map[string]any
Activity func(Invocation[any]) (*observation.ActivityPresentation, error)
Effects []Effect
ReadOnly bool
Destructive bool
OpenWorld bool
Permission PermissionSpec
PermissionFor PermissionResolver
OutputPolicy OutputPolicy
Annotations map[string]any
}
func ValidateDefinition ¶
func ValidateDefinition(def Definition) (Definition, error)
type DispatchOptions ¶ added in v0.18.0
type DispatchOptions struct {
RunID string
ThreadID string
TurnID string
PromptScopeID string
Step int
BatchIndex int
BatchSize int
Labels map[string]string
HostContext map[string]string
DispatchStarted func(DispatchStart)
ActivityUpdated func(ToolActivityUpdate)
EffectBatchPreflight EffectBatchPreflight
EffectDispatcher EffectDispatcher
}
type DispatchStart ¶ added in v0.3.63
type EffectBatchPreflight ¶ added in v0.20.0
type EffectBatchPreflight func(context.Context, []EffectDispatchRequest) error
type EffectDispatchRequest ¶ added in v0.18.0
type EffectDispatchRequest struct {
CallID string
Name string
RawArgs string
RunID string
ThreadID string
TurnID string
PromptScopeID string
Step int
BatchIndex int
BatchSize int
Labels map[string]string
HostContext map[string]string
Resources []ResourceRef
Effects []Effect
Permission PermissionSpec
ReadOnly bool
Destructive bool
OpenWorld bool
}
type EffectDispatcher ¶ added in v0.18.0
type EffectDispatcher func(context.Context, EffectDispatchRequest, func(context.Context) Result) Result
EffectDispatcher authorizes one prepared effect and chooses the execution context used by the tool handler. A lifecycle-owning dispatcher is responsible for bounding that selected context by its caller's execution lifetime.
type FullOutputPlan ¶ added in v0.18.0
FullOutputPlan is a side-effect-free request to admit the complete tool output together with its canonical result. It is not a durable artifact ref.
type Invocation ¶
type Invocation[T any] struct { CallID string Name string RawArgs string Args T RunID string ThreadID string TurnID string PromptScopeID string Step int Labels map[string]string HostContext map[string]string ActivityUpdater func(ActivityUpdate) }
func (Invocation[T]) UpdateActivity ¶ added in v0.3.68
func (i Invocation[T]) UpdateActivity(update ActivityUpdate)
type OutputPolicy ¶
type OutputPolicy struct {
VisibleMaxBytes int
VisibleMaxLines int
Strategy OutputStrategy
PreserveFull bool
PreserveFullSet bool
ArtifactKind string
ArtifactMIME string
}
func DefaultOutputPolicy ¶
func DefaultOutputPolicy() OutputPolicy
func MergeOutputPolicy ¶
func MergeOutputPolicy(base OutputPolicy, override *OutputPolicy) OutputPolicy
func NormalizeOutputPolicy ¶
func NormalizeOutputPolicy(policy OutputPolicy) OutputPolicy
type OutputProjection ¶
type OutputProjection struct {
VisibleText string
Truncated bool
OriginalBytes int
VisibleBytes int
OriginalLines int
VisibleLines int
Strategy OutputStrategy
ContentSHA256 string
FullOutput *ArtifactRef
FullOutputPlan *FullOutputPlan
}
func BuildOutputProjection ¶
func BuildOutputProjection(result Result, policy OutputPolicy) OutputProjection
type OutputStrategy ¶
type OutputStrategy string
const ( OutputHead OutputStrategy = "head" OutputTail OutputStrategy = "tail" )
type PendingToolResult ¶ added in v0.3.10
type PendingToolResult struct {
// Handle is the provider-visible continuation token. Hosts should put the
// exact token here that the model should reuse for later tool calls.
Handle string
State PendingToolResultState
// Summary and Instruction are provider-visible text.
Summary string
Instruction string
// Metadata is observation-only pending state. It is not rendered into the
// provider-visible pending result text.
Metadata map[string]string
}
PendingToolResult is returned by a tool handler after the host has started work whose lifecycle remains owned by the host application.
func (PendingToolResult) Validate ¶ added in v0.3.10
func (p PendingToolResult) Validate() error
type PendingToolResultState ¶ added in v0.3.10
type PendingToolResultState string
const ( // PendingToolResultRunning marks host-owned work that is still active outside Floret. PendingToolResultRunning PendingToolResultState = "running" )
type PermissionMode ¶
type PermissionMode string
const ( PermissionAllow PermissionMode = "allow" PermissionAsk PermissionMode = "ask" PermissionDeny PermissionMode = "deny" )
type PermissionRequest ¶ added in v0.3.12
type PermissionResolver ¶ added in v0.3.12
type PermissionResolver func(PermissionRequest) (PermissionSpec, error)
type PermissionSpec ¶
type PermissionSpec struct {
Mode PermissionMode
ResourceKinds []string
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistryE ¶
func (*Registry) ActivityForCall ¶ added in v0.3.7
func (r *Registry) ActivityForCall(call ToolCall, opts DispatchOptions) (*observation.ActivityPresentation, error)
func (*Registry) Definition ¶
func (r *Registry) Definition(name string) (Definition, bool)
func (*Registry) Definitions ¶
func (r *Registry) Definitions() []ToolDefinition
func (*Registry) DispatchBatch ¶ added in v0.20.0
func (*Registry) ExposedDefinitions ¶
func (r *Registry) ExposedDefinitions() []ToolDefinition
func (*Registry) OutputPolicyFor ¶
func (r *Registry) OutputPolicyFor(name string) OutputPolicy
type ResourceRef ¶
type Result ¶
type Result struct {
CallID string
Name string
Title string
Text string
Structured map[string]any
Metadata map[string]any
Activity *observation.ActivityPresentation
Artifacts []ArtifactRef
OutputPolicy *OutputPolicy
Pending *PendingToolResult
IsError bool
DispatchErr error
// contains filtered or unexported fields
}
func ErrorResult ¶
func (Result) RequiresEffectFinalization ¶ added in v0.18.0
RequiresEffectFinalization reports whether the result crossed the effect authority dispatcher and therefore requires its atomic result finalizer.
type Tool ¶
type Tool struct {
Definition Definition
// contains filtered or unexported fields
}
func Define ¶
func Define[T any]( def Definition, decode func([]byte) (T, error), resources func(Invocation[T]) ([]ResourceRef, error), handler func(context.Context, Invocation[T]) (Result, error), ) Tool