tool

package
v1.261105.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MPL-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BuiltinAdvisorSourceID = "advisor"
	BuiltinAdvisorToolName = "advisor"
)

Variables

This section is empty.

Functions

func GetAdvisorDepth

func GetAdvisorDepth(ctx context.Context) int

GetAdvisorDepth retrieves the current adviser call depth from context.

func IsMCPToolName

func IsMCPToolName(name string) bool

IsMCPToolName checks whether a tool name is a normalized MCP tool. Deprecated: use IsNormalizedToolName for protocol-neutral code.

func IsNormalizedToolName

func IsNormalizedToolName(name string) bool

IsNormalizedToolName checks whether a tool name is a normalized server tool name.

func NormalizeToolName

func NormalizeToolName(sourceID, toolName string) string

NormalizeToolName converts source/tool pair to normalized tool name.

func ParseNormalizedToolName

func ParseNormalizedToolName(name string) (string, string, bool)

ParseNormalizedToolName parses normalized name and returns sourceID/toolName.

func WithAdvisorContext

func WithAdvisorContext(ctx context.Context, ac *AdvisorContext) context.Context

WithAdvisorContext attaches advisor context to the context.

func WithAdvisorDepth

func WithAdvisorDepth(ctx context.Context, depth int) context.Context

WithAdvisorDepth sets the adviser call depth in context.

Types

type AdvisorContext

type AdvisorContext struct {
	Messages      []map[string]any
	UsesRemaining *int
}

AdvisorContext holds conversation state for the advisor tool.

func GetAdvisorContext

func GetAdvisorContext(ctx context.Context) (*AdvisorContext, bool)

GetAdvisorContext retrieves advisor context from the context.

type ContentType

type ContentType string

ContentType identifies the kind of content a tool produced.

const (
	ContentTypeText         ContentType = "text"
	ContentTypeImage        ContentType = "image"
	ContentTypeBlob         ContentType = "blob"
	ContentTypeAudio        ContentType = "audio"
	ContentTypeResource     ContentType = "resource"
	ContentTypeResourceLink ContentType = "resource_link"
)

type ToolCall

type ToolCall struct {
	Name      string
	Arguments map[string]any
}

ToolCall describes an in-process tool invocation independent of any wire protocol.

type ToolContent

type ToolContent struct {
	Type ContentType `json:"type"`
	// Text is populated when Type == ContentTypeText.
	Text string `json:"text,omitempty"`
	// Data is base64-encoded binary, populated when Type == ContentTypeImage or ContentTypeBlob.
	Data string `json:"data,omitempty"`
	// MIMEType is populated when Type == ContentTypeImage or ContentTypeBlob.
	MIMEType string `json:"mimeType,omitempty"`
	// Raw preserves MCP content fields (resources, annotations, links) across bridges.
	Raw json.RawMessage `json:"-"`
}

ToolContent is a single piece of content from a tool result. It is protocol-agnostic — adapters convert it to the wire format required by each upstream model API.

func (ToolContent) MarshalJSON added in v1.261026.0

func (c ToolContent) MarshalJSON() ([]byte, error)

func (ToolContent) ModelText added in v1.261026.0

func (c ToolContent) ModelText() string

ModelText renders content for model APIs that cannot accept the original MCP block. Preserve resource/audio/link fields as JSON rather than silently emitting empty text.

func (*ToolContent) UnmarshalJSON added in v1.261026.0

func (c *ToolContent) UnmarshalJSON(data []byte) error

type ToolResult

type ToolResult struct {
	Contents          []ToolContent  `json:"content"`
	IsError           bool           `json:"isError,omitempty"`
	StructuredContent any            `json:"structuredContent,omitempty"`
	Meta              map[string]any `json:"_meta,omitempty"`
}

ToolResult is the structured return value from a servertool execution.

func ErrorToolResult

func ErrorToolResult(text string) ToolResult

ErrorToolResult constructs an error ToolResult with a single text content item.

func TextToolResult

func TextToolResult(text string) ToolResult

TextToolResult constructs a ToolResult with a single text content item.

func (ToolResult) FirstText

func (r ToolResult) FirstText() string

FirstText returns the text of the first text content item, or empty string if none.

type ToolVisibility

type ToolVisibility string

ToolVisibility controls whether a tool is exposed to clients or kept server-side.

const (
	ToolVisibilityClient ToolVisibility = "client"
	ToolVisibilityServer ToolVisibility = "server"
)

type VirtualTool

type VirtualTool struct {
	Name        string
	Description string
	InputSchema any
	Handler     VirtualToolHandler
	Visibility  ToolVisibility
}

VirtualTool is an in-process tool definition.

type VirtualToolHandler

type VirtualToolHandler func(ctx context.Context, call ToolCall) (ToolResult, error)

VirtualToolHandler executes an in-process protocol-neutral tool.

type VirtualToolRegistry

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

VirtualToolRegistry holds registered in-process tools.

func NewVirtualToolRegistry

func NewVirtualToolRegistry() *VirtualToolRegistry

func (*VirtualToolRegistry) Get

func (r *VirtualToolRegistry) Get(name string) (VirtualTool, bool)

func (*VirtualToolRegistry) ListVirtualTools

func (r *VirtualToolRegistry) ListVirtualTools() []VirtualTool

func (*VirtualToolRegistry) OwnsNormalized added in v1.261026.0

func (r *VirtualToolRegistry) OwnsNormalized(name string) bool

func (*VirtualToolRegistry) Register

func (r *VirtualToolRegistry) Register(tool VirtualTool)

func (*VirtualToolRegistry) SetOwnershipResolver added in v1.261026.0

func (r *VirtualToolRegistry) SetOwnershipResolver(owner func(string) bool)

SetOwnershipResolver lets the execution adapters recognize gateway-owned remote tools without pretending they are in-process virtual implementations.

Jump to

Keyboard shortcuts

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