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 ¶
- func OptionalParam[T any](call ToolCall, name string, defaultValue T) (T, map[string]any)
- func Param[T any](call ToolCall, trace interface{ ... }, name string) (T, map[string]any)
- type Definition
- type EmptyTools
- type FindingTools
- type Parameter
- type Tool
- type ToolCall
- type ToolProvider
- type WorktreeTools
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OptionalParam ¶
OptionalParam extracts an optional parameter from the tool call args.
Types ¶
type Definition ¶
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 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. |