Skip to content

fix: new agent card #2623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/google/adk/cli/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,17 @@ async def _get_a2a_runner_async() -> Runner:
return _get_a2a_runner_async

for p in base_path.iterdir():
# only folders with an agent.json file representing agent card are valid
# only folders with an agent-card.json or agent.json file representing agent card are valid
# a2a agents
if (
p.is_file()
or p.name.startswith((".", "__pycache__"))
or not (p / "agent.json").is_file()
):
if p.is_file() or p.name.startswith(('.', '__pycache__')):
continue

json_file = p / 'agent-card.json'
if not json_file.is_file():
json_file = p / 'agent.json'
if not json_file.is_file():
continue

app_name = p.name
logger.info("Setting up A2A agent: %s", app_name)

Expand All @@ -359,8 +361,7 @@ async def _get_a2a_runner_async() -> Runner:
request_handler = DefaultRequestHandler(
agent_executor=agent_executor, task_store=a2a_task_store
)

with (p / "agent.json").open("r", encoding="utf-8") as f:
with json_file.open("r", encoding="utf-8") as f:
data = json.load(f)
agent_card = AgentCard(**data)

Expand Down
30 changes: 18 additions & 12 deletions tests/unittests/agents/test_remote_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,29 @@ def test_init_with_agent_card_object(self):
def test_init_with_url_string(self):
"""Test initialization with URL string."""
agent = RemoteA2aAgent(
name="test_agent", agent_card="https://example.com/agent.json"
name="test_agent", agent_card="https://example.com/agent-card.json"
)

assert agent.name == "test_agent"
assert agent._agent_card is None
assert agent._agent_card_source == "https://example.com/agent.json"
assert agent._agent_card_source == "https://example.com/agent-card.json"

def test_init_with_file_path(self):
"""Test initialization with file path."""
agent = RemoteA2aAgent(name="test_agent", agent_card="/path/to/agent.json")
agent = RemoteA2aAgent(
name="test_agent", agent_card="/path/to/agent-card.json"
)

assert agent.name == "test_agent"
assert agent._agent_card is None
assert agent._agent_card_source == "/path/to/agent.json"
assert agent._agent_card_source == "/path/to/agent-card.json"

def test_init_with_shared_httpx_client(self):
"""Test initialization with shared httpx client."""
httpx_client = httpx.AsyncClient()
agent = RemoteA2aAgent(
name="test_agent",
agent_card="https://example.com/agent.json",
agent_card="https://example.com/agent-card.json",
httpx_client=httpx_client,
)

Expand All @@ -158,7 +160,7 @@ def test_init_with_custom_timeout(self):
"""Test initialization with custom timeout."""
agent = RemoteA2aAgent(
name="test_agent",
agent_card="https://example.com/agent.json",
agent_card="https://example.com/agent-card.json",
timeout=300.0,
)

Expand Down Expand Up @@ -219,7 +221,7 @@ async def test_ensure_httpx_client_reuses_existing_client(self):
async def test_resolve_agent_card_from_url_success(self):
"""Test successful agent card resolution from URL."""
agent = RemoteA2aAgent(
name="test_agent", agent_card="https://example.com/agent.json"
name="test_agent", agent_card="https://example.com/agent-card.json"
)

with patch.object(agent, "_ensure_httpx_client") as mock_ensure_client:
Expand All @@ -234,15 +236,15 @@ async def test_resolve_agent_card_from_url_success(self):
mock_resolver_class.return_value = mock_resolver

result = await agent._resolve_agent_card_from_url(
"https://example.com/agent.json"
"https://example.com/agent-card.json"
)

assert result == self.agent_card
mock_resolver_class.assert_called_once_with(
httpx_client=mock_client, base_url="https://example.com"
)
mock_resolver.get_agent_card.assert_called_once_with(
relative_card_path="/agent.json"
relative_card_path="/agent-card.json"
)

@pytest.mark.asyncio
Expand All @@ -256,7 +258,9 @@ async def test_resolve_agent_card_from_url_invalid_url(self):
@pytest.mark.asyncio
async def test_resolve_agent_card_from_file_success(self):
"""Test successful agent card resolution from file."""
agent = RemoteA2aAgent(name="test_agent", agent_card="/path/to/agent.json")
agent = RemoteA2aAgent(
name="test_agent", agent_card="/path/to/agent-card.json"
)

with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
Expand Down Expand Up @@ -286,7 +290,9 @@ async def test_resolve_agent_card_from_file_not_found(self):
@pytest.mark.asyncio
async def test_resolve_agent_card_from_file_invalid_json(self):
"""Test agent card resolution from file with invalid JSON raises error."""
agent = RemoteA2aAgent(name="test_agent", agent_card="/path/to/agent.json")
agent = RemoteA2aAgent(
name="test_agent", agent_card="/path/to/agent-card.json"
)

with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
Expand Down Expand Up @@ -393,7 +399,7 @@ async def test_ensure_resolved_with_direct_agent_card(self):
async def test_ensure_resolved_with_url_source(self):
"""Test _ensure_resolved with URL source."""
agent = RemoteA2aAgent(
name="test_agent", agent_card="https://example.com/agent.json"
name="test_agent", agent_card="https://example.com/agent-card.json"
)

agent_card = create_test_agent_card()
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/cli/test_fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def temp_agents_dir_with_a2a():
agent_dir = Path(temp_dir) / "test_a2a_agent"
agent_dir.mkdir()

# Create agent.json file
# Create agent-card.json file
agent_card = {
"name": "test_a2a_agent",
"description": "Test A2A agent",
Expand All @@ -509,7 +509,7 @@ def temp_agents_dir_with_a2a():
"capabilities": ["text"],
}

with open(agent_dir / "agent.json", "w") as f:
with open(agent_dir / "agent-card.json", "w") as f:
json.dump(agent_card, f)

# Create a simple agent.py file
Expand Down