a2a library
Agent-to-Agent (A2A) protocol, executors, converters, and routers.
Provides A2aAgentExecutor, TaskResultAggregator, AgentCardBuilder, and event/part/request converters for inter-agent communication.
import 'package:adk_dart/a2a.dart';
final aggregator = TaskResultAggregator();
Classes
- A2aAgentExecutor
- Executes A2A requests by delegating to an ADK Runner.
- A2aAgentExecutorConfig
- Runtime configuration for A2aAgentExecutor.
- A2aApplication
- In-memory A2A application bundle of card, executor, and task store.
- A2aApplicationLifespan
- Optional lifecycle callbacks for host-managed A2A applications.
- A2aArtifact
- Artifact payload produced by a task.
- A2aCallContext
- Call context metadata sent with A2A requests.
- A2aCardRequestConfig
- Configuration for fetching an A2A agent card.
- A2aClientCallContext
- Mutable call context passed to A2A client transports.
- A2aDataPart
- Part payload carrying JSON-like structured data.
- A2aEvent
- Base type for all A2A stream events.
- A2aEventQueue
- Queue contract used to emit A2A events.
- A2aFile
- Base interface for file payload variants.
- A2aFilePart
- Part payload that wraps an A2aFile.
- A2aFileWithBytes
- File payload embedding bytes (typically base64-encoded).
- A2aFileWithUri
- File payload referencing a URI.
- A2AMessage
- A routed message exchanged between two local agents.
- A2aMessage
- Message envelope used by A2A requests and task history.
- A2aPart
- Wrapper for concrete part payload variants.
- A2aPartRoot
- Base interface for all A2A message parts.
- A2aRequestContext
- Incoming request context supplied to A2A executors.
- A2aSecurityScheme
- Security scheme descriptor for authenticated agent cards.
- A2aTask
- Task container for ongoing or completed A2A work.
- A2aTaskArtifactUpdateEvent
- Event carrying task artifact updates.
- A2aTaskStatus
- Status snapshot for an A2A task.
- A2aTaskStatusUpdateEvent
- Event carrying task status updates.
- A2aTaskStore
- Abstract storage interface for A2A A2aTask records.
- A2aTextPart
- Text part payload.
- A2aUser
- End-user identity attached to a call context.
- AgentCapabilities
- Extensible capability map for agent cards.
- AgentCard
- Agent-card payload exposed over A2A discovery endpoints.
- AgentCardBuilder
- Builds protocol-level AgentCard objects from runtime agents.
- AgentProvider
- Provider information for an agent card.
- AgentRunRequest
- Normalized runner request derived from an A2A request.
- AgentSkill
- Skill descriptor listed in an agent card.
- BoundedA2aTaskStore
-
Task store that serves each task only to the user who created it, drops
terminal tasks after
terminalTaskTtl, and evicts the least recently saved task when more thanmaxTasksare stored. - CardRequestInterceptor
- Interceptor invoked before/after fetching an A2A agent card.
- ErrorRecoveryTracker
- Tracks sub-agent error events and clears them when the enclosing scope subsequently produces a successful final response.
- ExecuteInterceptor
- Interceptor invoked around A2A agent executor event emission.
- ExecutorContext
- Execution context exposed to ExecuteInterceptor callbacks.
- InMemoryA2aEventQueue
- In-memory event queue implementation for A2A flows.
- InMemoryA2ARouter
- Routes A2AMessage payloads between local agent names.
- InMemoryA2aTaskStore
- Simple in-memory A2aTaskStore backed by a Map.
- LongRunningFunctions
- Tracks long-running function calls and matching responses across ADK events.
- ParametersConfig
- Parameters configuration passed through A2A request interceptors.
- RequestInterceptor
- Interceptor invoked before/after sending an A2A message request.
- TaskResultAggregator
- Aggregates task status updates into a single terminal summary.
Enums
- A2aRole
- Message author role in the A2A protocol.
- A2aTaskState
- Task lifecycle states in the A2A protocol.
Constants
- a2aDataPartMetadataIsLongRunningKey → const String
- Metadata key marking long-running tool calls.
- a2aDataPartMetadataTypeCodeExecutionResult → const String
- Metadata type value for code-execution result payloads.
- a2aDataPartMetadataTypeExecutableCode → const String
- Metadata type value for executable-code payloads.
- a2aDataPartMetadataTypeFunctionCall → const String
- Metadata type value for function-call payloads.
- a2aDataPartMetadataTypeFunctionResponse → const String
- Metadata type value for function-response payloads.
- a2aDataPartMetadataTypeKey → const String
- Metadata key for encoded A2A data-part type.
- a2aDataPartMetadataTypeToolCall → const String
- Metadata type value for server-side tool-call payloads.
- a2aDataPartMetadataTypeToolResponse → const String
- Metadata type value for server-side tool-response payloads.
- a2aDataPartTextMimeType → const String
- Mime type used for encoded fallback data-part payloads.
- a2aExperimentalDefaultMessage → const String
- The default warning message for A2A experimental APIs.
- a2aHttpExtensionHeader → const String
- Standard HTTP header used to advertise A2A extensions.
- a2aProtocolVersion → const String
- Current A2A protocol version sent by ADK A2A clients.
- a2aTaskFailedErrorCode → const String
- Error code set on ADK events when a remote A2A task fails.
- a2aTaskFailedErrorMessage → const String
- Fallback error message set on ADK events when a remote A2A task fails without providing status message text.
- a2aVersionHeader → const String
- HTTP header name for the A2A protocol version.
- adkContextIdPrefix → const String
- The fixed prefix used in encoded ADK A2A context identifiers.
- adkContextIdSeparator → const String
- The delimiter used to join context identifier segments.
- adkMetadataKeyPrefix → const String
- The metadata key prefix reserved for ADK-specific fields.
- artifactIdSeparator → const String
- Separator used when composing synthetic artifact IDs.
- defaultA2aMaxTasks → const int
- Default maximum number of tasks retained by BoundedA2aTaskStore.
- defaultA2aTerminalTaskTtl → const Duration
- Default TTL after a task enters a terminal state before eviction.
- defaultErrorMessage → const String
- Default error message used for failed conversion states.
- includeArtifactsInA2aEventInterceptor → const ExecuteInterceptor
-
Built-in ExecuteInterceptor that emits
A2aTaskArtifactUpdateEvents for artifacts recorded inadkEvent.actions.artifactDelta. - mockFunctionCallForRequiredUserAuth → const String
- Synthetic function-call name used to resume non-ADK auth-required events.
- mockFunctionCallForRequiredUserInput → const String
- Synthetic function-call name used to resume non-ADK input-required events.
- newA2aAdkIntegrationExtension → const String
- URI identifying the ADK A2A integration extension.
- newIntegrationExtensionInterceptor → const RequestInterceptor
- Built-in RequestInterceptor that injects the ADK A2A integration extension header.
Properties
-
a2aDataPartEndTag
→ List<
int> -
End tag for encoded fallback data-part payloads.
final
-
a2aDataPartStartTag
→ List<
int> -
Start tag for encoded fallback data-part payloads.
final
Functions
-
a2aExperimental<
T> (T value, {String? message}) → T -
The passthrough
valuemarked as experimental. -
a2aVersionHeaders(
[String version = a2aProtocolVersion]) → Map< String, String> - Returns default HTTP headers advertising the A2A protocol version.
-
artifactEventId(
String artifactId, InvocationContext? invocationContext) → String? -
Returns the deterministic UUIDv5 event ID shared by all chunks of an A2A
artifact update within
invocationContext, ornullwhen unavailable. -
buildA2aRequestLog(
A2aMessage request) → String -
The multi-line debug log payload for an outbound A2A
request. -
buildA2aResponseLog(
Object response) → String -
The multi-line debug log payload for an inbound A2A
response. -
buildMessagePartLog(
A2aPart part) → String -
The summarized log line for an A2A message
part. -
convertA2aArtifactUpdateToEvent(
A2aTaskArtifactUpdateEvent a2aArtifactUpdate, {String? author, InvocationContext? invocationContext, A2APartToGenAIPartConverter partConverter = convertA2aPartToGenaiPart}) → Event - Converts an A2aTaskArtifactUpdateEvent into an ADK Event.
-
convertA2aMessageToEvent(
A2aMessage a2aMessage, {String? author, InvocationContext? invocationContext, A2APartToGenAIPartConverter partConverter = convertA2aPartToGenaiPart}) → Event - Converts an A2aMessage into an ADK Event.
-
convertA2aPartToGenaiPart(
A2aPart a2aPart) → Object? - Converts an A2aPart into one or more GenAI Part payloads.
-
convertA2aRequestToAgentRunRequest(
A2aRequestContext request, {A2APartToGenAIPartConverter partConverter = convertA2aPartToGenaiPart}) → AgentRunRequest - Converts an A2aRequestContext into an AgentRunRequest.
-
convertA2aStatusUpdateToEvent(
A2aTaskStatusUpdateEvent a2aStatusUpdate, {String? author, InvocationContext? invocationContext, A2APartToGenAIPartConverter partConverter = convertA2aPartToGenaiPart}) → Event - Converts an A2aTaskStatusUpdateEvent into an ADK Event.
-
convertA2aTaskToEvent(
A2aTask a2aTask, {String? author, InvocationContext? invocationContext, A2APartToGenAIPartConverter partConverter = convertA2aPartToGenaiPart}) → Event - Converts an A2aTask into an ADK Event.
-
convertEventToA2aEvents(
Event event, InvocationContext invocationContext, {String? taskId, String? contextId, GenAIPartToA2APartConverter partConverter = convertGenaiPartToA2aPart}) → List< A2aEvent> - Converts an ADK Event into one or more A2A events.
-
convertEventToA2aMessage(
Event event, {InvocationContext? invocationContext, A2aRole? role, GenAIPartToA2APartConverter partConverter = convertGenaiPartToA2aPart}) → A2aMessage? - Converts an ADK Event into an A2aMessage, when possible.
-
convertGenaiPartToA2aPart(
Part part) → Object? - Converts a GenAI Part into one or more A2aPart payloads.
-
createArtifactId(
String appName, String userId, String sessionId, String filename, int version) → String - Creates a stable artifact ID from app/session/file/version fields.
-
createMockFunctionCallForRequiredUserInput(
A2aTaskState state, List< Part> outputParts, Set<String> longRunningFunctionIds) → (List<Part> , Set<String> ) -
Replaces the last text or
<a2a_datapart_json>part with a synthetic long-running function call when a non-ADK A2A peer reports input/auth required without an ADK tool id. -
fromA2aContextId(
String? contextId) → (String?, String?, String?) -
The parsed
(appName, userId, sessionId)tuple fromcontextId. -
getAdkMetadataKey(
String key) → String -
The ADK-scoped metadata key for
key. -
handleUserInput(
A2aRequestContext context) → A2aTaskStatusUpdateEvent? - Processes user input events, validating function responses when the task is awaiting input or authentication.
-
isFailedStatus(
A2aTaskStatus? status) → bool -
Returns true when
statusrepresents a failed A2A task state. -
markA2aTaskFailedEvent(
Event event) → Event -
Marks
eventwith a2aTaskFailedErrorCode and a fallback error message when a remote A2A task or status update is in a failed state. -
reportA2aExecutorError(
Object error, [StackTrace? stackTrace, bool? debugErrorsOverride]) → String -
Logs an uncaught executor
errorwith a correlation ID and returns a sanitized failure message for remote A2A peers. -
toA2a(
BaseAgent agent, {String host = 'localhost', int port = 8000, String protocol = 'http', String rpcPath = '', Object? agentCard, Runner? runner, Map< String, A2aTask> ? taskStore, A2aTaskStore? a2aTaskStore, Object agentExecutorFactory(Runner runner)?, Map<String, A2aSecurityScheme> ? securitySchemes, List<Map< ? defaultSkillSecurity, A2aApplicationLifespan? lifespan}) → Future<String, List< >String> >A2aApplication> -
The A2A application wrapper for
agent. -
toA2aContextId(
String appName, String userId, String sessionId) → String -
The encoded A2A context identifier for
appName,userId, andsessionId.
Typedefs
- A2aExecuteInterceptor = ExecuteInterceptor
- Alias for ExecuteInterceptor used by A2aAgentExecutorConfig.
-
A2aExecutorAfterAgentInterceptor
= FutureOr<
A2aTaskStatusUpdateEvent> Function(ExecutorContext executorContext, A2aTaskStatusUpdateEvent finalEvent) - Hook executed before emitting the final status update event.
-
A2aExecutorAfterEventInterceptor
= FutureOr<
Object?> Function(ExecutorContext executorContext, A2aEvent a2aEvent, Event adkEvent) - Hook executed after each ADK event is converted to an A2A event.
-
A2aExecutorBeforeAgentInterceptor
= FutureOr<
A2aRequestContext> Function(A2aRequestContext context) - Hook executed before A2A requests are converted and run.
- A2aExecutorContext = ExecutorContext
- Alias for ExecutorContext used by A2aAgentExecutorConfig.
- A2APartToGenAIPartConverter = Object? Function(A2aPart a2aPart)
- Converter signature from A2aPart to GenAI part unions.
- A2ARequestToAgentRunRequestConverter = AgentRunRequest Function(A2aRequestContext request, A2APartToGenAIPartConverter partConverter)
- Converter signature from A2aRequestContext to AgentRunRequest.
-
AdkEventToA2AEventsConverter
= List<
A2aEvent> Function(Event event, InvocationContext invocationContext, String? taskId, String? contextId, GenAIPartToA2APartConverter partConverter) - Converter signature from ADK Event to A2A event batches.
- GenAIPartToA2APartConverter = Object? Function(Part part)
- Converter signature from GenAI Part to A2A part unions.