File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,21 @@ func (a *Agent) collectTools(ctx context.Context) ([]tools.Tool, error) {
240240
241241 agentTools = append (agentTools , a .tools ... )
242242
243+ // Deduplicate tools by name, keeping the first occurrence.
244+ // Duplicate tool names cause provider API errors (e.g. Anthropic 400).
245+ seen := make (map [string ]struct {}, len (agentTools ))
246+ deduped := make ([]tools.Tool , 0 , len (agentTools ))
247+ for _ , t := range agentTools {
248+ if _ , exists := seen [t .Name ]; exists {
249+ slog .Warn ("Duplicate tool name; keeping first occurrence" ,
250+ "agent" , a .Name (), "tool" , t .Name )
251+ continue
252+ }
253+ seen [t .Name ] = struct {}{}
254+ deduped = append (deduped , t )
255+ }
256+ agentTools = deduped
257+
243258 if a .addDescriptionParameter {
244259 agentTools = tools .AddDescriptionParameter (agentTools )
245260 }
You can’t perform that action at this time.
0 commit comments