You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
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:
committed by
Copybara-Service
parent
5eff66a132
commit
9c0721beaa
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user