a2a.client.client_factory module

class a2a.client.client_factory.ClientFactory(config: ClientConfig | None = None)

Bases: object

Factory for creating clients that communicate with A2A agents.

The factory is configured with a ClientConfig and optionally custom transport producers registered via register. Example usage:

factory = ClientFactory(config) # Optionally register custom transport implementations factory.register(‘my_custom_transport’, custom_transport_producer) # Create a client from an AgentCard client = factory.create(card, interceptors) # Or resolve an AgentCard from a URL and create a client client = await factory.create_from_url(’https://example.com’)

The client can be used consistently regardless of the transport. This aligns the client configuration with the server’s capabilities.

create(card: AgentCard, interceptors: list[ClientCallInterceptor] | None = None) Client

Create a new Client for the provided AgentCard.

Parameters:
  • card – An AgentCard defining the characteristics of the agent.

  • interceptors – A list of interceptors to use for each request. These are used for things like attaching credentials or http headers to all outbound requests.

Returns:

A Client object.

Raises:
  • If there is no valid matching of the client configuration with the

  • server configuration, a ValueError is raised.

async create_from_url(url: str, interceptors: list[ClientCallInterceptor] | None = None, relative_card_path: str | None = None, resolver_http_kwargs: dict[str, Any] | None = None, signature_verifier: Callable[[AgentCard], None] | None = None) Client

Create a Client by resolving an AgentCard from a URL.

Resolves the agent card from the given URL using the factory’s configured httpx client, then creates a client via create.

If the agent card is already available, use create directly instead.

Parameters:
  • url – The base URL of the agent. The agent card will be fetched from <url>/.well-known/agent-card.json by default.

  • interceptors – A list of interceptors to use for each request. These are used for things like attaching credentials or http headers to all outbound requests.

  • relative_card_path – The relative path when resolving the agent card. See A2ACardResolver.get_agent_card for details.

  • resolver_http_kwargs – Dictionary of arguments to provide to the httpx client when resolving the agent card.

  • signature_verifier – A callable used to verify the agent card’s signatures.

Returns:

A Client object.

register(label: str, generator: Callable[[AgentCard, str, ClientConfig], ClientTransport]) None

Register a new transport producer for a given transport label.

async a2a.client.client_factory.create_client(agent: str | AgentCard, client_config: ClientConfig | None = None, interceptors: list[ClientCallInterceptor] | None = None, relative_card_path: str | None = None, resolver_http_kwargs: dict[str, Any] | None = None, signature_verifier: Callable[[AgentCard], None] | None = None) Client

Create a Client for an agent from a URL or AgentCard.

Convenience function that constructs a ClientFactory internally. For reusing a factory across multiple agents or registering custom transports, use ClientFactory directly instead.

Parameters:
  • agent – The base URL of the agent, or an AgentCard to use directly.

  • client_config – Optional ClientConfig. A default config is created if not provided.

  • interceptors – A list of interceptors to use for each request.

  • relative_card_path – The relative path when resolving the agent card. Only used when agent is a URL.

  • resolver_http_kwargs – Dictionary of arguments to provide to the httpx client when resolving the agent card.

  • signature_verifier – A callable used to verify the agent card’s signatures.

Returns:

A Client object.

a2a.client.client_factory.minimal_agent_card(url: str, transports: list[str] | None = None) AgentCard

Generates a minimal card to simplify bootstrapping client creation.

This minimal card is not viable itself to interact with the remote agent. Instead this is a shorthand way to take a known url and transport option and interact with the get card endpoint of the agent server to get the correct agent card. This pattern is necessary for gRPC based card access as typically these servers won’t expose a well known path card.