tool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package tool defines the Tool interface and its variants (SchemaTool, FuncTool) that agents expose to models. Concrete implementations live in the subpackages functool (Go functions), agenttool (an agent as a tool), hostedtool, mcptool, and shelltool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApprovalRequiredTool

type ApprovalRequiredTool interface {
	Tool

	// ApprovalRequired reports whether the tool requires user approval before invocation.
	ApprovalRequired() bool
}

ApprovalRequiredTool indicates whether a tool requires user approval before invocation.

type FuncTool

type FuncTool interface {
	SchemaTool

	// Call invokes the tool with raw JSON arguments.
	Call(ctx context.Context, args string) (any, error)
}

FuncTool describes a schema-aware tool that can be invoked by an agent.

func ApprovalRequiredFunc

func ApprovalRequiredFunc(t FuncTool) FuncTool

ApprovalRequiredFunc wraps a tool to indicate that it requires user approval before invocation. If the tool already requires approval, it is returned as-is. Not all tools support approval, in which case the original tool is returned.

type SchemaTool

type SchemaTool interface {
	Tool

	// Schema returns the tool input schema.
	Schema() any

	// ReturnSchema returns the tool output schema.
	ReturnSchema() any
}

SchemaTool describes a tool that exposes input and output schemas.

type Tool

type Tool interface {
	// Name returns the provider-facing tool name.
	Name() string

	// Description returns the provider-facing tool description.
	Description() string
}

Tool describes a tool that can be made available to an agent.

type ToolMode

type ToolMode string

ToolMode represents how tools should be used by the agent.

const (
	// ToolModeAuto allows the agent to decide when to use tools.
	ToolModeAuto ToolMode = "auto"

	// ToolModeRequired forces the agent to use at least one tool.
	ToolModeRequired ToolMode = "required"

	// ToolModeNone disables tool usage.
	ToolModeNone ToolMode = "none"
)

func RequireTool

func RequireTool(name string) ToolMode

RequireTool returns a ToolMode that requires the named tool to be used.

func (ToolMode) Mode

func (m ToolMode) Mode() ToolMode

Mode returns the base tool mode represented by m. Modes created by RequireTool return ToolModeRequired.

func (ToolMode) RequiredTool

func (m ToolMode) RequiredTool() (string, bool)

RequiredTool returns the specific tool name required by m. It returns false unless m was created by RequireTool.

Directories

Path Synopsis
Package agenttool adapts an agent.Agent into a tool.FuncTool via New, so one agent can be invoked as a tool by another.
Package agenttool adapts an agent.Agent into a tool.FuncTool via New, so one agent can be invoked as a tool by another.
Package functool turns a typed Go function into a tool.FuncTool via New and MustNew, deriving the tool's input and output JSON schemas from the function's parameter and return types.
Package functool turns a typed Go function into a tool.FuncTool via New and MustNew, deriving the tool's input and output JSON schemas from the function's parameter and return types.
Package hostedtool provides definitions for hosted tools.
Package hostedtool provides definitions for hosted tools.
Package mcptool provides integration with the Model Context Protocol (MCP).
Package mcptool provides integration with the Model Context Protocol (MCP).
Package shelltool provides a shell command execution tool that can be registered with an agent.
Package shelltool provides a shell command execution tool that can be registered with an agent.

Jump to

Keyboard shortcuts

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