crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] Completed A2A artifact text is omitted from the next LLM prompt

Open TehilaTheStudent opened this issue 1 month ago • 4 comments

Description

When a remote A2A task completes, CrewAI extracts the reply from the task artifact into a2a_result["result"], then builds the next local LLM prompt from task.history only. With the default trust_remote_completion_status=False, that result is not returned and is not inserted into the prompt.

The follow-up prompt still says the remote response is in <PREVIOUS_A2A_CONVERSATION>. For a spec-compliant server, that block contains only the user message. The artifact text never reaches the caller LLM.

A2A spec section 3.7: "Messages SHOULD NOT be used to deliver task outputs. Results SHOULD BE returned using Artifacts associated with a Task." Clients must not rely on history containing the output. The official Python executor sample does add_artifact(...) and then marks the task completed. History is the user turn, not the result.

Steps to Reproduce

  1. Point an Agent at a remote card with A2AConfig(endpoint=card_url). Leave trust_remote_completion_status unset (false).
  2. Have the remote server complete the task the way the spec describes: one artifact whose text is the answer, and history containing only the user message.
  3. Let CrewAI run the follow-up LLM call (_handle_agent_response_and_continue -> _augment_prompt_with_a2a).
  4. Inspect that prompt.

Relevant current main code:

crewai/a2a/task_helpers.py process_task_state, completed branch: result is the joined artifact text, history is a2a_task.history only. No agent message is synthesized from the artifact.

crewai/a2a/wrapper.py _handle_task_completion: on completed, remote_notice is REMOTE_AGENT_RESPONSE_NOTICE. Unless trust_remote_completion_status is true, the function returns result_if_trusted=None, so the artifact text is dropped.

_augment_prompt_with_a2a serializes conversation_history into <PREVIOUS_A2A_CONVERSATION> and appends the notice. It never appends a2a_result["result"].

Expected behavior

The caller LLM should see the artifact text, because that is the A2A result. The prompt should not claim the reply is in the conversation history when that history has no agent message and the artifact text was left out.

Screenshots/Code snippets

Remote task, protocol shape:

{
  "status": { "state": "completed" },
  "artifacts": [
    {
      "name": "response",
      "parts": [{ "kind": "text", "text": "turn 1: echo: ping-external-peer" }]
    }
  ],
  "history": [
    {
      "role": "user",
      "parts": [{ "kind": "text", "text": "ping-external-peer" }]
    }
  ]
}

Actual follow-up user message sent to the local LLM:

{
  "role": "user",
  "content": "<PREVIOUS_A2A_CONVERSATION>\n{\n  \"role\": \"user\",\n  \"parts\": [{ \"kind\": \"text\", \"text\": \"ping-external-peer\" }]\n}\n{\n  \"role\": \"user\",\n  \"parts\": [{ \"kind\": \"text\", \"text\": \"ping-external-peer\" }],\n  \"taskId\": \"1ed2a298-de09-4c2c-b63c-bea3c00c4f74\"\n}\n</PREVIOUS_A2A_CONVERSATION>\n\n<REMOTE_AGENT_STATUS>\nSTATUS: RESPONSE_RECEIVED\nThe remote agent has responded. Their response is in the conversation history above.\n</REMOTE_AGENT_STATUS>"
}

turn 1: echo: ping-external-peer is not in that prompt. The peer model did produce it, and it was the artifact text.

Operating System

Other (specify in additional context)

Python Version

3.11

crewAI Version

main as of 2026-10-18 (crewai[a2a]>=1.15). Same process_task_state / REMOTE_AGENT_RESPONSE_NOTICE path as current main.

crewAI Tools Version

n/a

Virtual Environment

Venv

Evidence

Observed with a non-streaming JSON-RPC server that publishes one artifact via TaskUpdater.add_artifact and then complete(). The caller recorded STATUS: RESPONSE_RECEIVED and /chat returned the scripted final answer, while the next chat-completions request contained only the two user-role history messages above.

extract_task_result_parts does read artifact text into result. The loss is later: _handle_task_completion does not pass result into the prompt unless trust_remote_completion_status is true, and _augment_prompt_with_a2a only dumps history.

Possible Solution

On TaskState.completed, include a2a_result["result"] (the artifact text) in the follow-up prompt. Do not tell the model the reply is in <PREVIOUS_A2A_CONVERSATION> when that list has no agent message.

Additional context

Reproduced while calling a same-framework CrewAI peer through an A2A gateway. The server side matches the spec and the official executor sample: the answer is an artifact, history stays the user message. macOS host, Python 3.11. This is distinct from #7473, which is about joining streamed artifact chunks with spaces. Here the artifact text is intact and then never placed in the next prompt.

TehilaTheStudent avatar Oct 18 '26 16:10 TehilaTheStudent

Hi! I'd like to work on this issue as my first contribution to CrewAI.

My plan is to add a regression test for a completed A2A task whose output is stored in an artifact but absent from the conversation history, then update the follow-up prompt construction so the caller LLM receives that output.

I'll also check the existing trust_remote_completion_status behavior to avoid regressions.

Is this approach acceptable? I'd be happy to submit a focused PR.

Jiacheng-952 avatar Oct 18 '26 17:10 Jiacheng-952

Still open on PyPI crewai 1.15.32 (2026-10-27). #8266 is the fix and the branch is behind main, so it cannot be merged as it stands.

@Jiacheng-952 please update the branch. @lorenzejay

TehilaTheStudent avatar Oct 28 '26 05:10 TehilaTheStudent

Thanks for the reminder!

I've merged the latest upstream main into PR #8266 and pushed the updated branch.

The A2A regression tests passed locally: 117 passed, 7 skipped, 0 failed.

The PR is now synchronized with upstream. I'm also working through the outstanding security review regarding untrusted completed A2A artifacts.

Thanks again for following up!

Jiacheng-952 avatar Oct 28 '26 05:10 Jiacheng-952

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 27 '26 12:11 github-actions[bot]