parts.go

Overview

The parts.go source file provides the core functionality for converting message content parts between two distinct representations used within the system:

This conversion layer supports various content types including text, file attachments, function calls, function responses, executable code, and code execution results. It preserves semantic metadata such as long-running tool indications and ensures proper encoding/decoding of file bytes.

By handling these conversions, this file enables seamless interoperability between local ADK agents and remote agents communicating over the A2A protocol. It also facilitates the streaming and processing of complex message contents that may include executable code or function calls, crucial for advanced AI workflows.


Detailed Explanation of Functions

ToA2AParts

func ToA2AParts(parts []*genai.Part, longRunningToolIDs []string) ([]a2a.Part, error)

toA2AFilePart

func toA2AFilePart(v *genai.Part) (a2a.FilePart, error)

toA2ADataPart

func toA2ADataPart(part *genai.Part, longRunningToolIDs []string) (a2a.DataPart, error)

ToGenAIParts

func ToGenAIParts(parts []a2a.Part) ([]*genai.Part, error)

toGenAIFilePart

func toGenAIFilePart(part a2a.FilePart) (*genai.Part, error)

toGenAIDataPart

func toGenAIDataPart(part a2a.DataPart) (*genai.Part, error)

toGenAITextPart

func toGenAITextPart(part a2a.DataPart) (*genai.Part, error)

toGenAIContent

func toGenAIContent(msg *a2a.Message) (*genai.Content, error)

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
subgraph GenAI_Parts [genai.Part]
genText[Text Part]
genFileInline[Inline File Data]
genFileURI[File URI Data]
genFuncCall[Function Call]
genFuncResp[Function Response]
genExecCode[Executable Code]
genCodeExecRes[Code Execution Result]
end
subgraph Conversion_Functions
ToA2APartsFunc[ToA2AParts]
toA2AFilePartFunc[toA2AFilePart]
toA2ADataPartFunc[toA2ADataPart]
ToGenAIPartsFunc[ToGenAIParts]
toGenAIFilePartFunc[toGenAIFilePart]
toGenAIDataPartFunc[toGenAIDataPart]
end
subgraph A2A_Parts [a2a.Part]
a2aText[a2a.TextPart]
a2aFile[a2a.FilePart]
a2aData[a2a.DataPart]
end
genText -->|ToA2AParts| ToA2APartsFunc
genFileInline -->|ToA2AParts| ToA2APartsFunc
genFileURI -->|ToA2AParts| ToA2APartsFunc
genFuncCall -->|ToA2AParts| ToA2APartsFunc
genFuncResp -->|ToA2AParts| ToA2APartsFunc
genExecCode -->|ToA2AParts| ToA2APartsFunc
genCodeExecRes -->|ToA2AParts| ToA2APartsFunc
ToA2APartsFunc -->|calls| toA2AFilePartFunc
ToA2APartsFunc -->|calls| toA2ADataPartFunc
toA2AFilePartFunc --> a2aFile
toA2ADataPartFunc --> a2aData
ToA2APartsFunc --> a2aText
a2aText -->|ToGenAIParts| ToGenAIPartsFunc
a2aFile -->|ToGenAIParts| ToGenAIPartsFunc
a2aData -->|ToGenAIParts| ToGenAIPartsFunc
ToGenAIPartsFunc -->|calls| toGenAIFilePartFunc
ToGenAIPartsFunc -->|calls| toGenAIDataPartFunc
toGenAIFilePartFunc --> genFileInline
toGenAIFilePartFunc --> genFileURI
toGenAIDataPartFunc --> genFuncCall
toGenAIDataPartFunc --> genFuncResp
toGenAIDataPartFunc --> genExecCode
toGenAIDataPartFunc --> genCodeExecRes
toGenAIDataPartFunc --> genText

Summary

This file is essential for bridging the internal and external message part representations, enabling the system to:

It operates at the heart of the agent communication stack, enabling flexible remote agent invocation, streaming, and response processing as described in the broader Remote Agent Communication (A2A) topic and the related Event Conversion and Processing subtopic.