Skip to content

fix: remove developer note from transfer_to_agent tool description#4654

Closed
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/transfer-to-agent-docstring
Closed

fix: remove developer note from transfer_to_agent tool description#4654
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/transfer-to-agent-docstring

Conversation

@giulio-leone
Copy link

Summary

Fixes #4615

The transfer_to_agent() function docstring included a Note: section with developer-facing guidance about preferring TransferToAgentTool. Since FunctionTool extracts the full docstring via inspect.cleandoc() and uses it as the tool description sent to the model on every invocation, this developer note was:

  1. Consuming unnecessary input tokens on every API call
  2. Adding irrelevant context to the model (advice about Python class usage)

Changes

  • Moved the developer-facing note from the docstring to an inline comment in the function body
  • The note remains visible to developers reading the source code
  • The tool description sent to the model is now concise and relevant

Before (sent to model)

Transfer the question to another agent.

This tool hands off control to another agent when it's more suitable to
answer the user's question according to the agent's description.

Note:
  For most use cases, you should use TransferToAgentTool instead of this
  function directly. TransferToAgentTool provides additional enum constraints
  that prevent LLMs from hallucinating invalid agent names.

Args:
  agent_name: the agent name to transfer to.

After (sent to model)

Transfer the question to another agent.

This tool hands off control to another agent when it's more suitable to
answer the user's question according to the agent's description.

Args:
  agent_name: the agent name to transfer to.

Testing

  • All 44 existing transfer tool and function declaration tests pass (2 consecutive clean runs)
  • Verified that TransferToAgentTool.description no longer contains the Note section

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refines the transfer_to_agent tool's description to optimize Large Language Model (LLM) interactions. By moving a developer-specific note from the function's docstring to an inline comment, the change reduces token usage and ensures that the model receives only relevant information, thereby improving efficiency and context clarity during API calls.

Highlights

  • Token Optimization: Removed a developer-facing note from the transfer_to_agent function's docstring to reduce unnecessary input token consumption by the model.
  • Model Context Improvement: Ensured the tool description sent to the model is concise and relevant by removing developer-specific guidance.
  • Code Readability: Relocated the developer note to an inline comment within the function body, maintaining visibility for developers without affecting the model's input.

🧠 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
  • src/google/adk/tools/transfer_to_agent_tool.py
    • Moved a developer note from the docstring to an inline comment within the function body.
Activity
  • No human activity has occurred on this pull request yet.
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.

@google-cla
Copy link

google-cla bot commented Feb 28, 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.

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Feb 28, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Feb 28, 2026

Response from ADK Triaging Agent

Hello @giulio-leone, thank you for your contribution!

Before we can merge this pull request, you'll need to sign a Contributor License Agreement (CLA). You can find more information in the "checks" section at the bottom of the pull request.

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 pull request correctly moves a developer-facing note from the transfer_to_agent function's docstring to an inline comment, preventing it from being sent to the LLM. This is a good change that saves tokens and removes irrelevant context for the model. I have added one suggestion to reformat the new comment to align with PEP 8 style guidelines for line length.

Comment on lines +35 to +37
# Developer note: For most use cases, prefer TransferToAgentTool over
# calling this function directly. TransferToAgentTool adds enum
# constraints that prevent LLMs from hallucinating invalid agent names.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

According to the PEP 8 style guide, lines in a block comment should be limited to 72 characters for readability. The first line of this comment exceeds this limit. Please re-wrap the comment to adhere to this guideline.

Suggested change
# Developer note: For most use cases, prefer TransferToAgentTool over
# calling this function directly. TransferToAgentTool adds enum
# constraints that prevent LLMs from hallucinating invalid agent names.
# Developer note: For most use cases, prefer TransferToAgentTool
# over calling this function directly. TransferToAgentTool adds enum
# constraints that prevent LLMs from hallucinating invalid agent names.
References
  1. PEP 8 recommends limiting lines of block comments to 72 characters to improve readability. (link)

@giulio-leone giulio-leone force-pushed the fix/transfer-to-agent-docstring branch from bda119b to 8010c56 Compare February 28, 2026 14:38
The docstring of transfer_to_agent() included a 'Note:' section with
developer-facing advice about preferring TransferToAgentTool. Since
FunctionTool uses the full docstring as the tool description sent to
the model on every invocation, this note was consuming input tokens
and adding irrelevant information to the model context.

Move the note to an inline comment in the function body so it remains
visible to developers but is not included in the tool description.

Fixes google#4615
@giulio-leone giulio-leone force-pushed the fix/transfer-to-agent-docstring branch from 8010c56 to a457fb7 Compare February 28, 2026 14:39
@giulio-leone
Copy link
Author

Closing — CLA not yet signed. Will resubmit when ready.

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

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the docstring for the transfer_to_agent tool to remove unneeded information sent to the model.

2 participants