Skip to content

Commit 5442960

Browse files
committed
fix: clean up transfer_to_agent docstring to reduce token waste
Move developer-facing note from the docstring to a code comment above the function. The docstring is sent to the model on every tool call, so keeping it lean reduces token usage and lowers hallucination risk. Fixes #4615
1 parent d47e4c6 commit 5442960

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/google/adk/flows/llm_flows/base_llm_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def _finalize_model_response_event(
121121
# Restore previously-assigned IDs (by position) so that partial and
122122
# final SSE events for the same function call share the same ID.
123123
if prior_fc_ids:
124-
for idx, fc in enumerate(function_calls):
125-
if idx < len(prior_fc_ids) and prior_fc_ids[idx]:
126-
fc.id = prior_fc_ids[idx]
124+
for fc, prior_id in zip(function_calls, prior_fc_ids):
125+
if prior_id:
126+
fc.id = prior_id
127127

128128
functions.populate_client_function_call_id(finalized_event)
129129

src/google/adk/tools/transfer_to_agent_tool.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@
2323
from .tool_context import ToolContext
2424

2525

26+
# Note: For most use cases, you should use TransferToAgentTool instead of this
27+
# function directly. TransferToAgentTool provides additional enum constraints
28+
# that prevent LLMs from hallucinating invalid agent names.
2629
def transfer_to_agent(agent_name: str, tool_context: ToolContext) -> None:
2730
"""Transfer the question to another agent.
2831
2932
This tool hands off control to another agent when it's more suitable to
3033
answer the user's question according to the agent's description.
3134
32-
Note:
33-
For most use cases, you should use TransferToAgentTool instead of this
34-
function directly. TransferToAgentTool provides additional enum constraints
35-
that prevent LLMs from hallucinating invalid agent names.
36-
3735
Args:
3836
agent_name: the agent name to transfer to.
3937
"""

0 commit comments

Comments
 (0)