fix: Update agent_card_builder to follow grammar rules

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

Fixes #2223

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/2226 from holtskinner:a2a-fixes ff556224e4071a8287a9ced19f645f0edd9916ef
PiperOrigin-RevId: 788512608
This commit is contained in:
Holt Skinner
2025-07-29 10:31:00 -07:00
committed by Copybara-Service
parent 5eff66a132
commit 9c0721beaa
2 changed files with 33 additions and 4 deletions
+22 -4
View File
@@ -224,7 +224,7 @@ def _build_code_executor_skill(agent: LlmAgent) -> AgentSkill:
return AgentSkill(
id=f'{agent.name}-code-executor',
name='code-execution',
description='Can execute codes',
description='Can execute code',
examples=None,
input_modes=None,
output_modes=None,
@@ -359,11 +359,29 @@ def _build_llm_agent_description_with_instructions(agent: LlmAgent) -> str:
def _replace_pronouns(text: str) -> str:
"""Replace pronouns in text for agent description (you -> I, your -> my, etc.)."""
pronoun_map = {'you': 'I', 'your': 'my', 'yours': 'mine'}
"""Replace pronouns and conjugate common verbs for agent description.
(e.g., "You are" -> "I am", "your" -> "my").
"""
pronoun_map = {
# Longer phrases with verb conjugations
'you are': 'I am',
'you were': 'I was',
"you're": 'I am',
"you've": 'I have',
# Standalone pronouns
'yours': 'mine',
'your': 'my',
'you': 'I',
}
# Sort keys by length (descending) to ensure longer phrases are matched first.
# This prevents "you" in "you are" from being replaced on its own.
sorted_keys = sorted(pronoun_map.keys(), key=len, reverse=True)
pattern = r'\b(' + '|'.join(re.escape(key) for key in sorted_keys) + r')\b'
return re.sub(
r'\b(you|your|yours)\b',
pattern,
lambda match: pronoun_map[match.group(1).lower()],
text,
flags=re.IGNORECASE,
@@ -403,6 +403,17 @@ class TestHelperFunctions:
# Assert
assert result == "youth, yourself, yourname" # No changes
def test_replace_pronouns_phrases(self):
"""Test _replace_pronouns with phrases that should be replaced."""
# Arrange
text = "You are a helpful chatbot"
# Act
result = _replace_pronouns(text)
# Assert
assert result == "I am a helpful chatbot"
def test_get_default_description_llm_agent(self):
"""Test _get_default_description for LlmAgent."""
# Arrange