Skip to content

Commit 71037fe

Browse files
committed
Improve wording for agent card information into agent transfer context
1 parent a177fab commit 71037fe

File tree

1 file changed

+48
-52
lines changed

1 file changed

+48
-52
lines changed

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

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -82,49 +82,36 @@ def _build_target_agent_info_from_card(
8282
agent_card: The resolved A2A Agent Card
8383
8484
Returns:
85-
Formatted string with detailed agent information from the card
85+
Formatted string with detailed agent information from the card,
86+
optimized for LLM consumption when selecting subagents.
8687
"""
87-
info_parts = [f'Agent name: {target_agent.name}']
88+
info_parts = []
8889

89-
# Use card description if available, fallback to agent description
90-
description = agent_card.description or target_agent.description
91-
if description:
92-
info_parts.append(f'Agent description: {description}')
90+
# Start with a clear header for the agent
91+
info_parts.append(f'### Agent: {target_agent.name}')
9392

94-
# Add skills information from the card
93+
# Include both RemoteA2aAgent description and agent card description
94+
# This provides both the locally-configured context and the remote agent's self-description
95+
descriptions = []
96+
if target_agent.description:
97+
descriptions.append(f'Description: {target_agent.description}')
98+
if agent_card.description and agent_card.description != target_agent.description:
99+
descriptions.append(f'Agent card description: {agent_card.description}')
100+
101+
if descriptions:
102+
info_parts.append('\n'.join(descriptions))
103+
104+
# Add skills in a structured, LLM-friendly format
95105
if agent_card.skills:
96-
skills_info = []
106+
info_parts.append('\nSkills:')
97107
for skill in agent_card.skills:
98-
skill_desc = f' - {skill.name}'
108+
# Format: "- skill_name: description (tags: tag1, tag2)"
109+
skill_parts = [f' - **{skill.name}**']
99110
if skill.description:
100-
skill_desc += f': {skill.description}'
111+
skill_parts.append(f': {skill.description}')
101112
if skill.tags:
102-
skill_desc += f' (tags: {", ".join(skill.tags)})'
103-
skills_info.append(skill_desc)
104-
105-
info_parts.append(f'Agent skills:\n' + '\n'.join(skills_info))
106-
107-
# Add capabilities if available
108-
if agent_card.capabilities:
109-
caps = agent_card.capabilities
110-
cap_info = []
111-
if hasattr(caps, 'streaming') and caps.streaming:
112-
cap_info.append('supports streaming')
113-
if hasattr(caps, 'multimodal') and caps.multimodal:
114-
cap_info.append('supports multimodal input/output')
115-
116-
if cap_info:
117-
info_parts.append(f'Capabilities: {", ".join(cap_info)}')
118-
119-
# Add input/output modes
120-
if agent_card.default_input_modes:
121-
info_parts.append(
122-
f'Input modes: {", ".join(agent_card.default_input_modes)}'
123-
)
124-
if agent_card.default_output_modes:
125-
info_parts.append(
126-
f'Output modes: {", ".join(agent_card.default_output_modes)}'
127-
)
113+
skill_parts.append(f' [Tags: {", ".join(skill.tags)}]')
114+
info_parts.append(''.join(skill_parts))
128115

129116
return '\n'.join(info_parts)
130117

@@ -166,12 +153,15 @@ def _build_target_agents_info(target_agent: BaseAgent) -> str:
166153
target_agent: The agent to build info for
167154
168155
Returns:
169-
Formatted string with basic agent information
156+
Formatted string with basic agent information, matching the enhanced format
157+
for consistency with A2A agent cards.
170158
"""
171-
return f"""
172-
Agent name: {target_agent.name}
173-
Agent description: {target_agent.description}
174-
"""
159+
info_parts = [f'### Agent: {target_agent.name}']
160+
161+
if target_agent.description:
162+
info_parts.append(f'Description: {target_agent.description}')
163+
164+
return '\n'.join(info_parts)
175165

176166

177167
line_break = '\n'
@@ -187,7 +177,8 @@ async def _build_target_agents_instructions(
187177
target_agents: List of agents that can be transferred to
188178
189179
Returns:
190-
Formatted instructions string with agent transfer information
180+
Formatted instructions string with agent transfer information,
181+
optimized for LLM decision-making about which subagent to use.
191182
"""
192183
# Build list of available agent names for the NOTE
193184
# target_agents already includes parent agent if applicable, so no need to add it again
@@ -207,25 +198,30 @@ async def _build_target_agents_instructions(
207198
agent_info = await _build_target_agents_info_async(target_agent)
208199
agent_info_list.append(agent_info)
209200

201+
# Create a separator for visual clarity
202+
agents_section = '\n\n'.join(agent_info_list)
203+
210204
si = f"""
211-
You have a list of other agents to transfer to:
205+
## Available Agents for Transfer
206+
207+
You can delegate tasks to the following specialized agents. Carefully review each agent's description and skills to determine the best match for the user's request.
208+
209+
{agents_section}
210+
211+
## Decision Criteria
212212
213-
{line_break.join(agent_info_list)}
213+
1. **Assess your own capability**: If you are the best agent to handle this request based on your own description and capabilities, answer it directly.
214214
215-
If you are the best to answer the question according to your description, you
216-
can answer it.
215+
2. **Consider specialized agents**: If another agent has more relevant skills or expertise for this request, call the `{_TRANSFER_TO_AGENT_FUNCTION_NAME}` function to transfer to that agent. Match the user's needs with the agent's skills and descriptions above.
217216
218-
If another agent is better for answering the question according to its
219-
description, call `{_TRANSFER_TO_AGENT_FUNCTION_NAME}` function to transfer the
220-
question to that agent. When transferring, do not generate any text other than
221-
the function call.
217+
3. **When transferring**: Only call the function - do not generate any additional text.
222218
223-
**NOTE**: the only available agents for `{_TRANSFER_TO_AGENT_FUNCTION_NAME}` function are {formatted_agent_names}.
219+
**IMPORTANT**: The only valid agent names for `{_TRANSFER_TO_AGENT_FUNCTION_NAME}` are: {formatted_agent_names}
224220
"""
225221

226222
if agent.parent_agent and not agent.disallow_transfer_to_parent:
227223
si += f"""
228-
If neither you nor the other agents are best for the question, transfer to your parent agent {agent.parent_agent.name}.
224+
4. **Escalate to parent**: If neither you nor the specialized agents are suitable for this request, transfer to your parent agent `{agent.parent_agent.name}` for broader assistance.
229225
"""
230226
return si
231227

0 commit comments

Comments
 (0)