Skip to content

Conversation

@Harshal1000
Copy link

Please ensure you have read the contribution guide before creating a pull request.

Description of Change

Implement a skip_synthesis parameter in FunctionTool and AgentTool to explicitly skip the LLM synthesis step after tool execution.

Problem:
Currently, the agent loop forces an LLM synthesis (response generation) step after every tool execution. This leads to several issues in specific workflows:

  • Unnecessary Costs & Latency: In scenarios where a tool's output is self-sufficient, the LLM often generates redundant text.
    Example: After explaining "Ratio and Proportion," the agent calls a Recommended Resources tool. The tool displays the links, but the LLM then needlessly generates "Here are the recommended resources," consuming output tokens and adding latency.
  • Redundant Loops: For tasks like "Give me a report and attach reference links," the attachment tool should be the final action. Using the LLM to confirm "I have attached the links" is unnecessary.
  • Agent Looping Issues: Sometimes the LLM struggles to recognize the task is complete after a tool call, leading to unintentional loops where it tries to perform the same action again or hallucinates further steps

Solution:
Add a skip_synthesis boolean flag to the tool configuration.

  • Stops Agent Loop: When set to True, the agent loop terminates immediately after the tool execution. The tool's result is returned as the final response for the turn.
  • Workflow Control: This enables precise control for "fire-and-forget" tools or final-step actions (e.g., displaying a UI widget, sending a final report).
  • Efficiency: It significantly reduces cost and latency by bypassing the LLM inference for turns where the tool result is the only required output.

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

Run the new unit tests to verify the core logic in Event, FunctionTool, and the LLM Flow.

Command:

uv run pytest tests/unittests/events/test_event.py \
              tests/unittests/tools/test_function_tool.py \
              tests/unittests/flows/llm_flows/test_functions_skip_synthesis.py

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed pytest results.
Screenshot 2025-12-07 at 12 52 23 PM

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.

Use the newly created sample skip_synthesis_followup to verify the behavior in a real agent loop.
Setup: Ensure your local changes are installed in editable mode:

python3.13 -m pip install -e .

Run Sample:

cd contributing/samples
adk web .

Test Steps:

Open the Developer UI (http://127.0.0.1/:8000).

  1. Select the skip_synthesis_followup app.
  2. Send the message: "Explain quantum physics".
  3. Verify: The specific tool output should appear, followed immediately by the "Followup Agent" asking for questions. Valid behavior is confirmed if there is NO intermediate message from the Explainer Agent (e.g., "I have explained the topic...").

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Screenshot 2025-12-07 at 12 01 08 PM Screenshot 2025-12-07 at 12 01 18 PM Screenshot 2025-12-07 at 12 01 37 PM
Screen.Recording.2025-12-07.at.12.00.23.PM.mov

…esponse generation, along with a new sample and tests.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Harshal1000, 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 the agent framework by allowing developers to explicitly control when the LLM should synthesize a response after a tool has been executed. By adding a skip_synthesis flag to tools, the system can now prevent redundant LLM calls, reduce operational costs, decrease latency, and avoid common agent looping issues. This change empowers more efficient and predictable agent behavior, particularly for tools whose output is self-sufficient or marks the completion of a task.

Highlights

  • New skip_synthesis parameter: Introduced a skip_synthesis boolean flag to FunctionTool and AgentTool configurations. When set to True, this flag explicitly bypasses the LLM synthesis step after a tool's execution.
  • Improved Agent Efficiency: This feature addresses issues like unnecessary costs, latency, redundant LLM responses, and agent looping by allowing tools to return their output directly as the final response for a turn, without requiring further LLM processing.
  • Enhanced Workflow Control: Provides precise control for 'fire-and-forget' tools or actions that are intended to be the final step in a sequence, such as displaying a UI widget or sending a report, ensuring the agent loop terminates appropriately.
  • New Sample and Tests: A new sample application (skip_synthesis_followup) demonstrates the functionality, along with comprehensive unit tests for Event, FunctionTool, and the LLM Flow to verify the core logic and propagation of the skip_synthesis flag.
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 adk-bot added the core [Component] This issue is related to the core interface and implementation label Dec 7, 2025
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 a skip_synthesis flag to bypass LLM response generation after tool execution, which is a valuable enhancement for optimizing agent workflows. The implementation is well-structured, propagating the new flag from the tool definitions through to the event handling logic. The addition of a new sample application and corresponding unit tests is thorough and effectively demonstrates the feature's functionality. My review includes a few minor suggestions for the new sample code to fix a typo and adhere to Python's styling conventions. Overall, this is a solid contribution.

Harshal1000 and others added 4 commits December 7, 2025 12:58
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>
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>
@Harshal1000
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 a skip_synthesis flag to bypass LLM response generation after a tool execution, which is a valuable feature for improving efficiency and controlling agent workflows. The implementation is solid, with changes consistently applied across the tool and event systems, and is well-supported by new unit tests and a sample application.

My review includes two main points:

  1. A suggestion to remove redundant logic in AgentTool to improve maintainability.
  2. A fix for a bug in the new sample application where the agent's prompt for the output format mismatches its Pydantic output schema, which would likely cause runtime errors.

@ryanaiagent ryanaiagent self-assigned this Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants