|
38 | 38 |
|
39 | 39 |
|
40 | 40 | 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 | + """ |
42 | 55 |
|
43 | 56 | def __init__( |
44 | 57 | self, |
@@ -92,7 +105,22 @@ def create( |
92 | 105 | consumers: list[Consumer] | None = None, |
93 | 106 | interceptors: list[ClientCallInterceptor] | None = None, |
94 | 107 | ) -> 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 | + """ |
96 | 124 | server_set = [card.preferred_transport or TransportProtocol.jsonrpc] |
97 | 125 | if card.additional_interfaces: |
98 | 126 | server_set.extend([x.transport for x in card.additional_interfaces]) |
@@ -131,7 +159,14 @@ def create( |
131 | 159 | def minimal_agent_card( |
132 | 160 | url: str, transports: list[str] | None = None |
133 | 161 | ) -> 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 | + """ |
135 | 170 | if transports is None: |
136 | 171 | transports = [] |
137 | 172 | return AgentCard( |
|
0 commit comments