agentscope.a2a

The A2A related modules.

class AgentCardResolverBase[source]

Bases: object

Base class for A2A agent card resolvers, responsible for fetching agent cards from various sources. Implementations must provide the get_agent_card method to retrieve the agent card.

abstract async get_agent_card(*args, **kwargs)[source]

Get Agent Card from the configured source.

Returns:

The resolved agent card object.

Return type:

AgentCard

Parameters:
  • args (Any)

  • kwargs (Any)

class FileAgentCardResolver[source]

Bases: AgentCardResolverBase

Agent card resolver that loads AgentCard from a JSON file.

The JSON file should contain an AgentCard object with the following required fields:

  • name (str): The name of the agent

  • url (str): The URL of the agent

  • version (str): The version of the agent

  • capabilities (dict): The capabilities of the agent

  • default_input_modes (list[str]): Default input modes

  • default_output_modes (list[str]): Default output modes

  • skills (list): List of agent skills

Example JSON file content:

{
    "name": "RemoteAgent",
    "url": "http://localhost:8000",
    "description": "A remote A2A agent",
    "version": "1.0.0",
    "capabilities": {},
    "default_input_modes": ["text/plain"],
    "default_output_modes": ["text/plain"],
    "skills": []
}
__init__(file_path)[source]

Initialize the FileAgentCardResolver with the path to the JSON file.

Parameters:

file_path (str) – The path to the JSON file containing the agent card.

Return type:

None

async get_agent_card()[source]

Get the agent card from the JSON file.

Returns:

The agent card loaded from the file.

Return type:

AgentCard

class WellKnownAgentCardResolver[source]

Bases: AgentCardResolverBase

Agent card resolver that loads AgentCard from a well-known URL.

__init__(base_url, agent_card_path=None)[source]

Initialize the WellKnownAgentCardResolver.

Parameters:
  • base_url (str) – The base URL to resolve the agent card from.

  • agent_card_path (str | None, optional) – The path to the agent card relative to the base URL. Defaults to AGENT_CARD_WELL_KNOWN_PATH from a2a.utils.

Return type:

None

async get_agent_card()[source]

Get the agent card from the well-known URL.

Returns:

The agent card loaded from the URL.

Return type:

AgentCard

class NacosAgentCardResolver[source]

Bases: AgentCardResolverBase

Nacos-based A2A Agent Card resolver.

Nacos is a dynamic service discovery, configuration and service management platform for building cloud native applications. This resolver fetches the agent card from a Nacos server and subscribes to updates.

__init__(remote_agent_name, nacos_client_config, version=None)[source]

Initialize the nacos agent card resolver.

Parameters:
  • remote_agent_name (str) – Name of the remote agent in Nacos.

  • nacos_client_config (ClientConfig | None, optional) – Nacos client configuration, where a server_addresses parameter is required.

  • version (str | None, optional) – Version of the agent card to fetch. If None, fetches the latest version. This version is also used when subscribing to agent card updates. Defaults to None (latest version).

Return type:

None

async get_agent_card()[source]

Get agent card from Nacos with lazy initialization.

Returns:

The resolved agent card from Nacos.

Return type:

AgentCard