-
Notifications
You must be signed in to change notification settings - Fork 2k
Added iterator agent for ADK pipeline #1611 #3103
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 @vivek100, 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 enhances the ADK's capabilities by introducing the ArrayIteratorAgent. This new agent provides a structured and efficient way to process collections of data within agent workflows. It allows for iterating over arrays in the session state, applying a single, focused sub-agent to each item, and then optionally collecting the results. This feature is crucial for handling common patterns like batch processing, document analysis, or data transformation, where a series of operations needs to be performed on multiple similar data points. The agent supports nested key access for flexible data handling and includes built-in validation and error handling to ensure robust operation. Highlights
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 new ArrayIteratorAgent
for processing arrays in session state, a valuable addition for common workflow patterns. The implementation is well-structured with good error handling and comprehensive unit tests. My review focuses on a critical issue in the result collection logic that fails to handle structured output from sub-agents correctly. I've also included suggestions to simplify the code and enhance test coverage to prevent similar issues in the future. Overall, this is a great feature, and with these fixes, it will be even more robust.
good catch Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
code suggestion to simplify the logic for storing results. The _set_nested_value function correctly handles both simple and nested keys, making the if/else check unnecessary. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…nt with output_schema Added a test case with a mock agent that simulates the behavior of an LlmAgent with output_schema. This mock test tests whether: Have an output_key attribute. Produce an event where event.actions.state_delta contains the structured result under its output_key. This will ensure that ArrayIteratorAgent correctly collects structured data from sub-agents.
/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 the ArrayIteratorAgent
, a useful addition for processing array data within the ADK pipeline. The implementation is solid, with good handling of nested keys and state management. The accompanying unit tests are comprehensive and cover a wide range of scenarios, ensuring the agent's reliability. The documentation and sample code are also well-written and provide clear guidance on usage. I've included a couple of suggestions to improve code clarity and documentation consistency.
Updated comment to show right text Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@gemini-code-assist can you look at the current implementation of agents in the main branch and create a pros and cons list of whether the itterator agent i created is helpful or not or there are other features already in the agent which we can use to achieve this. The idea is to give this option out of the box and option to connect this iterator agent with any of the available agents. |
Hi @vivek100, That's an excellent question! I've reviewed the ArrayIteratorAgent: Pros and ConsPros:
Cons (or Design Considerations):
Comparison with Existing Features
Conclusion on HelpfulnessThe Connecting with Any Available AgentsYes, the design allows for the Your implementation provides a much-needed abstraction that will make many common agent development patterns significantly simpler and more robust. Great work! |
Add ArrayIteratorAgent for Array Iteration Functionality
Summary
Implements ArrayIteratorAgent to provide built-in array iteration functionality for the ADK. This agent allows developers to iterate over arrays in session state and pass each element to a sub-agent for processing, addressing a common workflow pattern that was previously missing from the ADK.
Changes Made
✅ Added ArrayIteratorAgent class in src/google/adk/agents/array_iterator_agent.py
✅ Implemented single sub-agent constraint with validation
✅ Added support for nested array key access using dot notation (e.g., user_data.customers)
✅ Implemented automatic result collection from sub-agent's output_key
✅ Added comprehensive unit tests in tests/unittests/agents/test_array_iterator_agent.py
✅ Updated agent exports and imports for proper integration
✅ Added documentation and examples
Key Features
Single Sub-Agent Pattern: Enforces exactly one sub-agent to keep iteration focused and simple
Nested State Access: Supports dot notation for accessing nested arrays (app:config.items, user.data.list)
Automatic Collection: Collects results from sub-agent's output_key into an array
Configurable Context: Passes each array element via configurable item_key (default: current_item)
Optional Limits: Supports max_items parameter for processing subsets
Robust Error Handling: Validates array existence, sub-agent count, and handles edge cases
Usage Example
Sub-agent processes individual items
processor = LlmAgent(
name="item_processor",
instruction="Process: {current_item}",
output_key="result"
)
Array iterator
iterator = ArrayIteratorAgent(
name="batch_processor",
array_key="items",
output_key="all_results",
sub_agents=[processor]
)
Testing
✅ Unit tests cover all core functionality
✅ Edge cases tested (empty arrays, missing keys, validation errors)
✅ Integration with existing ADK patterns verified
✅ Nested state access thoroughly tested
✅ Error handling and validation confirmed
Breaking Changes
None - this is a new feature addition that doesn't modify existing functionality.
Documentation
Added comprehensive docstrings following Google style
Included usage examples in class documentation
Added type hints for all parameters and methods
Fixes #1610