tool

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tool provides high-level utilities for common AI workflows. It simplifies single-shot "tool call" patterns where a consistent action is applied to varying inputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SystemPrompt defines the tool's behavior and role.
	// This is cached automatically when the tool is reused.
	SystemPrompt string

	// MaxTokens is the maximum number of tokens to generate.
	// Defaults to 4096 if not specified.
	MaxTokens int

	// Temperature controls randomness (0.0 = deterministic, 1.0 = creative).
	// Defaults to 0.7 if not specified.
	Temperature float64

	// CacheTTL is the cache time-to-live for the system prompt.
	// Valid values: "5m" (5 minutes) or "1h" (1 hour).
	// Defaults to "5m" if not specified.
	CacheTTL string
}

Config holds configuration for a Tool instance. All fields are optional and will use sensible defaults if not specified.

type Tool

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

Tool represents a reusable AI tool with consistent behavior. Create a Tool instance with New(), then call Run() multiple times with different inputs. The system prompt is cached for efficiency.

func New

func New(client ai.Client, config Config) *Tool

New creates a new Tool instance with the given configuration. The configuration is applied once and reused for all subsequent Run() calls.

func (*Tool) Run

func (t *Tool) Run(ctx context.Context, input string) (string, error)

Run executes the tool on the given input string. The input is wrapped in XML document tags to provide clear semantic separation from the system prompt. This is especially important for inputs that might contain confusing content (like conversation logs with user/assistant markers).

The system prompt is cached automatically for efficiency when the tool is reused multiple times.

func (*Tool) RunWithResponse

func (t *Tool) RunWithResponse(ctx context.Context, input string) (*ai.CompletionResponse, error)

RunWithResponse executes the tool and returns the full completion response. This includes token usage information for cost tracking.

Jump to

Keyboard shortcuts

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