feat: Add enum constraint to agent_name for transfer_to_agent

Merge https://github.com/google/adk-python/pull/2437

Current implementation of `transfer_to_agent` doesn't enforce strict constraints on agent names, we could use JSON Schema's enum definition to implement stricter constraints.

Co-authored-by: Xuan Yang <xygoogle@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/2437 from qieqieplus:main 052e8e73b9d61c0998573a2077f15864873d0dd7
PiperOrigin-RevId: 836410397
This commit is contained in:
qieqieplus
2025-11-24 16:51:36 -08:00
committed by Copybara-Service
parent 728abe4d81
commit 4a42d0d9d8
6 changed files with 286 additions and 33 deletions
@@ -126,15 +126,16 @@ Agent name: peer_agent
Agent description: Peer agent
If you are the best to answer the question according to your description, you
can answer it.
If you are the best to answer the question according to your description,
you can answer it.
If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transferring, do not generate any text other than
the function call.
description, call `transfer_to_agent` function to transfer the question to that
agent. When transferring, do not generate any text other than the function
call.
**NOTE**: the only available agents for `transfer_to_agent` function are `a_agent`, `m_agent`, `parent_agent`, `peer_agent`, `z_agent`.
**NOTE**: the only available agents for `transfer_to_agent` function are
`a_agent`, `m_agent`, `parent_agent`, `peer_agent`, `z_agent`.
If neither you nor the other agents are best for the question, transfer to your parent agent parent_agent."""
@@ -189,15 +190,16 @@ Agent name: agent2
Agent description: Second sub-agent
If you are the best to answer the question according to your description, you
can answer it.
If you are the best to answer the question according to your description,
you can answer it.
If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transferring, do not generate any text other than
the function call.
description, call `transfer_to_agent` function to transfer the question to that
agent. When transferring, do not generate any text other than the function
call.
**NOTE**: the only available agents for `transfer_to_agent` function are `agent1`, `agent2`."""
**NOTE**: the only available agents for `transfer_to_agent` function are
`agent1`, `agent2`."""
assert expected_content in instructions
@@ -248,15 +250,16 @@ Agent name: parent_agent
Agent description: Parent agent
If you are the best to answer the question according to your description, you
can answer it.
If you are the best to answer the question according to your description,
you can answer it.
If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transferring, do not generate any text other than
the function call.
description, call `transfer_to_agent` function to transfer the question to that
agent. When transferring, do not generate any text other than the function
call.
**NOTE**: the only available agents for `transfer_to_agent` function are `parent_agent`, `sub_agent`.
**NOTE**: the only available agents for `transfer_to_agent` function are
`parent_agent`, `sub_agent`.
If neither you nor the other agents are best for the question, transfer to your parent agent parent_agent."""