Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions python/packages/a2a/agent_framework_a2a/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ def __init__(
"""Initialize the A2AAgent.

Keyword Args:
name: The name of the agent.
name: The name of the agent. Defaults to agent_card.name if agent_card is provided.
id: The unique identifier for the agent, will be created automatically if not provided.
description: A brief description of the agent's purpose.
description: A brief description of the agent's purpose. Defaults to agent_card.description
if agent_card is provided.
agent_card: The agent card for the agent.
url: The URL for the A2A server.
client: The A2A client for the agent.
Expand All @@ -127,6 +128,11 @@ def __init__(
10.0s write, 5.0s pool - optimized for A2A operations).
kwargs: any additional properties, passed to BaseAgent.
"""
# Default name/description from agent_card when not explicitly provided
if agent_card is not None:
name = name or agent_card.name
description = description or agent_card.description
Comment thread
giles17 marked this conversation as resolved.
Outdated

super().__init__(id=id, name=name, description=description, **kwargs)
self._http_client: httpx.AsyncClient | None = http_client
self._timeout_config = self._create_timeout_config(timeout)
Expand Down
32 changes: 32 additions & 0 deletions python/packages/a2a/tests/test_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,36 @@ def test_a2a_agent_initialization_with_client(mock_a2a_client: MockA2AClient) ->
assert agent.client == mock_a2a_client


def test_a2a_agent_defaults_name_description_from_agent_card(mock_a2a_client: MockA2AClient) -> None:
"""Test A2AAgent defaults name and description from agent_card when not explicitly provided."""
mock_card = MagicMock(spec=AgentCard)
mock_card.name = "Card Agent Name"
mock_card.description = "Card agent description"

agent = A2AAgent(agent_card=mock_card, client=mock_a2a_client, http_client=None)

assert agent.name == "Card Agent Name"
assert agent.description == "Card agent description"


def test_a2a_agent_explicit_name_description_overrides_agent_card(mock_a2a_client: MockA2AClient) -> None:
"""Test that explicit name/description take precedence over agent_card values."""
mock_card = MagicMock(spec=AgentCard)
mock_card.name = "Card Agent Name"
mock_card.description = "Card agent description"

agent = A2AAgent(
name="Explicit Name",
description="Explicit description",
agent_card=mock_card,
client=mock_a2a_client,
http_client=None,
)

assert agent.name == "Explicit Name"
assert agent.description == "Explicit description"


def test_a2a_agent_initialization_without_client_raises_error() -> None:
"""Test A2AAgent initialization without client or URL raises ValueError."""
with raises(ValueError, match="Either agent_card or url must be provided"):
Expand Down Expand Up @@ -561,6 +591,8 @@ def test_transport_negotiation_both_fail() -> None:
# Create a mock agent card
mock_agent_card = MagicMock(spec=AgentCard)
mock_agent_card.url = "http://test-agent.example.com"
mock_agent_card.name = "Test Agent"
mock_agent_card.description = "A test agent"

# Mock the factory to simulate both primary and fallback failures
mock_factory = MagicMock()
Expand Down
Loading