Detailed changes
@@ -82,7 +82,7 @@ func TestAgent_Generate_ResultContent_AllTypes(t *testing.T) {
Value string `json:"value" description:"Test value"`
}
- tool1 := NewTypedToolFunc(
+ tool1 := NewAgentTool(
"tool1",
"Test tool",
func(ctx context.Context, input TestInput, _ ToolCall) (ToolResponse, error) {
@@ -219,7 +219,7 @@ func TestAgent_Generate_ResultToolCalls(t *testing.T) {
SomethingElse string `json:"somethingElse" description:"Another test value"`
}
- tool1 := NewTypedToolFunc(
+ tool1 := NewAgentTool(
"tool1",
"Test tool 1",
func(ctx context.Context, input Tool1Input, _ ToolCall) (ToolResponse, error) {
@@ -227,7 +227,7 @@ func TestAgent_Generate_ResultToolCalls(t *testing.T) {
},
)
- tool2 := NewTypedToolFunc(
+ tool2 := NewAgentTool(
"tool2",
"Test tool 2",
func(ctx context.Context, input Tool2Input, _ ToolCall) (ToolResponse, error) {
@@ -300,7 +300,7 @@ func TestAgent_Generate_ResultToolResults(t *testing.T) {
Value string `json:"value" description:"Test value"`
}
- tool1 := NewTypedToolFunc(
+ tool1 := NewAgentTool(
"tool1",
"Test tool",
func(ctx context.Context, input TestInput, _ ToolCall) (ToolResponse, error) {
@@ -373,7 +373,7 @@ func TestAgent_Generate_MultipleSteps(t *testing.T) {
Value string `json:"value" description:"Test value"`
}
- tool1 := NewTypedToolFunc(
+ tool1 := NewAgentTool(
"tool1",
"Test tool",
func(ctx context.Context, input TestInput, _ ToolCall) (ToolResponse, error) {
@@ -20,7 +20,7 @@ func main() {
Location string `json:"location" description:"the city"`
}
- weatherTool := ai.NewTypedToolFunc(
+ weatherTool := ai.NewAgentTool(
"weather",
"Get weather information for a location",
func(ctx context.Context, input WeatherInput, _ ai.ToolCall) (ai.ToolResponse, error) {
@@ -28,7 +28,7 @@ func main() {
Message string `json:"message" description:"The message to echo back"`
}
- echoTool := ai.NewTypedToolFunc(
+ echoTool := ai.NewAgentTool(
"echo",
"Echo back the provided message",
func(ctx context.Context, input EchoInput, _ ai.ToolCall) (ai.ToolResponse, error) {
@@ -40,7 +40,7 @@ func main() {
}
// Create weather tool using the new type-safe API
- weatherTool := ai.NewTypedToolFunc(
+ weatherTool := ai.NewAgentTool(
"get_weather",
"Get the current weather for a specific location",
func(ctx context.Context, input WeatherInput, _ ai.ToolCall) (ai.ToolResponse, error) {
@@ -81,7 +81,7 @@ func main() {
)
// Create calculator tool using the new type-safe API
- calculatorTool := ai.NewTypedToolFunc(
+ calculatorTool := ai.NewAgentTool(
"calculate",
"Perform basic mathematical calculations",
func(ctx context.Context, input CalculatorInput, _ ai.ToolCall) (ai.ToolResponse, error) {
@@ -83,9 +83,9 @@ type AgentTool interface {
Run(ctx context.Context, params ToolCall) (ToolResponse, error)
}
-// NewTypedToolFunc creates a typed tool from a function with automatic schema generation.
+// NewAgentTool creates a typed tool from a function with automatic schema generation.
// This is the recommended way to create tools.
-func NewTypedToolFunc[TInput any](
+func NewAgentTool[TInput any](
name string,
description string,
fn func(ctx context.Context, input TInput, call ToolCall) (ToolResponse, error),
@@ -15,7 +15,7 @@ type CalculatorInput struct {
func TestTypedToolFuncExample(t *testing.T) {
// Create a typed tool using the function API
- tool := NewTypedToolFunc(
+ tool := NewAgentTool(
"calculator",
"Evaluates simple mathematical expressions",
func(ctx context.Context, input CalculatorInput, _ ToolCall) (ToolResponse, error) {
@@ -61,7 +61,7 @@ func TestEnumToolExample(t *testing.T) {
}
// Create a weather tool with enum support
- tool := NewTypedToolFunc(
+ tool := NewAgentTool(
"weather",
"Gets current weather for a location",
func(ctx context.Context, input WeatherInput, _ ToolCall) (ToolResponse, error) {
@@ -39,7 +39,7 @@ func NewBashTool(permissions permission.Service, workingDir string) ai.AgentTool
// Set up command blocking on the persistent shell
persistentShell := shell.GetPersistentShell(workingDir)
persistentShell.SetBlockFuncs(blockFuncs())
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
BashToolName,
bashDescription(),
func(ctx context.Context, params BashParams, call ai.ToolCall) (ai.ToolResponse, error) {
@@ -23,7 +23,7 @@ const (
)
func NewDiagnosticsTool(lsps map[string]*lsp.Client) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
DiagnosticsToolName,
`Get diagnostics for a file and/or project.
WHEN TO USE THIS TOOL:
@@ -39,7 +39,7 @@ func NewDownloadTool(permissions permission.Service, workingDir string) ai.Agent
IdleConnTimeout: 90 * time.Second,
},
}
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
DownloadToolName,
`Downloads binary data from a URL and saves it to a local file.
@@ -42,7 +42,7 @@ const (
)
func NewEditTool(lspClients map[string]*lsp.Client, permissions permission.Service, files history.Service, workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
EditToolName,
`Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the Bash tool with the 'mv' command instead. For larger file edits, use the FileWrite tool to overwrite files.
@@ -40,7 +40,7 @@ func NewFetchTool(permissions permission.Service, workingDir string) ai.AgentToo
IdleConnTimeout: 90 * time.Second,
},
}
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
FetchToolName,
`Fetches content from a URL and returns it in the specified format.
@@ -29,7 +29,7 @@ const (
)
func NewGlobTool(workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
GlobToolName,
`Fast file pattern matching tool that finds files by name and pattern, returning matching paths sorted by modification time (newest first).
@@ -93,7 +93,7 @@ const (
)
func NewGrepTool(workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
GrepToolName,
`Fast content search tool that finds files containing specific text or patterns, returning matching file paths sorted by modification time (newest first).
@@ -40,7 +40,7 @@ type LSResponseMetadata struct {
}
func NewLSTool(permissions permission.Service, workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
LSToolName,
`Directory listing tool that shows files and subdirectories in a tree structure, helping you explore and understand the project organization.
@@ -47,7 +47,7 @@ const (
)
func NewMultiEditTool(lspClients map[string]*lsp.Client, permissions permission.Service, files history.Service, workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
MultiEditToolName,
`This is a tool for making multiple edits to a single file in one operation. It is built on top of the Edit tool and allows you to perform multiple find-and-replace operations efficiently. Prefer this tool over the Edit tool when you need to make multiple edits to the same file.
@@ -38,7 +38,7 @@ func NewSourcegraphTool() ai.AgentTool {
IdleConnTimeout: 90 * time.Second,
},
}
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
SourcegraphToolName,
`Search code across public repositories using Sourcegraph's GraphQL API.
@@ -37,7 +37,7 @@ const (
)
func NewViewTool(lspClients map[string]*lsp.Client, permissions permission.Service, workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
ViewToolName,
`File viewing tool that reads and displays the contents of files with line numbers, allowing you to examine code, logs, or text data.
@@ -39,7 +39,7 @@ const (
)
func NewWriteTool(lspClients map[string]*lsp.Client, permissions permission.Service, files history.Service, workingDir string) ai.AgentTool {
- return ai.NewTypedToolFunc(
+ return ai.NewAgentTool(
WriteToolName,
`File writing tool that creates or updates files in the filesystem, allowing you to save or modify text content.