Implementation:A2aproject A2a java ClientConfig
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Client, Configuration |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete immutable configuration class controlling A2A client behavior including streaming mode, polling, transport preference, output modes, conversation history, and push notifications.
Description
`ClientConfig` defines how a `Client` communicates with agents. It is constructed via the `Builder` pattern and is immutable and thread-safe — multiple clients can share the same configuration instance.
Key configuration options:
- Streaming (default: `true`): Enables real-time event streaming. Actual streaming requires both this flag AND `AgentCapabilities.streaming()` to be `true`.
- Polling (default: `false`): When enabled, the client can poll for task updates instead of blocking or streaming. Sets `returnImmediately` in `MessageSendConfiguration`.
- useClientPreference (default: `false`): When `true`, the client's transport registration order takes priority over the server's preferred transport order.
- acceptedOutputModes (default: empty): Restricts which content types the client accepts (text, audio, image, etc.).
- historyLength (default: `null`): Number of previous messages to include as context.
- taskPushNotificationConfig (default: `null`): Default webhook configuration for all sendMessage calls.
- metadata (default: empty): Custom metadata attached to every request.
Usage
- Enable streaming: `new ClientConfig.Builder().setStreaming(true).build()`
- Client transport preference: `setUseClientPreference(true)` to prioritize client's transport order
- Conversation context: `setHistoryLength(10)` to include last 10 messages
- Push notifications: `setTaskPushNotificationConfig(config)` for webhook-based updates
Code Reference
Source Location
- Repository: a2a-java
- File: `client/base/src/main/java/org/a2aproject/sdk/client/config/ClientConfig.java`
- Lines: L140-411
Signature
public class ClientConfig {
// Getters
public boolean isStreaming();
public boolean isPolling();
public boolean isUseClientPreference();
public List<String> getAcceptedOutputModes();
public @Nullable TaskPushNotificationConfig getTaskPushNotificationConfig();
public @Nullable Integer getHistoryLength();
public Map<String, Object> getMetadata();
public static Builder builder();
public static class Builder {
public Builder setStreaming(@Nullable Boolean streaming);
public Builder setPolling(@Nullable Boolean polling);
public Builder setUseClientPreference(@Nullable Boolean useClientPreference);
public Builder setAcceptedOutputModes(List<String> acceptedOutputModes);
public Builder setTaskPushNotificationConfig(TaskPushNotificationConfig taskPushNotificationConfig);
public Builder setHistoryLength(Integer historyLength);
public Builder setMetadata(Map<String, Object> metadata);
public ClientConfig build();
}
}
Import
import org.a2aproject.sdk.client.config.ClientConfig;
I/O Contract
Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| streaming | Boolean | No | true | Enable streaming mode |
| polling | Boolean | No | false | Use polling instead of blocking |
| useClientPreference | Boolean | No | false | Client vs server transport priority |
| acceptedOutputModes | List<String> | No | empty | Accepted content types |
| taskPushNotificationConfig | TaskPushNotificationConfig | No | null | Default webhook config |
| historyLength | Integer | No | null | Previous messages as context |
| metadata | Map<String, Object> | No | empty | Custom metadata for all requests |
Outputs
| Name | Type | Description |
|---|---|---|
| build() returns | ClientConfig | Immutable, thread-safe configuration |
Usage Examples
Streaming Configuration
ClientConfig config = new ClientConfig.Builder()
.setStreaming(true)
.build();
Client client = Client.builder(card)
.clientConfig(config)
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder())
.addConsumer((event, c) -> { /* handle events */ })
.build();
Client Transport Preference
ClientConfig config = new ClientConfig.Builder()
.setUseClientPreference(true)
.build();
Client client = Client.builder(card)
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder())
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder())
.clientConfig(config) // Tries gRPC first, then JSON-RPC
.build();
Complete Configuration
ClientConfig config = new ClientConfig.Builder()
.setStreaming(true)
.setUseClientPreference(true)
.setAcceptedOutputModes(List.of("text"))
.setHistoryLength(5)
.setMetadata(Map.of("userId", "user-123"))
.build();
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment