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

how A2A java SDK support Manager/Supervisor agentic pattern

Open mescaja opened this issue 3 months ago • 17 comments

i would like if someone could confirm how A2A java SDK support the tasks lifecycle in an Manager/Supervisor agentic pattern scenario

The manager or supervisor agentic pattern uses a central coordinator agent to direct a team of specialized worker agents. The central boss breaks down a big job, hands tasks to specific helpers, checks their work, and puts all the pieces together into one final

So in a Manager/Supervisor agentic pattern, there are 2 main actors:

  • 1 Manager agent
  • multiple Worker agents

Although in theory we could plunge all artifacts in one single task, i can't see a way to manage the status of each of the worker agent and where to persist them.

In this scenario, i could manage that outside the SDK and use redis and/or database schema to persist task status however, that would not be a sound approach in my view. I would much rather use the SDK task management capabilities to handle task lifecycle for worker agents

With that in mind, looking at the SDK methods available i raised all the task like this

@Override
 public void execute(RequestContext context, AgentEmitter agentEmitter) throws A2AError {
.....
     //Create the parent task for the Manager agent
     agentEmitter.submit();
     agentEmitter.startWork();
     Log.info("Manager agent task id: " + agentEmitter.getTaskId());

            //Raise a new task for the worker agent
            Task task = agentEmitter.taskBuilder()
                .contextId(agentEmitter.getContextId())
                .status(new TaskStatus(TaskState.TASK_STATE_WORKING))
                .metadata(Map.of("agentId", subAgent.id))
                .metadata(Map.of("subAgentId", subAgent.subAgentId))
                .build();
            //Attach the new task to the context
            context.attachRelatedTask(task);
            Log.info("Worker agent task id: " + task.id());

            //Change Task Status to INPUT_REQUIRED on the worker agent task
            Message message = agentEmitter.messageBuilder()
                .contextId(task.contextId())
                .taskId(task.id())
                .parts(new TextPart("Worker Agent needs your input."))
                .build();
            agentEmitter.updateStatus(TaskState.TASK_STATE_INPUT_REQUIRED,message);
...
}

I made sure that both tasks are attached to the same contex and set with the same contextId

My question is: will the agentEmitter.updateStatus()

  • emit an event to update the Manager agent task? or
  • emit an event to update the Work agent task?

in other words, is it always true that Task updates will be carried out on the message.taskId() when it's not null falling back updating the task matching agentEmitter.getTaskId() id otherwise?

mescaja avatar Aug 14 '26 10:08 mescaja

Tried emitting an event for the new task attached to the context representing the worker agent

//Raise a new task for the SubAgent
            Task task = agentEmitter.taskBuilder()
                .id(UUID.randomUUID().toString())
                .contextId(agentEmitter.getContextId())
                .status(new TaskStatus(TaskState.TASK_STATE_SUBMITTED))
                .metadata(Map.of("agentId", subAgent.agentId))
                .metadata(Map.of("subAgentId", subAgent.subAgentId))
                .build();
            context.attachRelatedTask(task);
            Log.info("SubAgent contextId: " + task.contextId());
            Log.info("SubAgent taskId: " + task.id());

            //Emit an event
            TaskStatusUpdateEvent event = TaskStatusUpdateEvent.builder()
                .contextId(task.contextId())
                .taskId(task.id())
                .status(new TaskStatus(TaskState.TASK_STATE_WORKING))
                .metadata(Map.of("agentId", subAgent.agentId))
                .metadata(Map.of("subAgentId", subAgent.subAgentId))
                .build();
            agentEmitter.emitEvent(event);

it throws this error

2026-08-15 06:07:49,663 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-3) TurnOne: context: Context id : f07d1cf1-d68b-46d2-b936-3faed5d8e469
2026-08-15 06:07:49,663 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-3) TurnOne: context: Task id : 6931e386-73ee-4a3b-bf03-0a6f4c84da40
2026-08-15 06:07:49,663 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-3) TurnOne: agentEmitter: Context id : f07d1cf1-d68b-46d2-b936-3faed5d8e469
2026-08-15 06:07:49,664 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-3) TurnOne: agentEmitter: Task id : 6931e386-73ee-4a3b-bf03-0a6f4c84da40
.......
2026-08-15 06:07:49,752 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-3) SubAgent contextId: f07d1cf1-d68b-46d2-b936-3faed5d8e469
2026-08-15 06:07:49,752 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-3) SubAgent taskId: 23739c5f-154c-4a96-9697-e880931eebcf
.......
2026-08-15 06:07:49,752 ERROR [org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler] (executor-thread-3) Agent execution threw unexpected RuntimeException for task 6931e386-73ee-4a3b-bf03-0a6f4c84da40: java.lang.IllegalArgumentException: Event taskId mismatch: queue=6931e386-73ee-4a3b-bf03-0a6f4c84da40, event=23739c5f-154c-4a96-9697-e880931eebcf, eventType=TaskStatusUpdateEvent
	at org.a2aproject.sdk.server.events.EventQueue$MainQueue.validateEventIds(EventQueue.java:576)
	at org.a2aproject.sdk.server.events.EventQueue$MainQueue.enqueueItem(EventQueue.java:511)
	at org.a2aproject.sdk.server.events.EventQueue.enqueueEvent(EventQueue.java:221)
	at org.a2aproject.sdk.server.events.EventQueue$ChildQueue.enqueueEvent(EventQueue.java:779)
	at org.a2aproject.sdk.server.tasks.AgentEmitter.emitEvent(AgentEmitter.java:579)
	at org.acme.task.service.ManagerTurnOne.runTurnOne(ManagerTurnOne.java:72)
	at org.acme.task.service.ManagerTurnOne_ClientProxy.runTurnOne(Unknown Source)
	at org.acme.task.service.GatewayTurnOne.runTurnOne(GatewayTurnOne.java:26)
	at org.acme.task.service.GatewayTurnOne_ClientProxy.runTurnOne(Unknown Source)
	at org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor.execute(AgentExecutorProducer.java:115)
	at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler$2.run(DefaultRequestHandler.java:1047)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1825)
	at io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:695)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
	at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1622)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1589)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1474)

2026-08-15 06:07:49,755 ERROR [org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler] (a2a-event-consumer-2) onError for task 6931e386-73ee-4a3b-bf03-0a6f4c84da40: org.a2aproject.sdk.spec.InternalError: Agent execution failed: Event taskId mismatch: queue=6931e386-73ee-4a3b-bf03-0a6f4c84da40, event=23739c5f-154c-4a96-9697-e880931eebcf, eventType=TaskStatusUpdateEvent
	at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler$2.run(DefaultRequestHandler.java:1058)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1825)
	at io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:695)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
	at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1622)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1589)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1474)

mescaja avatar Aug 15 '26 06:08 mescaja

commented out

//Emit an event
            //TaskStatusUpdateEvent event = TaskStatusUpdateEvent.builder()
            //    .contextId(task.contextId())
            //    .taskId(task.id())
            //    .status(new TaskStatus(TaskState.TASK_STATE_WORKING))
            //    .metadata(Map.of("agentId", subAgent.agentId))
            //    .metadata(Map.of("subAgentId", subAgent.subAgentId))
            //    .build();
            //agentEmitter.emitEvent(event);

tried sending a message

Message message = agentEmitter.messageBuilder()
                .contextId(task.contextId())
                .taskId(task.id())
                .parts(new TextPart(deepChatHelper.convertDeepChatMessagesToString(List.of(answer))))
                .metadata(Map.of("agentId", subAgent.agentId))
                .metadata(Map.of("subAgentId", subAgent.subAgentId))
                .build();
            agentEmitter.sendMessage(message);

it throws this error

2026-08-15 06:26:40,964 ERROR [org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler] (executor-thread-2) Agent execution threw unexpected RuntimeException for task c4cc1899-80e6-41c1-9d5f-d03c696c0951: java.lang.IllegalArgumentException: Message taskId does not match the emitter's taskId
	at org.a2aproject.sdk.server.tasks.AgentEmitter.sendMessage(AgentEmitter.java:515)
	at org.acme.task.service.ManagerTurnOne.runTurnOne(ManagerTurnOne.java:83)
	at org.acme.task.service.ManagerTurnOne_ClientProxy.runTurnOne(Unknown Source)
	at org.acme.task.service.GatewayTurnOne.runTurnOne(GatewayTurnOne.java:26)
	at org.acme.task.service.GatewayTurnOne_ClientProxy.runTurnOne(Unknown Source)
	at org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor.execute(AgentExecutorProducer.java:115)
	at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler$2.run(DefaultRequestHandler.java:1047)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1825)
	at io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:695)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1586)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1474)

2026-08-15 06:26:40,967 ERROR [org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler] (a2a-event-consumer-1) onError for task c4cc1899-80e6-41c1-9d5f-d03c696c0951: org.a2aproject.sdk.spec.InternalError: Agent execution failed: Message taskId does not match the emitter's taskId
	at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler$2.run(DefaultRequestHandler.java:1058)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1825)
	at io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:695)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1586)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1474)

mescaja avatar Aug 15 '26 06:08 mescaja

Commented out this line .id(UUID.randomUUID().toString()) hoping the SDK will generate a new task Id

//Raise a new task for the SubAgent
            Task task = agentEmitter.taskBuilder()
                //.id(UUID.randomUUID().toString())
                .contextId(agentEmitter.getContextId())
                .status(new TaskStatus(TaskState.TASK_STATE_WORKING))
                .metadata(Map.of("agentId", subAgent.agentId))
                .metadata(Map.of("subAgentId", subAgent.subAgentId))
                .build();
            context.attachRelatedTask(task);
            Log.info("SubAgent contextId: " + task.contextId());
            Log.info("SubAgent taskId: " + task.id());

            //Get the attached tasks
            List<Task> tasks = context.getRelatedTasks();
            Log.info("nuber of tasks attached: " + tasks.size());
            for (Task t : tasks) {
                Log.info("Attached taskId: " + t.id());
            }

it outputs

2026-08-15 06:59:59,369 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-2) TurnOne: context: Context id : 0081ad49-76a8-45ff-8c5b-bfe6b9bb9d0a
2026-08-15 06:59:59,369 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-2) TurnOne: context: Task id : aad2f543-c1f3-4acd-87f1-55952300e7b2
2026-08-15 06:59:59,369 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-2) TurnOne: agentEmitter: Context id : 0081ad49-76a8-45ff-8c5b-bfe6b9bb9d0a
2026-08-15 06:59:59,369 INFO  [org.acme.a2a.AgentExecutorProducer$WanakuAgentExecutor] (executor-thread-2) TurnOne: agentEmitter: Task id : aad2f543-c1f3-4acd-87f1-55952300e7b2
....
2026-08-15 06:59:59,446 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-2) SubAgent contextId: 0081ad49-76a8-45ff-8c5b-bfe6b9bb9d0a
2026-08-15 06:59:59,446 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-2) SubAgent taskId: aad2f543-c1f3-4acd-87f1-55952300e7b2
2026-08-15 06:59:59,446 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-2) nuber of tasks attached: 1
2026-08-15 06:59:59,447 INFO  [org.acme.task.service.ManagerTurnOne] (executor-thread-2) Attached taskId: aad2f543-c1f3-4acd-87f1-55952300e7b2

There's only one task attached to the context (expected 2). This leads me to a dead end. I can't seem to be able to get the SDK raise a new task with a different Id. Tried both ways, me generating a new task id using UUID.randomUUID() and also letting the SDK to generate a new one. None of those approaches worked.

mescaja avatar Aug 15 '26 06:08 mescaja

it's not ideal but I'm afraid I can't see any alternative but persisting the worker agent progress status outside the SDK

  • Redis for short lived workflows
  • Database table for long running workflow that can span potentially hours or days.

Maybe my approach is not correct and there are other ways to attach extra tasks to the context but based on my findings, this could be an blocking issue stopping the adoption of the SDK for scenarios outside of a simple ReacAct pattern with 1 agent 1 task.

For more complex scenarios involving more than just one agent, i think this issue is a blockage.

mescaja avatar Aug 15 '26 12:08 mescaja

@mescaja Right, I think what you are seeing is to avoid emitting to tasks you don't own, and to avoid creating new tasks accidentally. But maybe that needs a rethink.

Maybe we need some new methods on the AgentEmitter? Something like

  • AgentEmitter newChildEmitter() - which creates a new child emitter
  • AgentEmitter getChildEmitter(String taskId) - reuses an existing emitter

The returned emitter would then be able to send to other tasks 'owned' by the current one, and could possibly populate a new suitable RequestContext.

However, we need to think carefully about this to make sure we get it right. This was just the first option that popped into my mind.

Another thing you could try, could be to inject DefaultRequestHandler into your AgentExecutor, and make the call from there to manage the other Task. This should show up as a brand new request. But I've never tried this so YMMV ;-)

kabir avatar Aug 18 '26 13:08 kabir

thanks @kabir

if each agentEmitter is tied up to just one task and can't submit new tasks then i think the 2 new methods that you proposed would be one way to solve the issue.

the other option you mentioned, inject DefaultRequestHandler, i am not too sure about it, even if it does work for turn one, i think the manager agent will not be able to pull back all tasks and their status on turn two and provide a snapshot on progress back to the client agent. All child tasks created needs to be attached to the pair contextId, taskId.

i guess you need some time to think about all viable options and put together a design for it that is sound.

mescaja avatar Aug 18 '26 14:08 mescaja

Hi @mescaja I looked a bit more into the Manager/Supervisor pattern, and the gist of it seems to be that the Manager delegates tasks to specialized agents.

With what you are outlining, you're just calling yourself again - it will end up in the same AgentExecutor (ie no specialization).

What you need to do is call remote agents based on what is needed. We have an example in our tests.

Here is the AgentExecutor part calling another agent using the Client API. The 'sub-task' lives on the other agent: https://github.com/a2aproject/a2a-java/blob/main/tests/server-common/src/test/java/org/a2aproject/sdk/server/apps/common/AgentExecutorProducer.java#L196-L257

And here is the test, testing this: https://github.com/a2aproject/a2a-java/blob/main/tests/server-common/src/test/java/org/a2aproject/sdk/server/apps/common/AbstractA2AServerTest.java#L3024-L3063

Creating sub-tasks within the same executor seems a different issue (if it is needed). So I'll close this one for now.

Feel free to reopen if you feel I got something wrong :-)

kabir avatar Aug 19 '26 14:08 kabir

thanks @kabir

"With what you are outlining, you're just calling yourself again". not quite, the AI platform i am building defined A2A agents (handling orchestration, do not run any tools) and Local Agents (running the langChain/LangGraph stuff and tools and producing artifacts). The scenario i was testing was one of an A2A Server agent calling multiple local agents which would produce the artifacts that the A2A agents would attach to the task.

What i was hoping to be able to achieve is to have a separate A2A task for each of the calls to Local Agents . Clearly after your last comments, it seems the SDK does not support it.

I started to understand the limitations of the SDK.

What its started to become apparent to me is that A2A is great as a protocol that allows agents to talk to agents even when they are built with different programming languages and frameworks. The A2A orchestration capabilities as described in the spec are the grey area for me and too restricted in my view.

i can see two options:

  • put a separate A2A server agent on top of each local agent call just to be able to raise child task, an overhead that i can't quite understand. This approach will make scaling more challenging
  • keep just one task for the supervisor agent and use a different orchestration tools (Bamoe would be a good fit) to handle child tasks.

I decided to implement the option 2 with Redis and/or Database for now and looking to move it to Bamoe soon till i see the benefit of going for option 1.

Anyway, it was very interesting going though these stuff. you came out of it understanding the whole picture of what the piece of software can and can't do.

mescaja avatar Aug 19 '26 14:08 mescaja

@mescaja A2A is a communication protocol, why would you want to call your local agent via A2A ? I guess you could use the internal API to do that, bypassing the transport part except for the callback which I'm not sure we expose. LangChain4j agentic API allows you to do this for example. But maybe I'm not understanding properly what you want to achieve.

ehsavoie avatar Aug 19 '26 16:08 ehsavoie

"A2A is a communication protocol, why would you want to call your local agent via A2A ?" @ehsavoie yes agreed but also i need to handle task statuses in complex scenarios where the flow gets interrupted.

if the prompt is, for instance, book me a flight and a hotel in Bali, that's 2 tasks on the same contextid which most likely will set to status INPUT_REQUIRED requiring the second turn to provide more info for the local agent to be able to run the tools "book-hotel" and "book-fight"

when you run the second turn, how would you know the context have 2 tasks in INPUT_REQUIRED status unless in the turn one you attached them to the contextid?

and that's the issue, when on the turn one, the A2A server agent tries to call 2 local agent (the hotel and flight one) that's where i struggle, i can't create those 2 tasks unless I put an A2A agent on top of each local agent which is an overhead i don't think it's worth.

what i'll do is, in turn one, call Bamoe to create a simple workflow with a user task that will be completed on turn two.

I tried the Qurkus Agentic framework too, it has a few limitations, to start with the @A2AClientAgent annotation does not support Bear token propagation. I did raise a ticket a while ago, not sure what the status of it is cause i moved on taking different approach.

But again LangChain, Agentic framework, LangGraph etc, these are extensions used to develop local agent, in my view, you'd still have to wrap them in a A2A server agent otherwise it'll be hard for others to consume and call them.

it's quite interesting see others people angles to the same problem. I hope i was able to articulate mine clearly.

mescaja avatar Aug 19 '26 16:08 mescaja

but at the end of the day, the truth of the matter is that i was not able to figure out how to create child tasks from the same agent executor class and from @kabir comments i don't think it's possible.

Maybe you have other ways to do this....

mescaja avatar Aug 19 '26 16:08 mescaja

Well I would say you should have tried langchain4j-cdi then ;) There was an issue for opentelemetry propagation as well so this might be fixeable in the same way. I'm not super sure about your contextId problem: you have an agent A or some code that calls either sequentially or in parallel your 2 other agents and process the result. That's something we were used to do with JMS form example., I'm not sure were the AI part in that is different (apart from the non-deterministic part).

ehsavoie avatar Aug 19 '26 17:08 ehsavoie

@ehsavoie , I am annotating classes with @RegisterAIService and injecting the AI Services in my WebSocket resource for instance. So using it already, but that has nothing to do with the A2A task status issue i was trying to solve.

you have an agent A or some code that calls either sequentially or in parallel your 2 other agents and process the result. yes that correct

turn 1 user prompt >> Agent A (A2A Server Agent) >> run LLM to break the prompt into chunks >> iterate through each chuck and call local Agent >> Local Agent run tools return either the artifact or a prompt asking for additional information turn 2 user feedback about the INPUT REQUIRED tasks >> Agent A (A2A Server Agent) >> Call Local Agent

in the above scenario, it's purely non-deterministic, the outcome is either, i have a tool therefore it gets run and artifact will follow and sent back to the caller or a generic message "sorry we do not have the tools to answer your prompt".

i am not quite sure about the JMS form example, is there any link for it?

mescaja avatar Aug 19 '26 17:08 mescaja

Yes https://github.com/ehsavoie/langchain4j-cdi-lab-2026/tree/volcamp2026 in exercise 5/6 (the workshop is in French). It is not as sophisticated as what you are trying to do but it could (in theory). I can help along the way if you encounter issues or requires some fixes / features.

Sorry by JMS I was thinking of the old way of multitasking back in the JavaEE days.

ehsavoie avatar Aug 19 '26 17:08 ehsavoie

Thanks for the lab project. Let me take a look at the code

mescaja avatar Aug 19 '26 17:08 mescaja

Hello @ehsavoie . I just looked at the code and picked up on a couple of pieces

Observation 1. I believe that RegisterA2AAgent still does not support sending Bearer token in the Authrorization header. Even it it does, i have to abe able to send the DPoP header as well when the token is a sender constrained one rather than Bearer. Also because the flow is interrupted i need to be able to send the contextId and taskId as part of the request in Turn Two so not sure RegisterA2AAgent allows it.

@RegisterA2AAgent(
        name = "style-scorer",
        a2aServerUrl = "${a2a.style-scorer.url}",
        outputKey = "score",
        description = "Score a saga based on how well it captures a given style")

i tried a similar way using the A2AClientAgent annotation

@A2AClientAgent(a2aServerUrl = "http://localhost:11001", outputKey = "aiMessage", description = "Binance Crypto Market Analizer")

I had to open 2 tickets to address the contextId/taskId issue and the Authorization header issue. Both tickets are closed but i never had the change to run a proper test

https://github.com/langchain4j/langchain4j/issues/5311 https://github.com/langchain4j/langchain4j/issues/5310

Observation 2:

@RegisterSequenceAgent(
        subAgentNames = {"creative-writer", "style-review-loop"},

i moved away from using Parallel, Sequential, Loop etc agent annotation. Reason being is that i managed to build an AI harness that looks into the database for SubAgent, in other words, the supervisor agent is not hard wired to the SubAgent in the code rather it fetches the SubAgents from a database table so at runtime the supervisor looks up in the table and delegate to each of the subagent that it finds in the database under him. This way i don't need to build new images and deploy it when changes on the delegation/supervisor logic happens.

the only one i use from the Langchain4j Agentic framework is the dev.langchain4j.agentic.declarative.ParallelMapperAgent; which i found it really useful for managing inference on very complex prompt that need to be distilled and broken down into smaller prompts.

mescaja avatar Aug 20 '26 16:08 mescaja

e to reopen if you feel I got something wro

Hi @mescaja I looked a bit more into the Manager/Supervisor pattern, and the gist of it seems to be that the Manager delegates tasks to specialized agents.

With what you are outlining, you're just calling yourself again - it will end up in the same AgentExecutor (ie no specialization).

What you need to do is call remote agents based on what is needed. We have an example in our tests.

Here is the AgentExecutor part calling another agent using the Client API. The 'sub-task' lives on the other agent: https://github.com/a2aproject/a2a-java/blob/main/tests/server-common/src/test/java/org/a2aproject/sdk/server/apps/common/AgentExecutorProducer.java#L196-L257

And here is the test, testing this: https://github.com/a2aproject/a2a-java/blob/main/tests/server-common/src/test/java/org/a2aproject/sdk/server/apps/common/AbstractA2AServerTest.java#L3024-L3063

Creating sub-tasks within the same executor seems a different issue (if it is needed). So I'll close this one for now.

Feel free to reopen if you feel I got something wrong :-)

revisited this issue again and reviewed carefully your sample apps you mentioned. Each server agent might potentially need to delegate/hand-off to other specialized agents so server agents will most likely be hybrid ones, built-in with client agent so they can execute agent-to-agent operations. Implemented 2 scenarios: first a manager with 2 subagents and and the second a handoff agent that delegate to a subagent (best suited agent for the job based on a semantic router outcome) the agentEmitter.submit() will create a new task for each subagent. the client agent inside the manager/handoff agents will stream events sent by the subagents agentEmitter. The overall flow would be like this user client app (chatbot connected to Quarkus webSocket resource) >> A2A client >> A2A server (manager) + A2A client >> A2A server (subagent) the challenge that i faced was the fact that the A2A client that first initiate the call to the A2A server (manager) does not subscribe by default to artifacts and messages from any of the subagents. Events like TaskArtifactUpdateEvent emiited by subagent are then sent back to client using a websocket client. i also implemented AG-UI, sending ag-ui events with a2a artifact as payload to kafka and streaming them using Quarkus Mutiny (SSE). Thanks @kabir for the headups and pointed me in the right direction.

mescaja avatar Oct 05 '26 20:10 mescaja