Skip to content

Conversation

@sarojrout
Copy link

@sarojrout sarojrout commented Jan 8, 2026

agent tool resilience sample to handle retry, timeout

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 adds a comprehensive sample to the ADK community repository, focusing on building resilient multi-agent applications. It provides practical examples and tools to manage common challenges like agent timeouts and failures, ensuring smoother operation and better user experience. The sample demonstrates how to implement robust error handling, retry mechanisms, and intelligent agent fallbacks, offering a blueprint for developers to create more reliable agent-based systems.

Highlights

  • New Resilience Sample: Introduces a new sample demonstrating AgentTool resilience patterns, including timeout handling, automatic retries, and dynamic agent redirection in multi-agent workflows using ADK.
  • Custom TimeoutAgentTool: Adds a custom TimeoutAgentTool wrapper that provides timeout protection for sub-agent execution, catching asyncio.TimeoutError and returning a structured error response.
  • Automatic Retry Mechanism: Integrates the ReflectAndRetryToolPlugin to handle automatic retries for failed tool calls, enhancing the robustness of agent interactions.
  • Dynamic Fallback and Error Recovery: Implements a coordinator_agent that dynamically routes requests to a research_agent_fallback when the primary agent fails or times out, and utilizes an error_recovery_agent for user-friendly error analysis.
  • Test Utilities for Resilience: Provides test_helpers.py with TimeoutSimulatorTool and FailureSimulatorTool to easily simulate timeout and failure scenarios for comprehensive testing of resilience patterns.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 an excellent and valuable sample demonstrating resiliency patterns such as timeouts, retries, and fallbacks in a multi-agent system. The code is well-structured, and the examples are clear and helpful. I've identified a critical issue with a filename that will prevent the Python package from being recognized, along with several medium-severity issues related to unused imports, a redundant variable, and code organization that will improve maintainability.

@sarojrout
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 an excellent and comprehensive sample for demonstrating agent resiliency patterns, including timeouts, retries, and fallbacks. The code is well-structured, with a clear separation of concerns that makes it easy to understand. The use of a custom TimeoutAgentTool and the ReflectAndRetryToolPlugin effectively showcases the capabilities of the ADK. I have a few minor suggestions to improve code clarity and fix a typo in the documentation.

├── agent.py # Agent definitions with resilience patterns
├── test_helpers.py # Test utilities for simulating timeouts and failures
├── test_example.py # Example script demonstrating how to test the sample
├── __Init__.py # Package initialization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in the filename within the sample structure diagram. Python package initialization files are conventionally named __init__.py in all lowercase.

Suggested change
├── __Init__.py # Package initialization
├── __init__.py # Package initialization

plugins=[retry_plugin],
)

root_agent = coordinator_agent No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The root_agent variable is redundant as it's assigned the coordinator_agent, which is already set as the root_agent for the app instance on line 245. This variable is also not used elsewhere in the sample. To improve code clarity and avoid redundancy, it's best to remove this line.


from google.adk.runners import Runner
from google.adk.tools import AgentTool
from agent import coordinator_agent, app, TimeoutAgentTool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The app variable is imported from the agent module but is not used anywhere in this file. Removing unused imports helps keep the code clean and maintainable.

Suggested change
from agent import coordinator_agent, app, TimeoutAgentTool
from agent import coordinator_agent, TimeoutAgentTool

print("=" * 60)

# Create a coordinator with timeout_test_agent wrapped in TimeoutAgentTool
from agent import Agent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This Agent class is imported locally within the function. According to PEP 8 style guidelines, imports should be placed at the top of the file. This improves readability and makes dependencies clear. Please remove this local import and add from google.adk import Agent at the top of the file.

print("=" * 60)

# Create a coordinator with failure_test_agent
from agent import Agent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other test function, this Agent class is imported locally. For consistency and adherence to PEP 8, please move this import to the top of the file. This makes the code cleaner and easier to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant