fix: Convert examples for A2A agent card

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

The AgentSkill in an A2A AgentCard expects examples to be a list of queries as strings. Therefore, agent examples, e.g., as provided by an ExampleTool, must be converted.

This change performs that extraction of just the inputs and converting them to a string to add to the AgentSkill.

### Testing Plan

**Unit Tests:**

- [x] I have added or updated unit tests for my change.
- [x] All unit tests pass locally.

**Manual End-to-End (E2E) Tests:**

Create an agent with ExampleTool and use agent card builder to create agent card for that agent. Fails without this change, succeeds with change included.

### Checklist

- [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] New and existing unit tests pass locally with my changes.
- [x] I have manually tested my changes end-to-end.
- [x] Any dependent changes have been merged and published in downstream modules.

Co-authored-by: Xiang (Sean) Zhou <seanzhougoogle@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3999 from timn:timn/fix-a2a-examples-from-tool 34c727c3311d2ec945efa3eec652d9e28b6ae2a9
PiperOrigin-RevId: 855288587
This commit is contained in:
Tim Niemueller
2026-01-12 10:37:24 -08:00
committed by Copybara-Service
parent 4a34501d38
commit 458d24e24e
2 changed files with 102 additions and 2 deletions
@@ -28,6 +28,7 @@ from google.adk.a2a.utils.agent_card_builder import _build_parallel_description
from google.adk.a2a.utils.agent_card_builder import _build_sequential_description
from google.adk.a2a.utils.agent_card_builder import _convert_example_tool_examples
from google.adk.a2a.utils.agent_card_builder import _extract_examples_from_instruction
from google.adk.a2a.utils.agent_card_builder import _extract_inputs_from_examples
from google.adk.a2a.utils.agent_card_builder import _get_agent_skill_name
from google.adk.a2a.utils.agent_card_builder import _get_agent_type
from google.adk.a2a.utils.agent_card_builder import _get_default_description
@@ -41,6 +42,7 @@ from google.adk.agents.llm_agent import LlmAgent
from google.adk.agents.loop_agent import LoopAgent
from google.adk.agents.parallel_agent import ParallelAgent
from google.adk.agents.sequential_agent import SequentialAgent
from google.adk.examples import Example
from google.adk.tools.example_tool import ExampleTool
import pytest
@@ -1100,3 +1102,73 @@ class TestExampleExtractionFunctions:
assert len(result) == 1 # Only complete pairs should be included
assert result[0]["input"] == {"text": "What is the weather?"}
assert result[0]["output"] == [{"text": "What time is it?"}]
def test_extract_inputs_from_examples_from_plain_text_input(self):
"""Test _extract_inputs_from_examples on plain text as input."""
# Arrange
examples = [
{
"input": {"text": "What is the weather?"},
"output": [{"text": "What time is it?"}],
},
{
"input": {"text": "The weather is sunny."},
"output": [{"text": "It is 3 PM."}],
},
]
# Act
result = _extract_inputs_from_examples(examples)
# Assert
assert len(result) == 2
assert result[0] == "What is the weather?"
assert result[1] == "The weather is sunny."
def test_extract_inputs_from_examples_from_example_tool(self):
"""Test _extract_inputs_from_examples as extracted from ExampleTool."""
# Arrange
# This is what would be extracted from an ExampleTool
examples = [
{
"input": {
"role": "user",
"parts": [{"text": "What is the weather?"}],
},
"output": [
{
"role": "model",
"parts": [{"text": "What time is it?"}],
},
],
},
{
"input": {
"role": "user",
"parts": [{"text": "The weather is sunny."}],
},
"output": [
{
"role": "model",
"parts": [{"text": "It is 3 PM."}],
},
],
},
]
# Act
result = _extract_inputs_from_examples(examples)
# Assert
assert len(result) == 2
assert result[0] == "What is the weather?"
assert result[1] == "The weather is sunny."
def test_extract_inputs_from_examples_none_input(self):
"""Test _extract_inputs_from_examples on None as input."""
# Act
result = _extract_inputs_from_examples(None)
# Assert
assert len(result) == 0