fix: anthropic parallel tool call results.
Merged
IO
2y ago+71+71+01234567890123456789-49-49-01234567890123456789
I've found that when receiving parallel tool results, Anthropic API requires the results to be grouped within the content field of a single message. If the client returns them as several role='user', content=[<TOOL_RESULT>] messages, Anthropic API will end up return an error like this:
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': "messages.2: the following `tool_use` ids were not found in `tool_result` blocks: {'toolu_01MtMyrsycEunT8wDfk2vpAi', 'toolu_01SzMGM1XsqzqYi9gNDWkV9P'}"}}
This is similar to https://github.com/pydantic/pydantic-ai/issues/562 , but is specific to Anthropic as far I can tell.
This PR groups multiple tool results within a single ModelRequest into one message which addresses the issue for me.
Closes #741