feat!: Use AgentEmitter instead of EventQueue in AgentExecutor methods#621
feat!: Use AgentEmitter instead of EventQueue in AgentExecutor methods#621kabir wants to merge 1 commit 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.
| // strategy.getCallCount() should be 3: testEvent, final Task, then QueueClosedEvent (poison pill) | ||
| assertEquals(3, strategy.getCallCount(), "Should have replicated testEvent, final Task, and QueueClosedEvent"); |
There was a problem hiding this comment.
The comment on line 527 is slightly misleading. It states that a 'final Task' is replicated, but the implementation in ReplicatedQueueManager.onTaskFinalized actually sends a TaskStatusUpdateEvent to maintain consistency with local event distribution. The assertion on line 528 is correct (it expects 3 events), but updating the comment would improve clarity for future maintainers.
| // strategy.getCallCount() should be 3: testEvent, final Task, then QueueClosedEvent (poison pill) | |
| assertEquals(3, strategy.getCallCount(), "Should have replicated testEvent, final Task, and QueueClosedEvent"); | |
| // strategy.getCallCount() should be 3: testEvent, final TaskStatusUpdateEvent, then QueueClosedEvent (poison pill) | |
| assertEquals(3, strategy.getCallCount(), "Should have replicated testEvent, final TaskStatusUpdateEvent, and QueueClosedEvent"); |
c35e5e3 to
065787e
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.
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.
| agentEmitter.fail(new UnsupportedOperationError()); | ||
| } |
There was a problem hiding this comment.
After failing the task with agentEmitter.fail(), the execution continues and attempts to send another message or task event. This is likely not the intended behavior. You should probably add a return; statement after agentEmitter.fail() to terminate the execution for this case.
agentEmitter.fail(new UnsupportedOperationError());
return;
}
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.
Fixes #604 🦕