diff --git a/agent_test.go b/agent_test.go index d50c87ca723a7dbccf8ce92cff39714fffd6e450..f21781c8639697a4bd5aac4c33809885c00242a4 100644 --- a/agent_test.go +++ b/agent_test.go @@ -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) { diff --git a/examples/agent/main.go b/examples/agent/main.go index c6d563e2f192dec7888b518b0a32703366d9b739..99e8663c622d0c7795c71ef3320e88cc0ed9d28e 100644 --- a/examples/agent/main.go +++ b/examples/agent/main.go @@ -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) { diff --git a/examples/streaming-agent-simple/main.go b/examples/streaming-agent-simple/main.go index 00eb7177911bb31b93393f0b96af1d0004c286e0..6bc548e154f14ecdc66a877b9cd4ad7fbac24ff3 100644 --- a/examples/streaming-agent-simple/main.go +++ b/examples/streaming-agent-simple/main.go @@ -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) { diff --git a/examples/streaming-agent/main.go b/examples/streaming-agent/main.go index 4222277fc8afc17b06d0eb295ff18a0ce1a4fa9b..1c6295da514fc672a88f9aa27daadc5deb2b8b80 100644 --- a/examples/streaming-agent/main.go +++ b/examples/streaming-agent/main.go @@ -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) { diff --git a/tool.go b/tool.go index 1b476f699eaeae287db19766438aa966ccc9288c..c12b2775be655eeb93576ef68f509c2d6ce6d761 100644 --- a/tool.go +++ b/tool.go @@ -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), diff --git a/tool_test.go b/tool_test.go index 3413e7040fa26d55f8505ca8136a38998ee17cfb..2d11d899122596b1250b5a09ecccc4d15326cc50 100644 --- a/tool_test.go +++ b/tool_test.go @@ -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) { diff --git a/tools/bash.go b/tools/bash.go index 62f195598b94ac09847977923ba9e3a4289de29f..e3b547fdfed4fb2355d72ffa934d260ee0abbd36 100644 --- a/tools/bash.go +++ b/tools/bash.go @@ -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) { diff --git a/tools/diagnostics.go b/tools/diagnostics.go index b5601b4b508a4b542b1e29e7c2bf15ab866930fa..160e97ea5ab804b8ac461a1e7e764a84b2f155b0 100644 --- a/tools/diagnostics.go +++ b/tools/diagnostics.go @@ -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: diff --git a/tools/download.go b/tools/download.go index 612bcc550976fa0ccfd144fbf79b8b232c9e234b..710e9e5180fc499bb5d901e5adb2a7e4074dfa22 100644 --- a/tools/download.go +++ b/tools/download.go @@ -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. diff --git a/tools/edit.go b/tools/edit.go index c7dd9e8c66d060ee9c846be1b3fa4f23b7e9e91e..fc9060e85327d3c9d0775890f0822f1772898e27 100644 --- a/tools/edit.go +++ b/tools/edit.go @@ -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. diff --git a/tools/fetch.go b/tools/fetch.go index 05db05764195f29b5b6223afce01ce83cc89f2d8..4866ec222745255d162ff49eb9dfa5600536b923 100644 --- a/tools/fetch.go +++ b/tools/fetch.go @@ -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. diff --git a/tools/glob.go b/tools/glob.go index b06162157e393c5a0cb3bcfca99a50c5e35ede13..a643adbb2f7c8af1ff552b72ebd3a20695d9dc17 100644 --- a/tools/glob.go +++ b/tools/glob.go @@ -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). diff --git a/tools/grep.go b/tools/grep.go index 7fdfb10d5da3b11c1c36aa93e233ad9fb572d848..7ac412314f5eafe1638449d3a36033e9f69220d2 100644 --- a/tools/grep.go +++ b/tools/grep.go @@ -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). diff --git a/tools/ls.go b/tools/ls.go index dff3c5dac77b1bd269a2f783159ef259c00ba70d..b01f2ca5873d945fe8fe2df10399306cf7acc2fe 100644 --- a/tools/ls.go +++ b/tools/ls.go @@ -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. diff --git a/tools/multiedit.go b/tools/multiedit.go index 12b1347f93d6aa456fdfa3bba198d87ffd11681e..6630cf43317e6e2c54c31aa6b32a8e264e580b1c 100644 --- a/tools/multiedit.go +++ b/tools/multiedit.go @@ -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. diff --git a/tools/sourcegraph.go b/tools/sourcegraph.go index 5722c223ba32bede778d08fbcec856513d427c75..04f5193525d73af40d4b29352a72b398df1ba4d1 100644 --- a/tools/sourcegraph.go +++ b/tools/sourcegraph.go @@ -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. diff --git a/tools/view.go b/tools/view.go index bd20376ef95a9fa925420bd32776fc3c874bbe7e..3079073af7ac89e205206e49c4da7cd8bc70b5a4 100644 --- a/tools/view.go +++ b/tools/view.go @@ -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. diff --git a/tools/write.go b/tools/write.go index a231c364712c84ddeda24a817b1e440a9e14d243..2eec7f3ee82008bef78e6addceea3e43e8c17105 100644 --- a/tools/write.go +++ b/tools/write.go @@ -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.