fix(agentcore): parse A2A JSON-RPC responses in AgentCore provider - #24995
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes empty responses from AgentCore when the underlying agent is an A2A (Agent-to-Agent Protocol) agent. The root cause was that A2A agents return a Fix summary:
Test coverage:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/agentcore/transformation.py | Adds Strategy 0 for A2A JSON-RPC detection in _parse_json_response(); delegates to existing extract_text_from_a2a_response() utility; falls through cleanly to existing strategies if extraction yields empty. Minor import ordering issue (new import placed mid-block between two bedrock imports rather than alphabetically before them). |
| tests/test_litellm/llms/bedrock/chat/agentcore/test_agentcore_transformation.py | Adds 4 pure-mock unit tests covering the new A2A Strategy 0: nested message, direct parts, multi-part concatenation, and empty-result fallthrough. No network calls, all assertions are correct. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[_parse_json_response called] --> B{Is dict?}
B -- No --> Z[Strategy 4: return raw JSON string]
B -- Yes --> C{jsonrpc key present? Strategy 0 NEW}
C -- Yes --> D[extract_text_from_a2a_response]
D --> E{content non-empty?}
E -- Yes --> F[Return A2A content]
E -- No --> G{result is dict? Strategy 1}
C -- No --> G
G -- Yes --> H[_extract_content_from_message - return with final_message]
G -- No --> I{response is list? Strategy 2}
I -- Yes --> J[_extract_content_from_message - return content]
I -- No --> K{result or response is string? Strategy 3}
K -- Yes --> L[Return string value]
K -- No --> Z
Reviews (1): Last reviewed commit: "fix(agentcore): parse A2A JSON-RPC respo..." | Re-trigger Greptile
| from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper | ||
| from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException | ||
| from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM | ||
| from litellm.llms.a2a.common_utils import extract_text_from_a2a_response |
There was a problem hiding this comment.
Import placed out of alphabetical order
The new a2a import is inserted between two litellm.llms.bedrock.* imports. Following the existing file's alphabetical grouping (a2a < base_llm < bedrock), it should appear before the base_llm import.
| from litellm.llms.a2a.common_utils import extract_text_from_a2a_response | |
| from litellm.llms.a2a.common_utils import extract_text_from_a2a_response | |
| from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException | |
| from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
f109dff
into
BerriAI:litellm_internal_dev_04_02_2026
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
Changes
Problem:
_parse_json_response()in the AgentCore provider returns empty content for A2A agents. Strategy 1 matches A2A responses (becauseresultis a dict), but_extract_content_from_message()looks forresult["content"]which doesn't exist in A2A format — A2A agents returnresult["message"]["parts"]instead. This meansmessage.get("content", [])returns[], producing an empty string.Fix: Added Strategy 0 before the existing strategies that detects A2A JSON-RPC responses by checking for the
"jsonrpc"key, then delegates to the existingextract_text_from_a2a_response()utility fromlitellm/llms/a2a/common_utils.py. This utility already handles 5 A2A response shapes (direct message, nested message, task with artifacts, task status, streaming artifact-update). If A2A extraction returns empty, it falls through to the existing strategies — zero regression risk.Files modified:
litellm/llms/bedrock/chat/agentcore/transformation.py— added import + Strategy 0 in_parse_json_response()tests/test_litellm/llms/bedrock/chat/agentcore/test_agentcore_transformation.py— 4 new testsTests added (all in
TestAgentCoreJsonResponseParsing):test_parse_json_a2a_jsonrpc_nested_message—result.message.parts[]format (customer's exact case)test_parse_json_a2a_jsonrpc_direct_parts—result.parts[]formattest_parse_json_a2a_jsonrpc_multi_parts— multiple text parts concatenatedtest_parse_json_a2a_jsonrpc_empty_falls_through— empty A2A result falls through to Strategy 3