tool

package
v0.260801.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

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 GetAdvisorRecordSink

func GetAdvisorRecordSink(ctx context.Context) (any, bool)

GetAdvisorRecordSink retrieves the record sink from the 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.

func WithAdvisorRecordSink

func WithAdvisorRecordSink(ctx context.Context, sink any) context.Context

WithAdvisorRecordSink attaches a record sink to the context for advisor call recording.

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

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"`
}

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.

type ToolResult

type ToolResult struct {
	Contents []ToolContent
	IsError  bool
}

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

func (r *VirtualToolRegistry) Register(tool VirtualTool)

Jump to

Keyboard shortcuts

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