Event Conversion and Processing

Purpose

Within the broader scope of the Remote Agent Communication (A2A) topic, the Event Conversion and Processing subtopic addresses the critical need to translate and manage event data exchanged between the ADK session model and the A2A protocol model. This subtopic solves two main problems:

This functionality is essential to support distributed multi-agent workflows where agents interact remotely, translate complex event data structures, and maintain task status consistency.

Functionality

Conversion Between ADK Session Events and A2A Events

This subtopic provides bidirectional conversion functions that map between the ADK session.Event and A2A a2a.Event types. This includes:

The conversion ensures that semantic information (e.g., which function calls are long-running) is preserved using metadata keys, enabling correct handling downstream.

Processing Event Streams for Task Status

The eventProcessor type encapsulates logic to process a sequence of ADK session events, typically generated as an agent executes and produces incremental output. Key features include:

This processing enables the system to generate consistent A2A task status updates from incremental ADK session events, supporting smooth remote agent interactions and task lifecycle management.

Integration

Code Interaction Highlights

// Converts an ADK session event to an A2A message.
func EventToMessage(event *session.Event) (*a2a.Message, error) {
    parts, err := ToA2AParts(event.Content.Parts, event.LongRunningToolIDs)
    if err != nil {
        return nil, err
    }
    var role a2a.MessageRole
    if event.Author == "user" {
        role = a2a.MessageRoleUser
    } else {
        role = a2a.MessageRoleAgent
    }
    msg := a2a.NewMessage(role, parts...)
    msg.Metadata = setActionsMeta(msg.Metadata, event.Actions)
    return msg, nil
}
func (p *eventProcessor) process(_ context.Context, event *session.Event) (*a2a.TaskArtifactUpdateEvent, error) {
    p.updateTerminalActions(event)
    resp := event.LLMResponse
    if resp.ErrorCode != "" {
        // Mark failure and prepare terminal event
        ...
    }
    if resp.Content == nil || len(resp.Content.Parts) == 0 {
        return nil, nil
    }
    if isInputRequired(event, resp.Content.Parts) {
        // Handle long-running tool input requirement
        ...
    }
    parts, err := ToA2AParts(resp.Content.Parts, event.LongRunningToolIDs)
    ...
    return a2a.NewArtifactEventOrUpdate(p.reqCtx, p.responseID, parts...), nil
}

Diagram

sequenceDiagram
participant ADK as ADK Session
participant EP as EventProcessor
participant A2A as A2A Protocol
ADK->>EP: session.Event stream (includes LLMResponse, actions)
EP->>A2A: Convert to a2a.TaskArtifactUpdateEvent
EP->>EP: Track terminalActions (escalate, transfer)
EP->>A2A: Emit terminal a2a.TaskStatusUpdateEvent when complete
A2A->>EP: Incoming a2a.Event (Task, Message, ArtifactUpdate)
EP->>ADK: Convert to session.Event with custom metadata

This diagram illustrates the bidirectional flow where session events from the ADK are processed and converted into A2A events for remote communication, and incoming A2A events are translated back into session events for local consumption.


The Event Conversion and Processing subtopic thus forms the essential bridge and event stream manager within the distributed agent communication infrastructure, ensuring coherent and interoperable task status representation across the ADK and A2A layers. It complements other subtopics like A2A Agent Implementation by providing the translation and event flow logic necessary for remote agent interactions.