toolcall

package
v0.0.0-...-89b5c40 Latest Latest
Warning

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

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

Documentation

Overview

Package toolcall defines composable tool providers for AI agents.

This package provides a layered tool composition system for AI agent file and finding operations. Tools are composed using generics: Empty -> Worktree -> Finding.

Callback types (WorktreeCallbacks, FindingCallbacks, etc.) are defined in the toolcall/callbacks subpackage. This separation allows packages that only need callback types to avoid importing AI SDK dependencies.

Tool Composition

Tools are composed by wrapping callback structs in generic wrappers:

// Callbacks hold the actual implementation functions
wt := callbacks.WorktreeCallbacks{
	ReadFile: func(ctx context.Context, path string) (string, error) { ... },
	WriteFile: func(ctx context.Context, path, content string, mode os.FileMode) error { ... },
}
fc := callbacks.FindingCallbacks{
	GetDetails: func(ctx context.Context, kind callbacks.FindingKind, id string) (string, error) { ... },
	GetLogs: func(ctx context.Context, kind callbacks.FindingKind, id string) (string, error) { ... },
}

// Compose tools: Empty -> Worktree -> Finding
tools := toolcall.NewFindingTools(
	toolcall.NewWorktreeTools(toolcall.EmptyTools{}, wt),
	fc,
)

Tool Providers

Providers generate tool definitions for specific AI backends (Claude, Gemini):

provider := toolcall.NewFindingToolsProvider[*Response, toolcall.WorktreeTools[toolcall.EmptyTools]](
	toolcall.NewWorktreeToolsProvider[*Response, toolcall.EmptyTools](
		toolcall.NewEmptyToolsProvider[*Response](),
	),
)

claudeTools := provider.ClaudeTools(tools)
googleTools := provider.GoogleTools(tools)

Callback Sources

Factory functions for callbacks are provided by other packages:

  • WorktreeCallbacks: clonemanager.WorktreeCallbacks(worktree)
  • FindingCallbacks: session.FindingCallbacks()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptionalParam

func OptionalParam[T any](call ToolCall, name string, defaultValue T) (T, map[string]any)

OptionalParam extracts an optional parameter from the tool call args.

func Param

func Param[T any](call ToolCall, trace interface {
	BadToolCall(string, string, map[string]any, error)
}, name string) (T, map[string]any)

Param extracts a required parameter from the tool call args. On error, records a bad tool call on the trace and returns an error response.

Types

type Definition

type Definition struct {
	Name        string
	Description string
	Parameters  []Parameter
}

Definition describes a tool's schema (name, description, parameters).

type EmptyTools

type EmptyTools struct{}

EmptyTools is the base tools type with no callbacks. Use this as the foundation when composing tool stacks.

type FindingTools

type FindingTools[T any] struct {
	callbacks.FindingCallbacks
	// contains filtered or unexported fields
}

FindingTools wraps a base tools type and adds finding callbacks.

func NewFindingTools

func NewFindingTools[T any](base T, cb callbacks.FindingCallbacks) FindingTools[T]

NewFindingTools creates a FindingTools wrapping the given base tools.

type Parameter

type Parameter struct {
	Name        string
	Type        string // "string", "integer", "boolean", "number"
	Description string
	Required    bool
}

Parameter describes a single tool parameter.

type Tool

type Tool[Resp any] struct {
	Def     Definition
	Handler func(ctx context.Context, call ToolCall, trace *agenttrace.Trace[Resp], result *Resp) map[string]any
}

Tool defines a tool once with a single handler that works with any provider.

type ToolCall

type ToolCall struct {
	ID   string
	Name string
	Args map[string]any
}

ToolCall is a provider-independent representation of a tool call.

type ToolProvider

type ToolProvider[Resp, CB any] interface {
	// Tools returns unified tool definitions that work with any provider.
	Tools(cb CB) map[string]Tool[Resp]
}

ToolProvider defines tools for an agent. Implementations return provider-independent tool definitions. Compose providers by wrapping: Empty -> Worktree -> Finding. Conversion to SDK-specific types happens downstream in the metaagent layer.

func NewEmptyToolsProvider

func NewEmptyToolsProvider[Resp any]() ToolProvider[Resp, EmptyTools]

NewEmptyToolsProvider returns a ToolProvider that provides no tools. Use this as the base when composing tool provider stacks.

func NewFindingToolsProvider

func NewFindingToolsProvider[Resp, T any](base ToolProvider[Resp, T]) ToolProvider[Resp, FindingTools[T]]

NewFindingToolsProvider creates a provider that adds finding tools (get_finding_details, get_finding_logs) on top of the base provider's tools. The finding tools are only added if the corresponding callbacks are available.

func NewWorktreeToolsProvider

func NewWorktreeToolsProvider[Resp, T any](base ToolProvider[Resp, T]) ToolProvider[Resp, WorktreeTools[T]]

NewWorktreeToolsProvider creates a provider that adds worktree tools on top of the base provider's tools.

type WorktreeTools

type WorktreeTools[T any] struct {
	callbacks.WorktreeCallbacks
	// contains filtered or unexported fields
}

WorktreeTools wraps a base tools type and adds worktree callbacks.

func NewWorktreeTools

func NewWorktreeTools[T any](base T, cb callbacks.WorktreeCallbacks) WorktreeTools[T]

NewWorktreeTools creates a WorktreeTools wrapping the given base tools.

Directories

Path Synopsis
Package callbacks provides lightweight callback types for AI agent tool operations.
Package callbacks provides lightweight callback types for AI agent tool operations.
Package claudetool provides utilities for handling tool calls in Claude AI applications.
Package claudetool provides utilities for handling tool calls in Claude AI applications.
Package googletool provides utilities for handling function calls in Google Gemini AI applications.
Package googletool provides utilities for handling function calls in Google Gemini AI applications.
Package params provides shared parameter extraction and error formatting utilities used by both Claude and Google tool implementations.
Package params provides shared parameter extraction and error formatting utilities used by both Claude and Google tool implementations.

Jump to

Keyboard shortcuts

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