Class ClientConfig
ClientConfig defines how the client communicates with agents, including streaming mode,
transport preference, output modes, and request metadata. The configuration is immutable
and constructed using the ClientConfig.Builder pattern.
Key configuration options:
- Streaming: Enable/disable real-time event streaming (default: true)
- Polling: Use polling instead of blocking for updates (default: false)
- Transport preference: Client vs server transport priority (default: server preference)
- Output modes: Acceptable content types (text, audio, image, etc.)
- History length: Number of previous messages to include as context
- Push notifications: Default webhook configuration for task updates
- Metadata: Custom metadata attached to all requests
Streaming mode: Controls whether the client uses streaming or blocking communication. Streaming mode requires both the client configuration AND the agent's capabilities to support it:
// Enable streaming (if agent also supports it)
ClientConfig config = new ClientConfig.Builder()
.setStreaming(true)
.build();
// Actual mode = config.streaming && agentCard.capabilities().streaming()
When streaming is enabled and supported, the client receives events asynchronously as the
agent processes the request. When disabled, the client blocks until the task completes.
Transport preference: Controls which transport protocol is selected when multiple options are available:
// Default: Use server's preferred transport (first in AgentCard.supportedInterfaces)
ClientConfig serverPref = new ClientConfig.Builder()
.setUseClientPreference(false)
.build();
// Use client's preferred transport (order of withTransport() calls)
ClientConfig clientPref = new ClientConfig.Builder()
.setUseClientPreference(true)
.build();
Client client = Client.builder(card)
.withTransport(GrpcTransport.class, grpcConfig) // Client preference 1
.withTransport(JSONRPCTransport.class, jsonConfig) // Client preference 2
.clientConfig(clientPref)
.build();
// With useClientPreference=true, tries gRPC first, then JSON-RPC
// With useClientPreference=false, uses server's order from AgentCard
Output modes: Specify which content types the client can handle:
ClientConfig config = new ClientConfig.Builder()
.setAcceptedOutputModes(List.of("text", "image", "audio"))
.build();
// Agent will only return text, image, or audio content
Conversation history: Request previous messages as context:
ClientConfig config = new ClientConfig.Builder()
.setHistoryLength(10) // Include last 10 messages
.build();
This is useful for maintaining conversation context across multiple requests in the same session.
Push notifications: Configure default webhook for all task updates:
TaskPushNotificationConfig pushConfig = TaskPushNotificationConfig.builder()
.id("config-1")
.url("https://my-app.com/webhooks/tasks")
.authentication(new AuthenticationInfo("bearer", "my-token"))
.build();
ClientConfig config = new ClientConfig.Builder()
.setTaskPushNotificationConfig(pushConfig)
.build();
// All sendMessage() calls will use this webhook config
Custom metadata: Attach metadata to all requests:
Map<String, Object> metadata = Map.of(
"userId", "user-123",
"sessionId", "session-456",
"clientVersion", "1.0.0"
);
ClientConfig config = new ClientConfig.Builder()
.setMetadata(metadata)
.build();
// Metadata is included in every message sent
Complete example:
ClientConfig config = new ClientConfig.Builder()
.setStreaming(true) // Enable streaming
.setUseClientPreference(true) // Use client transport order
.setAcceptedOutputModes(List.of("text")) // Text responses only
.setHistoryLength(5) // Last 5 messages as context
.setMetadata(Map.of("userId", "user-123")) // Custom metadata
.build();
Client client = Client.builder(agentCard)
.clientConfig(config)
.withTransport(JSONRPCTransport.class, transportConfig)
.build();
Default values:
- streaming:
true - polling:
false - useClientPreference:
false(server preference) - acceptedOutputModes: empty list (accept all)
- historyLength:
null(no history) - taskPushNotificationConfig:
null(no push notifications) - metadata: empty map
Thread safety: ClientConfig is immutable and thread-safe. Multiple clients can share the same configuration instance.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic ClientConfig.Builderbuilder()Create a new builder for constructing ClientConfig instances.Get the list of accepted output modes.@Nullable IntegerGet the conversation history length.Get the custom metadata attached to all requests.@Nullable TaskPushNotificationConfigGet the default push notification configuration.booleanCheck if polling mode is enabled for task updates.booleanCheck if streaming mode is enabled.booleanCheck if client transport preference is enabled.
-
Method Details
-
isStreaming
public boolean isStreaming()Check if streaming mode is enabled.Note: Actual streaming requires both this configuration AND agent support (
AgentCapabilities.streaming()).- Returns:
trueif streaming is enabled (default)
-
isPolling
public boolean isPolling()Check if polling mode is enabled for task updates.When polling is enabled, the client can poll for task status updates instead of blocking or streaming. This is useful for asynchronous workflows where the client doesn't need immediate results.
- Returns:
trueif polling is enabled,falseby default
-
isUseClientPreference
public boolean isUseClientPreference()Check if client transport preference is enabled.When
true, the client iterates through its configured transports (in the order they were added viaClientBuilder.withTransport(java.lang.Class<T>, org.a2aproject.sdk.client.transport.spi.ClientTransportConfigBuilder<? extends org.a2aproject.sdk.client.transport.spi.ClientTransportConfig<T>, ?>)) and selects the first one the agent supports.When
false(default), the agent's preferred transport is used (first entry inAgentCard.supportedInterfaces()).- Returns:
trueif using client preference,falsefor server preference (default)
-
getAcceptedOutputModes
Get the list of accepted output modes.This list specifies which content types the client can handle (e.g., "text", "audio", "image", "video"). An empty list means all modes are accepted.
The agent will only return content in the specified modes. For example, if only "text" is specified, the agent won't return images or audio.
- Returns:
- the list of accepted output modes (never null, but may be empty)
-
getTaskPushNotificationConfig
Get the default push notification configuration.If set, this webhook configuration will be used for all sendMessage calls unless overridden with a different configuration.
- Returns:
- the push notification config, or
nullif not configured - See Also:
-
getHistoryLength
Get the conversation history length.This value specifies how many previous messages should be included as context when sending a new message. For example, a value of 10 means the agent receives the last 10 messages in the conversation for context.
- Returns:
- the history length, or
nullif not configured (no history)
-
getMetadata
Get the custom metadata attached to all requests.This metadata is included in every message sent by the client. It can contain user IDs, session identifiers, client version, or any other custom data.
- Returns:
- the metadata map (never null, but may be empty)
-
builder
Create a new builder for constructing ClientConfig instances.- Returns:
- a new builder
-