-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(agent-tool): Add event streaming propagation from AgentTool sub-agents to Runner #3991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @sarojrout, 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 introduces a significant enhancement to how AgentTool interacts with sub-agents, enabling real-time event propagation. The primary purpose is to transform the previously opaque execution of sub-agents into a transparent process, allowing users to observe the step-by-step progress of complex multi-agent tasks. This change dramatically improves the responsiveness and user experience of applications built with hierarchical agent systems by providing immediate feedback and visibility into intermediate operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature for event streaming from AgentTool sub-agents, significantly improving the user experience for hierarchical agent systems by providing real-time feedback. The implementation is well-structured, adding a new run_async_with_events method and a corresponding streaming handler while maintaining backward compatibility. The inclusion of new unit tests and a sample application is commendable. I have a couple of suggestions to improve a test case for better validation and to remove a minor code redundancy.
| if not isinstance(tool_result, dict): | ||
| tool_result = {'result': tool_result} | ||
| agent_tool_results[function_call.id] = tool_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to wrap tool_result in a dictionary is redundant here. The __build_response_event function, which is called later with this result, already handles wrapping non-dictionary results. Removing this logic will make the code cleaner and more consistent with the non-streaming tool execution path.
agent_tool_results[function_call.id] = tool_result|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature for real-time event streaming from AgentTool sub-agents, significantly improving the user experience for hierarchical agent systems. The implementation is well-structured and includes thorough testing. My review focuses on opportunities to reduce code duplication and improve readability, which will enhance the long-term maintainability of this new functionality.
| cd contributing/samples | ||
| adk web . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command to run the demo appears to be incorrect. The PR description suggests running adk web . from within the agent_tool_event_streaming directory. To align with that and ensure the sample runs correctly, this path should be updated.
| cd contributing/samples | |
| adk web . | |
| cd contributing/samples/agent_tool_event_streaming | |
| adk web . |
| if ( | ||
| event.content | ||
| and event.content.parts | ||
| and any( | ||
| part.function_response | ||
| for part in event.content.parts | ||
| if part.function_response | ||
| ) | ||
| ): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if not isinstance(tool_result, dict): | ||
| tool_result = {'result': tool_result} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… building logic into helper methods
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature for real-time event streaming from AgentTool sub-agents, which significantly improves the user experience for hierarchical agent systems by providing visibility into sub-agent execution. The implementation is well-structured, with a new streaming method in AgentTool, a dedicated handler in functions.py, and comprehensive unit tests and a sample application to validate the changes. My review includes a couple of suggestions to enhance maintainability by reducing code duplication and to improve performance by optimizing a list comprehension.
| parts=[ | ||
| part | ||
| for part in (function_call_event.content.parts or []) | ||
| if part.function_call | ||
| and part.function_call.name | ||
| not in [fc.name for fc, _ in agent_tool_calls] | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list comprehension used here to filter parts for regular_call_event re-evaluates [fc.name for fc, _ in agent_tool_calls] on each iteration. For improved performance, especially when dealing with many parts, it's more efficient to compute the set of agent tool names once before the list comprehension.
agent_tool_names = {fc.name for fc, _ in agent_tool_calls}
parts=[
part
for part in (function_call_event.content.parts or [])
if part.function_call
and part.function_call.name not in agent_tool_names
],
Implements real-time event streaming for AgentTool to propagate sub-agent events, addressing issue #3984.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
If applicable, please follow the issue templates to provide as much detail as
possible.
Problem:
When a coordinator agent delegates to a sub-agent via
AgentTool, the sub-agent's execution acts as a "black box". No events are yielded during sub-agent execution, making the frontend appear unresponsive for the duration of sub-agent execution (which can be 20-30 seconds for complex tasks). Only the final result is returned after sub-agent completes, providing no visibility into intermediate steps, tool calls, or responses.This creates a poor user experience for hierarchical multi-agent systems where users need real-time feedback about sub-agent progress.
Solution:
Implemented event streaming propagation for
AgentToolto yield events from sub-agents in real-time to the parent Runner. This enables:Implementation Details:
run_async_with_events()method toAgentToolthat yields events from sub-agent executionhandle_function_calls_async_with_agent_tool_streaming()helper function infunctions.pyto handle AgentTool event streaming_postprocess_handle_function_calls_async()inbase_llm_flow.pyto use the new streaming mechanismrun_async()method still works as beforeTesting Plan
Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.
Unit Tests:
Test Results:
Manual End-to-End (E2E) Tests:
Setup:
Test Steps:
agent_tool_event_streamingfrom the dropdownExpected Behavior:
research_agentappears immediatelyresearch_agentstream progressively (not all at once)Screenshots:



Checklist
Additional context
This PR will have merge conflicts with PR #3848 (streaming-tools-non-live) as both modify:
src/google/adk/flows/llm_flows/functions.pysrc/google/adk/flows/llm_flows/base_llm_flow.pyif we are planning to merge this pr first, then i will have to rebase again and fix the conflicts of #3848
Note: These are separate features (PR #3848 handles streaming tools in non-live mode, while this PR handles AgentTool event streaming), but they touch the same code paths.
Sample Code:
A complete sample demonstrating the feature is available at:
contributing/samples/agent_tool_event_streaming/Key Benefits: