-
Notifications
You must be signed in to change notification settings - Fork 354
Fix/deduplicate tool names #2278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,22 @@ func (a *Agent) collectTools(ctx context.Context) ([]tools.Tool, error) { | |
|
|
||
| agentTools = append(agentTools, a.tools...) | ||
|
|
||
| // Deduplicate tools by name, keeping the first occurrence. | ||
| // Duplicate tool names cause provider API errors (e.g. Anthropic 400). | ||
| seen := make(map[string]struct{}, len(agentTools)) | ||
| deduped := make([]tools.Tool, 0, len(agentTools)) | ||
| for _, t := range agentTools { | ||
| if _, exists := seen[t.Name]; exists { | ||
| slog.Warn("Duplicate tool name; keeping first occurrence", | ||
|
Anubhav200311 marked this conversation as resolved.
|
||
| "agent", a.Name(), "tool", t.Name) | ||
| a.addToolWarning(fmt.Sprintf("duplicate tool %q: keeping first occurrence", t.Name)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MEDIUM/LIKELY] New
If two goroutines call Impact: In practice the risk is low because agent methods are typically not called concurrently from different goroutines, and this is a pre-existing structural gap rather than a new one. However, the new dedup code is the first time duplicate-tool warnings can be generated during normal (non-error) operation, making this path more likely to be exercised. Suggestion: Guard |
||
| continue | ||
| } | ||
| seen[t.Name] = struct{}{} | ||
| deduped = append(deduped, t) | ||
| } | ||
| agentTools = deduped | ||
|
|
||
| if a.addDescriptionParameter { | ||
| agentTools = tools.AddDescriptionParameter(agentTools) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.