Skip to content

Commit b32b0da

Browse files
committed
Restore some comments gemini mysteriously deleted
1 parent d057808 commit b32b0da

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

src/a2a/client/client_factory.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@
3838

3939

4040
class ClientFactory:
41-
"""ClientFactory is used to generate the appropriate client for the agent."""
41+
"""ClientFactory is used to generate the appropriate client for the agent.
42+
43+
The factory is configured with a `ClientConfig` and optionally a list of
44+
`Consumer`s to use for all generated `Client`s. The expected use is:
45+
46+
factory = ClientFactory(config, consumers)
47+
# Optionally register custom client implementations
48+
factory.register('my_customer_transport', NewCustomTransportClient)
49+
# Then with an agent card make a client with additional consumers and
50+
# interceptors
51+
client = factory.create(card, additional_consumers, interceptors)
52+
# Now the client can be used the same regardless of transport and
53+
# aligns client config with server capabilities.
54+
"""
4255

4356
def __init__(
4457
self,
@@ -92,7 +105,22 @@ def create(
92105
consumers: list[Consumer] | None = None,
93106
interceptors: list[ClientCallInterceptor] | None = None,
94107
) -> Client:
95-
"""Create a new `Client` for the provided `AgentCard`."""
108+
"""Create a new `Client` for the provided `AgentCard`.
109+
110+
Args:
111+
card: An `AgentCard` defining the characteristics of the agent.
112+
consumers: A list of `Consumer` methods to pass responses to.
113+
interceptors: A list of interceptors to use for each request. These
114+
are used for things like attaching credentials or http headers
115+
to all outbound requests.
116+
117+
Returns:
118+
A `Client` object.
119+
120+
Raises:
121+
If there is no valid matching of the client configuration with the
122+
server configuration, a `ValueError` is raised.
123+
"""
96124
server_set = [card.preferred_transport or TransportProtocol.jsonrpc]
97125
if card.additional_interfaces:
98126
server_set.extend([x.transport for x in card.additional_interfaces])
@@ -131,7 +159,14 @@ def create(
131159
def minimal_agent_card(
132160
url: str, transports: list[str] | None = None
133161
) -> AgentCard:
134-
"""Generates a minimal card to simplify bootstrapping client creation."""
162+
"""Generates a minimal card to simplify bootstrapping client creation.
163+
164+
This minimal card is not viable itself to interact with the remote agent.
165+
Instead this is a short hand way to take a known url and transport option
166+
and interact with the get card endpoint of the agent server to get the
167+
correct agent card. This pattern is necessary for gRPC based card access
168+
as typically these servers won't expose a well known path card.
169+
"""
135170
if transports is None:
136171
transports = []
137172
return AgentCard(

0 commit comments

Comments
 (0)