feat!: Use AgentEmitter instead of EventQueue in AgentExecutor methods#621
feat!: Use AgentEmitter instead of EventQueue in AgentExecutor methods#621kabir wants to merge 5 commits intoa2aproject:mainfrom
Conversation
Summary of ChangesHello @kabir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the internal event processing and agent communication mechanisms to improve robustness, consistency, and developer experience. By introducing a dedicated Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is an excellent and significant refactoring that greatly improves the architecture and robustness of the A2A Java SDK. The introduction of the AgentEmitter provides a much cleaner and simpler API for agent developers, abstracting away the complexities of the EventQueue. The new MainEventBus architecture with its "persistence first" approach is a major step forward for data consistency and reliability, especially in replicated environments. The improvements to thread pool management, client disconnect handling, and replication logic are all critical for stability and performance. The test suite has also been made more robust and reliable. The minor suggestion regarding a comment in a test file has been retained as it does not contradict any established rules.
...ore/src/test/java/io/a2a/extras/queuemanager/replicated/core/ReplicatedQueueManagerTest.java
Show resolved
Hide resolved
065787e to
8bb5d93
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and beneficial refactoring by replacing the TaskUpdater with a new AgentEmitter class. This change provides a cleaner and more powerful API for agent developers, encapsulating task lifecycle management and message sending in a single place. The new AgentEmitter is well-documented and includes helpful builders for creating tasks and messages.
Key improvements include:
- A unified
AgentEmitterAPI for all agent-to-client communication. - Simplification of agent implementations, as seen in the updated examples and tests.
- Introduction of
taskIdvalidation in theEventQueuefor improved robustness.
The changes have been applied consistently throughout the codebase. I have one minor suggestion in a test file to improve the logic after a task is failed. Overall, this is an excellent pull request that improves the SDK's design and usability.
tests/server-common/src/test/java/io/a2a/server/apps/common/AgentExecutorProducer.java
Outdated
Show resolved
Hide resolved
8bb5d93 to
4b2052d
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and valuable refactoring by replacing TaskUpdater and direct EventQueue access with the new AgentEmitter class. This greatly simplifies the API for agent developers, providing a clear and concise way to manage task lifecycles and send events. The changes are applied consistently across the entire codebase, including documentation, examples, and tests. The addition of task ID validation in the event queue is also a great improvement for correctness.
I have a couple of suggestions for the new AgentEmitter class to further improve its robustness and implementation.
server-common/src/main/java/io/a2a/server/tasks/AgentEmitter.java
Outdated
Show resolved
Hide resolved
0d2734c to
b3e6a9f
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This is an excellent and significant refactoring that greatly improves the agent developer experience by introducing the AgentEmitter. Hiding the EventQueue and replacing TaskUpdater makes the API much cleaner and more intuitive.
The other changes are also very valuable:
- The fix for the race condition in
DefaultRequestHandlerby registering the consumer callback before starting the agent is a critical improvement for stability. - Handling
A2AErrors by transitioning the task to aFAILEDstate makes error handling more robust and predictable. - Adding
taskIdvalidation inEventQueueis a great defensive measure against event misrouting.
I've found one potential race condition in the new AgentEmitter class itself, which could allow multiple terminal events to be enqueued. I've added comments with suggestions to address this.
Overall, this is a high-quality pull request that makes the SDK much better. Great work!
b3e6a9f to
5fecd16
Compare
BREAKING CHANGE: AgentEmitter contains the methods from the old TaskUpdater and is now the only way agents send results back to the caller. This hides the EventQueue mechanism from users. Also introduced a check that when placing a full Task object on the queue, which should only be done for calls with no existing Task, that the Task's ID is the one expected for the queue, as calculated by the RequestContext. Added Message and Task builders to AgentEmitter to help with using the proper taskID and contextId.
This removes a race condition where an agent might complete before adding the callback
5fecd16 to
12106b5
Compare
BREAKING CHANGE: AgentEmitter contains the methods from the old TaskUpdater
and is now the only way agents send results back to the caller. This hides
the EventQueue mechanism from users.
Also introduced a check that when placing a full Task object on the queue,
which should only be done for calls with no existing Task, that the
Task's ID is the one expected for the queue, as calculated by the
RequestContext.
Added Message and Task builders to AgentEmitter to help with using the
proper taskID and contextId.
Treat A2AErrors internally as a state transition to FAILED.
Register EventConsumer callback before starting agent to fix a race condition/hang when an agent completes before the callback is registered.
Fixes #604 🦕