Skip to content

Commit 17ab201

Browse files
author
Anubhav200311
committed
deduplicate fix
1 parent c805d09 commit 17ab201

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/agent/agent.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)