fix(agent): occurrence-aware tool call id sanitization#1854
Open
badgerbees wants to merge 1 commit intosipeed:mainfrom
Open
fix(agent): occurrence-aware tool call id sanitization#1854badgerbees wants to merge 1 commit intosipeed:mainfrom
badgerbees wants to merge 1 commit intosipeed:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Summary:
This PR implements occurrence-aware tool ID sanitization to resolve
400 Bad Requesterrors caused by duplicatetool_call_idvalues. This ensures that PicoClaw is fully compatible with strict LLM providers (especially Anthropic and Cerebras) that reject reused IDs, even when they appear across separate turns.Key Features & Fixes:
call_auto_N). Tool results then "pop" from the queue to match their respective rewritten IDs in the correct order.tool_call_idand its correspondingtoolresponse are distinct and unique across the entire history.Changes:
pkg/providers/toolcall_utils.go: UpdatedNormalizeToolCallto plural form with logic to ensure initial uniqueness within a single message.pkg/agent/context.go: Implemented the FIFO-based resolver insanitizeHistoryForProvider(Pass 3) for absolute history-wide uniqueness.pkg/agent/loop.go&pkg/tools/toolloop.go: Switched to the new consolidated normalization helper.🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
N/A
📚 Technical Context (Skip for Docs)
Problem Overview:
Modern LLM APIs require every tool call ID to be unique across a session. If a provider repeats an ID in different turns (or even in one message), it results in an API error. A simple static map fails here because it doesn't account for how many times an ID has appeared.
Solution Implementation:
By using an
IDMapwith slice values, we can handle multiple occurrences of the same raw ID by assigning a unique rewritten ID for each. This preserves the correct call-order pairing and makes the whole transcript "OpenAI-compatible" for strict providers.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Test Results
Test Results:
go build ./pkg/agentgo build ./pkg/tools☑️ Checklist