Skip to content
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
7 changes: 6 additions & 1 deletion src/a2a/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
ClientEvent,
Consumer,
)
from a2a.client.client_factory import ClientFactory, minimal_agent_card
from a2a.client.client_factory import (
A2AClientFactory,
ClientFactory,
minimal_agent_card,
)
from a2a.client.errors import (
A2AClientError,
A2AClientTimeoutError,
Expand All @@ -32,6 +36,7 @@
__all__ = [
'A2ACardResolver',
'A2AClientError',
'A2AClientFactory',
'A2AClientTimeoutError',
'AgentCardResolutionError',
'AuthInterceptor',
Expand Down
23 changes: 13 additions & 10 deletions src/a2a/client/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
]


class ClientFactory:
"""ClientFactory is used to generate the appropriate client for the agent.
class A2AClientFactory:
"""A2AClientFactory is used to generate the appropriate client for the agent.

The factory is configured with a `ClientConfig` and optionally a list of
`Consumer`s to use for all generated `Client`s. The expected use is:

.. code-block:: python

factory = ClientFactory(config, consumers)
factory = A2AClientFactory(config, consumers)
# Optionally register custom client implementations
factory.register('my_customer_transport', NewCustomTransportClient)
# Then with an agent card make a client with additional consumers and
Expand Down Expand Up @@ -101,7 +101,7 @@ def jsonrpc_transport_producer(
url: str,
config: ClientConfig,
) -> ClientTransport:
interface = ClientFactory._find_best_interface(
interface = A2AClientFactory._find_best_interface(
list(card.supported_interfaces),
protocol_bindings=[TransportProtocol.JSONRPC],
url=url,
Expand Down Expand Up @@ -140,7 +140,7 @@ def rest_transport_producer(
url: str,
config: ClientConfig,
) -> ClientTransport:
interface = ClientFactory._find_best_interface(
interface = A2AClientFactory._find_best_interface(
list(card.supported_interfaces),
protocol_bindings=[TransportProtocol.HTTP_JSON],
url=url,
Expand Down Expand Up @@ -186,7 +186,7 @@ def grpc_transport_producer(
) -> ClientTransport:
# The interface has already been selected and passed as `url`.
# We determine its version to use the appropriate transport implementation.
interface = ClientFactory._find_best_interface(
interface = A2AClientFactory._find_best_interface(
list(card.supported_interfaces),
protocol_bindings=[TransportProtocol.GRPC],
url=url,
Expand Down Expand Up @@ -278,13 +278,13 @@ async def connect( # noqa: PLR0913

Constructs a client that connects to the specified agent. Note that
creating multiple clients via this method is less efficient than
constructing an instance of ClientFactory and reusing that.
constructing an instance of A2AClientFactory and reusing that.

.. code-block:: python

# This will search for an AgentCard at /.well-known/agent-card.json
my_agent_url = 'https://travel.agents.example.com'
client = await ClientFactory.connect(my_agent_url)
client = await A2AClientFactory.connect(my_agent_url)


Args:
Expand Down Expand Up @@ -364,7 +364,7 @@ def create(
selected_interface = None
if self._config.use_client_preference:
for protocol_binding in client_set:
selected_interface = ClientFactory._find_best_interface(
selected_interface = A2AClientFactory._find_best_interface(
list(card.supported_interfaces),
protocol_bindings=[protocol_binding],
)
Expand All @@ -375,7 +375,7 @@ def create(
for supported_interface in card.supported_interfaces:
if supported_interface.protocol_binding in client_set:
transport_protocol = supported_interface.protocol_binding
selected_interface = ClientFactory._find_best_interface(
selected_interface = A2AClientFactory._find_best_interface(
list(card.supported_interfaces),
protocol_bindings=[transport_protocol],
)
Expand Down Expand Up @@ -432,3 +432,6 @@ def minimal_agent_card(
version='',
name='',
)


ClientFactory = A2AClientFactory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

While this alias is great for backward compatibility, it's a good practice to plan for its eventual deprecation to encourage users to adopt the new A2AClientFactory name. Adding a TODO comment here can help track this for the future.

Suggested change
ClientFactory = A2AClientFactory
ClientFactory = A2AClientFactory # TODO: Deprecate in favor of A2AClientFactory

Loading