You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AWS Bedrock ValidationException: Protocol violation when assistant message contains both tool_calls and content #1593
area/providersFor features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.)area/providers/anthropicFor features/issues/fixes related to the usage of Anthropic modelsarea/providers/bedrockAWS Bedrock provider support
Model: haiku (Claude Haiku via bedrock/anthropic.claude-3-5-haiku-20241022-v1:0)
Setup: Multi-agent coordinator with subagents using transfer_task
The Problem
When cagent delegates tasks to subagents using transfer_task, it generates an assistant message that contains BOTHtool_calls AND content in the same turn. This violates the Anthropic/AWS Bedrock API protocol specification.
Complete Error Message
error receiving from stream: POST "http://localhost:4000/chat/completions":
503 Service Unavailable {
"message": "litellm.ServiceUnavailableError: litellm.MidStreamFallbackError:
litellm.APIConnectionError: APIConnectionError: OpenAIException -
Stream generation failed: ProviderException: (400,
\"AWS client error encountered: <class 'botocore.errorfactory.ValidationException'>:
An error occurred (ValidationException) when calling the ConverseStream operation
(reached max retries: 0): The number of toolResult blocks at messages.5.content
exceeds the number of toolUse blocks of previous turn.\"
}
The Protocol Violation
Here's the malformed message structure that cagent generates (message index 5 in the conversation):
{
"role": "assistant",
"content": "Let me proceed with analyzing the issue...",
"tool_calls": [
{
"id": "tooluse_ABC123",
"type": "function",
"function": {
"name": "transfer_task",
"arguments": "{\"agent\": \"scout\", \"task\": \"Retrieve data from source A\", \"expected_output\": \"Summary of findings\"}"
}
},
{
"id": "tooluse_XYZ789",
"type": "function",
"function": {
"name": "transfer_task",
"arguments": "{\"agent\": \"coder\", \"task\": \"Analyze the implementation\", \"expected_output\": \"Technical analysis\"}"
}
}
]
}
This is WRONG! The assistant message contains:
??? 2 tool calls (to delegate to subagents)
??? Text content explaining what it's doing
What Happens Next
After this malformed message, two tool results come back:
This is a protocol-level issue, not a model-specific problem
Affects all Anthropic models via AWS Bedrock (Claude 3.x, 4.x)
OpenAI-compatible endpoints may hide this bug due to lenient validation
Issue exists in the conversation history builder, not the LLM itself
Request
Can the cagent team investigate where assistant messages are constructed for API calls, specifically around multi-agent transfer_task handling? The fix should ensure strict separation of tool calls and content responses.
Happy to provide additional debugging information if needed.
area/providersFor features/issues/fixes related to LLM providers (Bedrock, LiteLLM, Qwen, custom, etc.)area/providers/anthropicFor features/issues/fixes related to the usage of Anthropic modelsarea/providers/bedrockAWS Bedrock provider support
Activity
ThePlenkov commentedon Feb 4, 2026
Full Technical Details with Reproduction Case
Environment
haiku(Claude Haiku via bedrock/anthropic.claude-3-5-haiku-20241022-v1:0)transfer_taskThe Problem
When cagent delegates tasks to subagents using
transfer_task, it generates an assistant message that contains BOTHtool_callsANDcontentin the same turn. This violates the Anthropic/AWS Bedrock API protocol specification.Complete Error Message
The Protocol Violation
Here's the malformed message structure that cagent generates (message index 5 in the conversation):
{ "role": "assistant", "content": "Let me proceed with analyzing the issue...", "tool_calls": [ { "id": "tooluse_ABC123", "type": "function", "function": { "name": "transfer_task", "arguments": "{\"agent\": \"scout\", \"task\": \"Retrieve data from source A\", \"expected_output\": \"Summary of findings\"}" } }, { "id": "tooluse_XYZ789", "type": "function", "function": { "name": "transfer_task", "arguments": "{\"agent\": \"coder\", \"task\": \"Analyze the implementation\", \"expected_output\": \"Technical analysis\"}" } } ] }This is WRONG! The assistant message contains:
What Happens Next
After this malformed message, two tool results come back:
{ "role": "tool", "content": "Result from scout agent...", "tool_call_id": "tooluse_ABC123" }{ "role": "tool", "content": "Result from coder agent...", "tool_call_id": "tooluse_XYZ789" }But AWS Bedrock rejects this entire conversation because:
tool_callsANDcontentCorrect Protocol (What Should Happen)
Turn 1 - Assistant makes tool calls (NO content):
{ "role": "assistant", "tool_calls": [ {"id": "tooluse_ABC123", "type": "function", "function": {...}}, {"id": "tooluse_XYZ789", "type": "function", "function": {...}} ] }Note: NO "content" field at all!
Turn 2 - Tool results come back:
{"role": "tool", "content": "...", "tool_call_id": "tooluse_ABC123"} {"role": "tool", "content": "...", "tool_call_id": "tooluse_XYZ789"}Turn 3 - Assistant responds with analysis:
{ "role": "assistant", "content": "Based on the results from scout and coder agents..." }Note: NO tool_calls here
Root Cause Analysis
The system prompts in cagent include:
However, cagent is violating its own instruction by generating text content alongside
transfer_taskcalls.This suggests the issue is in:
Why This Only Affects AWS Bedrock
Minimal Reproduction
transfer_tasktool for delegationExpected vs Actual Behavior
Expected:
tool_callsORcontent, never bothActual:
tool_callsANDcontentImpact
transfer_taskusage fails immediatelySuggested Fix
The bug is likely in the code that:
transfer_taskfunction call responsesRequired change: When
tool_callsare present in an assistant message, ensure:contentfield is completely omitted (preferred)nullTemporary Workaround
Users can add LiteLLM middleware to sanitize messages:
Additional Context
Request
Can the cagent team investigate where assistant messages are constructed for API calls, specifically around multi-agent
transfer_taskhandling? The fix should ensure strict separation of tool calls and content responses.Happy to provide additional debugging information if needed.
fix(session): drop duplicate tool results in sanitizeToolCalls