Skip to content

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.

@Jacksunwei Jacksunwei changed the title fix(tools): allow transfer_to_agent to accept extra kwargs chore: refines transfer_to_agent docstring for more stable agent transfer stability. May 29, 2025
@Jacksunwei Jacksunwei added the ready to pull [Status] This PR is ready to be importing back to Google label May 29, 2025
@Jacksunwei Jacksunwei added ready to pull [Status] This PR is ready to be importing back to Google and removed ready to pull [Status] This PR is ready to be importing back to Google labels May 29, 2025
copybara-service bot pushed a commit that referenced this pull request May 29, 2025
Copybara import of the project:

--
e246af5 by Alankrit Verma <[email protected]>:

tools: allow transfer_to_agent to accept extra kwargs

transfer_to_agent now takes **kwargs to swallow unexpected keyword args
Added integration tests covering single and multiple extra kwargs.
Fixes #458.

--
55fea78 by Alankrit Verma <[email protected]>:

fix(tests): correct indentation in test_transfer.py for better readability

--
0c04f2d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): restore strict two-arg signature and clarify 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 #458

--
d37448d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): update docstring for clarity and accuracy

--
ea827af by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool docstring for better prompt
--
a144069 by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool.py

COPYBARA_INTEGRATE_REVIEW=#466 from AlankritVerma01:tools/transfer-accept-kwargs 686d436
PiperOrigin-RevId: 764940463
@hangfei
Copy link
Collaborator

hangfei commented May 30, 2025

merged in 854a544. Thanks!

@hangfei hangfei closed this May 30, 2025
@Jacksunwei Jacksunwei added this to the FixIt Week milestone May 30, 2025
whhlct pushed a commit to whhlct/adk-python that referenced this pull request Jun 6, 2025
Copybara import of the project:

--
e246af5 by Alankrit Verma <[email protected]>:

tools: allow transfer_to_agent to accept extra kwargs

transfer_to_agent now takes **kwargs to swallow unexpected keyword args
Added integration tests covering single and multiple extra kwargs.
Fixes google#458.

--
55fea78 by Alankrit Verma <[email protected]>:

fix(tests): correct indentation in test_transfer.py for better readability

--
0c04f2d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): restore strict two-arg signature and clarify 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

--
d37448d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): update docstring for clarity and accuracy

--
ea827af by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool docstring for better prompt
--
a144069 by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool.py

COPYBARA_INTEGRATE_REVIEW=google#466 from AlankritVerma01:tools/transfer-accept-kwargs 686d436
PiperOrigin-RevId: 764940463
coder-aditi pushed a commit to coder-aditi/adk-python that referenced this pull request Jul 2, 2025
Copybara import of the project:

--
e246af5 by Alankrit Verma <[email protected]>:

tools: allow transfer_to_agent to accept extra kwargs

transfer_to_agent now takes **kwargs to swallow unexpected keyword args
Added integration tests covering single and multiple extra kwargs.
Fixes google#458.

--
55fea78 by Alankrit Verma <[email protected]>:

fix(tests): correct indentation in test_transfer.py for better readability

--
0c04f2d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): restore strict two-arg signature and clarify 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

--
d37448d by Alankrit Verma <[email protected]>:

fix(transfer_to_agent): update docstring for clarity and accuracy

--
ea827af by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool docstring for better prompt
--
a144069 by Wei Sun (Jack) <[email protected]>:

Update transfer_to_agent_tool.py

COPYBARA_INTEGRATE_REVIEW=google#466 from AlankritVerma01:tools/transfer-accept-kwargs 686d436
PiperOrigin-RevId: 764940463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to pull [Status] This PR is ready to be importing back to Google
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transfer_to_agent tool fails with unexpected kwarg
3 participants