a2a-java icon indicating copy to clipboard operation
a2a-java copied to clipboard

agentEmitter.requiresInput(a2aMessage) does not trigger a TaskStatusUpdateEvent

Open mescaja opened this issue 3 months ago • 7 comments

I have come across an issue when setting the A2A Agent task to TaskState.TASK_STATE_INPUT_REQUIRED

These are the steps to reproduce with latest 1.2.0.Final version

Step 1: A2A client agent sends a a2aMessage1 with null contextId and null taskId Step 2: A2A Server agent

agentEmitter.submit();
agentEmitter.startWork();
agentEmitter.updateStatus(TaskState.TASK_STATE_WORKING, null);

//Do some stuff, call APIs and MCPs endpoint to run tools feeding back the result
.....

//Send a message
agentEmitter.sendMessage(a2aMessage2);

//Do some more stuff, workout logic to see if the task status needs changing
....

// Change task status
agentEmitter.requiresInput(a2aMessage3);

//Do some more stuff, send an artifact and workout logic to see if the task needs to be completed
....
agentEmitter.addArtifact(List.of(textPart));
agentEmitter.complete(a2aMessage4);

Step 3: A2A Client agent

  • Received MessageEvent and a2aMessage2 successfully returned using messageEvent.getMessage()
  • taskStatusUpdateEvent was not received for the task status update to TaskState.TASK_STATE_INPUT_REQUIRED hence a2aMessage3 got lost.
  • Received TaskArtifactUpdateEvent along with the TextPart using taskArtifactUpdateEvent.artifact().parts()
  • Received taskStatusUpdateEvent and a2aMessage4 successfully returned using taskStatusUpdateEvent.status().message()

I tried setting a task status update using the code below. The outcome was the same

agentEmitter.updateStatus(TaskState.TASK_STATE_INPUT_REQUIRED, a2aMessage3);

i need to be able to send a few messages and for the A2A client to be able to stream the corresponing MessageEvent and also to be able to set the task status to TASK_STATE_INPUT_REQUIRED and stream the associated message with it afterwards.

For some reason setting a task to INPUT_REQUIRED does not trigger the TaskStatusUpdateEvent on the client side.

I think the combination of agentEmitter.sendMessage follow by an agentEmitter.requiresInput is what causes this issue.

mescaja avatar Aug 10 '26 12:08 mescaja

by the way, i was also able to reproduce the issue on 1.1.0.Final so i don't think this issue has anything to do with the latest version. I believe if it's a bug, it's been there in the product for while.

mescaja avatar Aug 10 '26 12:08 mescaja

I reproduced this on current main (bbee3369) with the task stream sequence WORKING Task -> Message -> INPUT_REQUIRED -> COMPLETED. I ran the focused Java 17 regression three times; every run received only the first two events (expected: <4> but was: <2>), because EventConsumer closes the stream after every Message. I am testing a minimal change that keeps standalone/stateless messages terminal while allowing messages emitted after a task has started to remain intermediate stream events.

dangzitou avatar Aug 12 '26 18:08 dangzitou

@dangzitou amazing. Thanks for fixing it

Your fixes will help me put the finishing touches on some of the human in loop scenarios I’ve working on

mescaja avatar Aug 12 '26 19:08 mescaja

@mescaja FYI the PR got closed. See the comments in the PR. I'm not sure if the PR addressed your exact use case. Maybe what we need is the AgentEmitter to throw an error if the AgentExecutor tries to emit a Message when it is working on a Task, since Message/Task are mutually exclusive

kabir avatar Aug 18 '26 12:08 kabir

Thanks @kabir for the update.

"since Message/Task are mutually exclusive", does it mean the code below is not supported?

Message a2aMessage = A2A.toAgentTextMessage("Task status changed");
Message a2aMessage2 = A2A.toAgentTextMessage("Task still being worked on");
Message a2aMessage3 = A2A.toAgentTextMessage("Task needs some input");
Message a2aMessage4 = A2A.toAgentTextMessage("Task completed");
agentEmitter.submit(a2aMessage);
agentEmitter.startWork(a2aMessage);
agentEmitter.sendMessage(a2aMessage2);
agentEmitter.requiresInput(a2aMessage3);
agentEmitter.complete(a2aMessage4);

am i right in thinking that in your view, the SDK should throw the error on agentEmitter.sendMessage(a2aMessage2);?

i'm not quite understand you last comment. Now to sure how the SDK is designed to work in the above scenario?

mescaja avatar Aug 18 '26 13:08 mescaja

@mescaja The spec says here

In the Agent2Agent (A2A) Protocol, interactions can range from simple, stateless exchanges to complex, long-running processes. When an agent receives a message from a client, it can respond in one of two fundamental ways:

  • Respond with a Stateless Message: This type of response is typically used for immediate, self-contained interactions that conclude without requiring further state management.
  • Initiate a Stateful Task: If the response is a Task, the agent will process it through a defined lifecycle, communicating progress and requiring input as needed, until it reaches an interrupted state (e.g., input-required, auth-required) or a terminal state (e.g., completed, canceled, rejected, failed).

So it seems to me one should not emit Messages when a Task is being worked on.

kabir avatar Aug 18 '26 15:08 kabir

It’s now crystal clear based on the spec. I will close this ticket then

It’ll make things more difficult anyway but can’t do anything about it

Thanks for your support @kabir

mescaja avatar Aug 18 '26 15:08 mescaja