Skip to content

fix(tools): allow transfer_to_agent to accept extra kwargs #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AlankritVerma01
Copy link
Contributor

@AlankritVerma01 AlankritVerma01 commented Apr 30, 2025

Fixes: #458

Background
When an LLM‐driven agent called transfer_to_agent with extra parameters (e.g. query, temperature), the tool raised:

TypeError: transfer_to_agent() got an unexpected keyword argument 'query'

because its signature only accepted agent_name and tool_context.

With this change, we:

  • Update src/google/adk/tools/transfer_to_agent_tool.py to:
    def transfer_to_agent(
        agent_name: str,
        tool_context: ToolContext,
        **kwargs,
    ):
        """Transfer the question to another agent."""
        tool_context.actions.transfer_to_agent = agent_name
    so that any unexpected kwargs are silently ignored.
  • Expand tests/integration/tools/test_transfer.py to include:
    1. A call with a single extra kwarg (query)
    2. A call with multiple extra kwargs (query, temperature, max_tokens)
      Each test is parametrized to run against both the GOOGLE_AI and VERTEX backends.

Test Plan

  1. Run the targeted integration tests:
    pytest tests/integration/tools/test_transfer.py
  2. Run the full suite to ensure no regressions:
    pytest

Checklist


Next Steps / TODO
@hangfei @Jacksunwei
Per the existing TODO comment in transfer_to_agent_tool.py, we could further internalize this tool (e.g. rename to _transfer_to_agent or move into an internal/ submodule) so it doesn’t leak into the public API.
I can work on that. Let me know if I can / should?

transfer_to_agent now takes **kwargs to swallow unexpected keyword args
Added integration tests covering single and multiple extra kwargs.
Fixes google#458.
@AlankritVerma01 AlankritVerma01 changed the title Tools/transfer accept kwargs fix(tools): allow transfer_to_agent to accept extra kwargs Apr 30, 2025
@Jacksunwei Jacksunwei self-assigned this May 1, 2025
@Jacksunwei
Copy link
Collaborator

Thanks for the PR!

But I think this is not the way to go. Model shouldn't be passing query to this tool. We need inspect the prompt and see why.

A better approach could be improving the docstring, which will be in the prompt.

…usage

Revert the earlier **kwargs change so transfer_to_agent again only accepts
(agent_name, tool_context).  Improve the doc-string to make clear that no
other parameters should be passed to this tool.

Fixes google#458
@AlankritVerma01
Copy link
Contributor Author

Thanks @Jacksunwei for the feedback! I’ve removed the **kwargs change and updated the docstring to clarify that only agent_name and tool_context are accepted and that parameters like query belong in the LLM prompt. Let me know if you’d like any further tweaks.

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.

transfer_to_agent tool fails with unexpected kwarg
2 participants