File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
tests/unittests/a2a/utils Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -224,7 +224,7 @@ def _build_code_executor_skill(agent: LlmAgent) -> AgentSkill:
224
224
return AgentSkill (
225
225
id = f'{ agent .name } -code-executor' ,
226
226
name = 'code-execution' ,
227
- description = 'Can execute codes ' ,
227
+ description = 'Can execute code ' ,
228
228
examples = None ,
229
229
input_modes = None ,
230
230
output_modes = None ,
@@ -359,11 +359,29 @@ def _build_llm_agent_description_with_instructions(agent: LlmAgent) -> str:
359
359
360
360
361
361
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'
364
382
365
383
return re .sub (
366
- r'\b(you|your|yours)\b' ,
384
+ pattern ,
367
385
lambda match : pronoun_map [match .group (1 ).lower ()],
368
386
text ,
369
387
flags = re .IGNORECASE ,
Original file line number Diff line number Diff line change @@ -403,6 +403,17 @@ def test_replace_pronouns_partial_matches(self):
403
403
# Assert
404
404
assert result == "youth, yourself, yourname" # No changes
405
405
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
+
406
417
def test_get_default_description_llm_agent (self ):
407
418
"""Test _get_default_description for LlmAgent."""
408
419
# Arrange
You can’t perform that action at this time.
0 commit comments