Search⌘ K
AI Features

Loop Workflow

Explore how to create resilient AI workflows with LoopAgents in Google ADK. Learn to design iterative processes that handle retries and terminate dynamically, improving your multi-agent system's reliability and efficiency.

We have successfully engineered pipelines that are both reliable, using the SequentialAgent, and efficient, using the ParallelAgent. The final fundamental quality of a professional-grade system is resilience, the ability to handle tasks that may not succeed perfectly on the first attempt. Many real-world processes, especially those involving external systems, require iteration or retries.

In this lesson, we will introduce the LoopAgent as the tool for building resilient and iterative workflows. We will refactor our Research Assistant to handle a common scenario: a search that might not immediately return results. By adding a retry mechanism, we will create a more robust agent that can persist in its task, making our system more capable of handling the imperfections of real-world interactions.

Designing an iterative research pipeline

Let’s consider a practical challenge in our research process. When we query an external service like the arXiv API, there is no guarantee of immediate success. The service could be temporarily unavailable, or a search for a highly specific or niche topic might not yield results on the first try. A simple pipeline would fail in this scenario. A more robust and resilient agent, however, should be able to try again.

This is the perfect use case for a LoopAgent. We will redesign our workflow to incorporate an iterative research step:

  1. Iterative research: We will use a LoopAgent to repeatedly execute our arxiv_agent.

  2. Termination conditions: The loop will be designed to stop as soon as one of two conditions is met: either the arxiv_agent successfully ...