Skip to content

Commit 9c0721b

Browse files
holtskinnercopybara-github
authored andcommitted
fix: Update agent_card_builder to follow grammar rules
Merge #2226 Fixes #2223 COPYBARA_INTEGRATE_REVIEW=#2226 from holtskinner:a2a-fixes ff55622 PiperOrigin-RevId: 788512608
1 parent 5eff66a commit 9c0721b

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/google/adk/a2a/utils/agent_card_builder.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _build_code_executor_skill(agent: LlmAgent) -> AgentSkill:
224224
return AgentSkill(
225225
id=f'{agent.name}-code-executor',
226226
name='code-execution',
227-
description='Can execute codes',
227+
description='Can execute code',
228228
examples=None,
229229
input_modes=None,
230230
output_modes=None,
@@ -359,11 +359,29 @@ def _build_llm_agent_description_with_instructions(agent: LlmAgent) -> str:
359359

360360

361361
def _replace_pronouns(text: str) -> str:
362-
"""Replace pronouns in text for agent description (you -> I, your -> my, etc.)."""
363-
pronoun_map = {'you': 'I', 'your': 'my', 'yours': 'mine'}
362+
"""Replace pronouns and conjugate common verbs for agent description.
363+
(e.g., "You are" -> "I am", "your" -> "my").
364+
"""
365+
pronoun_map = {
366+
# Longer phrases with verb conjugations
367+
'you are': 'I am',
368+
'you were': 'I was',
369+
"you're": 'I am',
370+
"you've": 'I have',
371+
# Standalone pronouns
372+
'yours': 'mine',
373+
'your': 'my',
374+
'you': 'I',
375+
}
376+
377+
# Sort keys by length (descending) to ensure longer phrases are matched first.
378+
# This prevents "you" in "you are" from being replaced on its own.
379+
sorted_keys = sorted(pronoun_map.keys(), key=len, reverse=True)
380+
381+
pattern = r'\b(' + '|'.join(re.escape(key) for key in sorted_keys) + r')\b'
364382

365383
return re.sub(
366-
r'\b(you|your|yours)\b',
384+
pattern,
367385
lambda match: pronoun_map[match.group(1).lower()],
368386
text,
369387
flags=re.IGNORECASE,

tests/unittests/a2a/utils/test_agent_card_builder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ def test_replace_pronouns_partial_matches(self):
403403
# Assert
404404
assert result == "youth, yourself, yourname" # No changes
405405

406+
def test_replace_pronouns_phrases(self):
407+
"""Test _replace_pronouns with phrases that should be replaced."""
408+
# Arrange
409+
text = "You are a helpful chatbot"
410+
411+
# Act
412+
result = _replace_pronouns(text)
413+
414+
# Assert
415+
assert result == "I am a helpful chatbot"
416+
406417
def test_get_default_description_llm_agent(self):
407418
"""Test _get_default_description for LlmAgent."""
408419
# Arrange

0 commit comments

Comments
 (0)