Skip to content

Add detailed ReAct loop flowchart documentation#4484

Open
bsamadi wants to merge 1 commit intogoogle:mainfrom
Nubonetics:claude/react-loop-flowchart-bM2QR
Open

Add detailed ReAct loop flowchart documentation#4484
bsamadi wants to merge 1 commit intogoogle:mainfrom
Nubonetics:claude/react-loop-flowchart-bM2QR

Conversation

@bsamadi
Copy link

@bsamadi bsamadi commented Feb 13, 2026

Link to Issue or Description of Change

2. Description of Change:

Problem:
The Google ADK Python library's internal ReAct (Reason + Act) loop execution flow is complex, spanning multiple layers and files. Developers and contributors lack a comprehensive visual reference that traces the full execution path from entry point through LLM invocation, tool execution, and loop termination.

Solution:
Added a new documentation file docs/react-loop-flowchart.md that provides:

  1. Source file reference table — Maps each layer of the execution stack to its corresponding file and line numbers for quick navigation
  2. High-level overview flowchart — Shows the entry point flow from Runner.run_async() through BaseAgent to LlmAgent
  3. Detailed ReAct loop flowchart — Comprehensive Mermaid diagram illustrating:
    • The main while True loop in BaseLlmFlow.run_async()
    • Five core stages: preprocess, LLM call (Reason), postprocess, tool execution (Act), and loop decision
    • Internal details of LLM invocation with callback hooks
    • Parallel tool execution pipeline with per-tool callback stages
    • Post-tool checks (auth, confirmation, agent transfer)
    • Loop termination conditions
  4. Loop termination conditions table — Documents the is_final_response() logic that determines when the ReAct loop exits
  5. Key design characteristics — Highlights six important architectural patterns (async generators, parallel execution, callback pipeline, agent transfer, resumability, callback short-circuits)

This documentation serves as a reference guide for understanding the framework's core control flow and will help contributors navigate the codebase more effectively.

Testing Plan

No testing needed — this is a documentation-only change that adds a new reference guide without modifying any source code, tests, or functionality.

Checklist

  • I have read the CONTRIBUTING.md document.
  • This is a documentation addition with no code changes.
  • The documentation accurately reflects the current implementation based on source file references.

Additional context

The flowchart uses Mermaid syntax for rendering in GitHub and includes color-coded nodes to distinguish between reasoning steps (blue), action/tool execution (orange), decision points (yellow), and event yields (green). All line number references are approximate and point to the general location of key functions for easy lookup.

https://claude.ai/code/session_016VEahaKckWEj9PWBgqr6Yi

Traces the full execution path from Runner.run_async() through
BaseLlmFlow's while-True loop, covering LLM invocation, parallel
tool execution, agent transfer, resumability, and loop termination
conditions. Includes Mermaid diagrams and source file references.

https://claude.ai/code/session_016VEahaKckWEj9PWBgqr6Yi
@google-cla
Copy link

google-cla bot commented Feb 13, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bsamadi, 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 documentation for the Google ADK Python library by introducing a detailed guide to its internal ReAct (Reason + Act) loop. The new documentation provides a clear, visual, and structured explanation of the agent's core execution flow, from initial invocation through LLM interaction and tool execution, addressing the complexity of the system's multi-layered architecture. This addition aims to improve understanding for developers and contributors, making it easier to navigate and contribute to the codebase.

Highlights

  • New Documentation File: Added docs/react-loop-flowchart.md to provide a comprehensive visual and textual guide to the internal ReAct loop.
  • Source File References: Included a table mapping each layer of the execution stack to its corresponding file and approximate line numbers for quick navigation.
  • High-Level Overview Flowchart: Provided a Mermaid diagram illustrating the entry point flow from Runner.run_async() through BaseAgent to LlmAgent.
  • Detailed ReAct Loop Flowchart: Presented a comprehensive Mermaid diagram detailing the main while True loop in BaseLlmFlow.run_async(), including preprocess, LLM call (Reason), postprocess, tool execution (Act), and loop decision stages, with color-coded nodes.
  • Loop Termination Conditions: Documented the is_final_response() logic that determines when the ReAct loop exits, including specific conditions.
  • Key Design Characteristics: Highlighted six important architectural patterns of the ReAct loop, such as async generators, parallel tool execution, and callback short-circuits.

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

Changelog
  • docs/react-loop-flowchart.md
    • Added a new documentation file explaining the internal ReAct loop.
    • Included a source file reference table for key components.
    • Provided a high-level overview flowchart of the agent's execution.
    • Detailed the ReAct loop with a comprehensive Mermaid flowchart.
    • Documented the conditions for loop termination.
    • Outlined key design characteristics of the ReAct implementation.
Activity
  • The pull request introduces new documentation without modifying any existing source code, tests, or functionality.
  • The author confirmed that the documentation accurately reflects the current implementation and has read the contributing guidelines.
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.

@adk-bot
Copy link
Collaborator

adk-bot commented Feb 13, 2026

Response from ADK Triaging Agent

Hello @bsamadi, thank you for your contribution!

Before we can merge this PR, you'll need to sign the Contributor License Agreement (CLA). You can do so by following the instructions at https://cla.developers.google.com/.

Once the CLA is signed, we can proceed with the review of your documentation addition. Thanks!

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 is an excellent documentation addition. The detailed flowcharts and source code references provide a much-needed comprehensive guide to the internal ReAct loop, which will be incredibly valuable for both new and existing developers working with the ADK. The breakdown of the loop into stages, termination conditions, and key design patterns is very clear and well-structured. I have one minor suggestion to improve the clarity of the detailed flowchart.

Comment on lines +102 to +103
AMC -- altered response --> YIELD_LLM_RESP
AMC -- no change --> YIELD_LLM_RESP["Yield LlmResponse"]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

In the _call_llm_async() internals subgraph, the after_model_callback? decision node has two branches (altered response and no change) that both lead to the same Yield LlmResponse step. While correct, this can be simplified for better readability. Since the callback's purpose is to potentially alter the response before it's yielded, a single path from the callback to the yield step would make the diagram cleaner without losing the essential logic. The fact that the response can be altered is implicit in the nature of an after_ callback.

Suggested change
AMC -- altered response --> YIELD_LLM_RESP
AMC -- no change --> YIELD_LLM_RESP["Yield LlmResponse"]
AMC --> YIELD_LLM_RESP["Yield LlmResponse"]

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.

3 participants