tool_call_dedupTier 1 · 70% confidence

ai-agents-tool-call-dedup-tool-call-definitions-are-duplicated-in-multi-turn-ddaf8e76

agent: ai_agents

When does this happen?

IF Tool call definitions are duplicated in multi-turn conversations when using the /responses API with Bedrock, causing a ValidationException for duplicate toolUseId.

How others solved it

THEN In the transformation logic for the /responses endpoint, before reattaching cached tool-call definitions, check whether the incoming request already contains a matching assistant tool-call block (same role and tool_call_id). If present, skip the cache reattachment to avoid duplication.

def _attach_cached_tool_calls(parsed_payload, tool_calls_cache):
    new_payload = parsed_payload.copy()
    # Identify existing tool call IDs from the input messages
    existing_ids = set()
    for msg in new_payload.get('messages', []):
        if msg.get('role') == 'assistant':
            for block in msg.get('content', []):
                if 'toolUse' in block:
                    existing_ids.add(block['toolUse']['toolUseId'])
    # Only append from cache if ID not already present
    for tc in tool_calls_cache:
        if tc['id'] not in existing_ids:
            new_payload['messages'].append({'role': 'assistant', 'content': [{'toolUse': tc}]})
    return new_payload

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics