Skip to content

Commit 5bee33c

Browse files
committed
fix: Update agent_card_builder to follow grammar rules
1 parent f29ab5d commit 5bee33c

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

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

Lines changed: 36 additions & 5 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,16 +359,47 @@ 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+
"""
363+
Replace pronouns and conjugate common verbs for agent description.
364+
(e.g., "You are" -> "I am", "your" -> "my").
365+
"""
366+
# --- Stage 1: Handle specific phrases with verb conjugations ---
367+
phrase_map = {
368+
'you are': 'I am',
369+
'you were': 'I was',
370+
"you're": 'I am',
371+
"you've": 'I have',
372+
}
373+
374+
phrase_pattern = r'\b(' + '|'.join(phrase_map.keys()) + r')\b'
375+
376+
text = re.sub(
377+
phrase_pattern,
378+
lambda match: phrase_map[match.group(1).lower()],
379+
text,
380+
flags=re.IGNORECASE,
381+
)
382+
383+
# --- Stage 2: Handle remaining, standalone pronouns ---
384+
# This runs on the already-modified text to catch any remaining pronouns.
385+
pronoun_map = {
386+
'you': 'I',
387+
'your': 'my',
388+
'yours': 'mine',
389+
'yourself': 'myself',
390+
}
391+
392+
pronoun_pattern = r'\b(' + '|'.join(pronoun_map.keys()) + r')\b'
364393

365-
return re.sub(
366-
r'\b(you|your|yours)\b',
394+
text = re.sub(
395+
pronoun_pattern,
367396
lambda match: pronoun_map[match.group(1).lower()],
368397
text,
369398
flags=re.IGNORECASE,
370399
)
371400

401+
return text
402+
372403

373404
def _get_workflow_description(agent: BaseAgent) -> Optional[str]:
374405
"""Get workflow-specific description for non-LLM agents."""

0 commit comments

Comments
 (0)