adka2a

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package adka2a allows to expose ADK agents via A2A.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAgentSkills

func BuildAgentSkills(agent agent.Agent) []a2a.AgentSkill

BuildAgentSkills attempts to create a list of [a2a.AgentSkill]s based on agent descriptions and types. This information can be used in a2a.AgentCard to help clients understand agent capabilities.

func EventToMessage

func EventToMessage(event *session.Event) (*a2a.Message, error)

EventToMessage converts the provided session event to A2A message.

func GetA2ATaskInfo

func GetA2ATaskInfo(event *session.Event) (a2a.TaskID, string)

GetA2ATaskInfo returns A2A task and context IDs if they are present in session event custom metadata.

func NewRemoteAgentEvent

func NewRemoteAgentEvent(ctx agent.InvocationContext) *session.Event

NewRemoteAgentEvent create a new Event authored by the agent running in the provided invocation context.

func ToA2AMetaKey

func ToA2AMetaKey(key string) string

ToA2AMetaKey adds a prefix used to differentiage ADK-related values stored in Metadata an A2A event.

func ToA2APart

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

ToA2APart converts the provided genai part to A2A equivalent. Long running tool IDs are used for attaching metadata to the relevant data parts.

func ToA2AParts

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

ToA2AParts converts the provided genai parts to A2A equivalents. Long running tool IDs are used for attaching metadata to the relevant data parts.

func ToADKMetaKey

func ToADKMetaKey(key string) string

ToADKMetaKey adds a prefix used to differentiage A2A-related values stored in custom metadata of an ADK session event.

func ToCustomMetadata

func ToCustomMetadata(taskID a2a.TaskID, ctxID string) map[string]any

ToCustomMetadata creates a session event custom metadata with A2A task and context IDs in it.

func ToGenAIPart

func ToGenAIPart(part a2a.Part) (*genai.Part, error)

ToGenAIPart converts the provided A2A part to a genai equivalent.

func ToGenAIParts

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

ToGenAIParts converts the provided A2A parts to genai equivalents.

func ToSessionEvent

func ToSessionEvent(ctx agent.InvocationContext, event a2a.Event) (*session.Event, error)

ToSessionEvent converts the provided a2a event to session event authored by the agent running in the provided invocation context.

Types

type A2APartConverter

type A2APartConverter func(ctx context.Context, a2aEvent a2a.Event, part a2a.Part) (*genai.Part, error)

A2APartConverter is a custom converter for converting A2A parts to GenAI parts. Implementations should generally remember to leverage adka2a.ToGenAiPart for default conversions nil returns are considered intentionally dropped parts.

type AfterEventCallback

type AfterEventCallback func(ctx ExecutorContext, event *session.Event, processed *a2a.TaskArtifactUpdateEvent) error

AfterEventCallback is the callback which will be called after an ADK event is converted to an A2A event.

type AfterExecuteCallback

type AfterExecuteCallback func(ctx ExecutorContext, finalEvent *a2a.TaskStatusUpdateEvent, err error) error

AfterExecuteCallback is the callback which will be called after an execution resolved into a completed or failed task.

type BeforeExecuteCallback

type BeforeExecuteCallback func(ctx context.Context, reqCtx *a2asrv.RequestContext) (context.Context, error)

BeforeExecuteCallback is the callback which will be called before an execution is started.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor invokes an ADK agent and translates session.Event-s to a2a.Event-s according to the following rules:

  • If the input doesn't reference any a2a.Task, produce a Task with TaskStateSubmitted state.
  • Right before runner.Runner invocation, produce TaskStatusUpdateEvent with TaskStateWorking.
  • For every session.Event produce a TaskArtifactUpdateEvent{Append=true} with transformed parts.
  • After the last session.Event is processed produce an empty TaskArtifactUpdateEvent{Append=true} with LastChunk=true, if at least one artifact update was produced during the run.
  • If there was an LLMResponse with non-zero error code, produce a TaskStatusUpdateEvent with TaskStateFailed. Else if there was an LLMResponse with long-running tool invocation, produce a TaskStatusUpdateEvent with TaskStateInputRequired. Else produce a TaskStatusUpdateEvent with TaskStateCompleted.

func NewExecutor

func NewExecutor(config ExecutorConfig) *Executor

NewExecutor creates an initialized Executor instance.

func (*Executor) Cancel

func (e *Executor) Cancel(ctx context.Context, reqCtx *a2asrv.RequestContext, queue eventqueue.Queue) error

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, reqCtx *a2asrv.RequestContext, queue eventqueue.Queue) error

type ExecutorConfig

type ExecutorConfig struct {
	// RunnerConfig is the configuration which will be used for [runner.New] during A2A Execute invocation.
	RunnerConfig runner.Config

	// RunConfig is the configuration which will be passed to [runner.Runner.Run] during A2A Execute invocation.
	RunConfig agent.RunConfig

	// BeforeExecuteCallback is the callback which will be called before an execution is started.
	// It can be used to instrument a context or prevent the execution by returning an error.
	BeforeExecuteCallback BeforeExecuteCallback

	// AfterEventCallback is the callback which will be called after an ADK event is successfully converted to an A2A event.
	// This gives an opportunity to enrich the event with additional metadata or abort the execution by returning an error.
	// The callback is not invoked for errors originating from ADK or event processing. Such errors are converted to
	// TaskStatusUpdateEvent-s with TaskStateFailed state. If needed these can be intercepted using AfterExecuteCallback.
	AfterEventCallback AfterEventCallback

	// AfterExecuteCallback is the callback which will be called after an execution resolved into a completed or failed task.
	// This gives an opportunity to enrich the event with additional metadata or log it.
	AfterExecuteCallback AfterExecuteCallback

	// A2APartConverter is a custom converter for converting A2A parts to GenAI parts.
	// Implementations should generally remember to leverage [adka2a.ToGenAiPart] for default conversions
	// nil returns are considered intentionally dropped parts.
	A2APartConverter A2APartConverter

	// GenAIPartConverter is a custom converter for converting GenAI parts to A2A parts.
	// Implementations should generally remember to leverage [adka2a.ToA2APart] for default conversions
	// nil returns are considered intentionally dropped parts.
	GenAIPartConverter GenAIPartConverter
}

ExecutorConfig allows to configure Executor.

type ExecutorContext

type ExecutorContext interface {
	context.Context

	// SessionID is ID of the session. It is passed as contextID in A2A request.
	SessionID() string
	// UserID is ID of the user who made the request. The information is either extracted from [a2asrv.CallContext]
	// or derived from session ID for unauthenticated requests.
	UserID() string
	// AgentName is the name of the root agent.
	AgentName() string
	// ReadonlyState provides a view of the current session state.
	ReadonlyState() session.ReadonlyState
	// Events provides a readonly view of the current session events.
	Events() session.Events
	// UserContent is a converted A2A message which is passed to runner.Run.
	UserContent() *genai.Content
	// RequestContext containts information about the original A2A Request, the current task and related tasks.
	RequestContext() *a2asrv.RequestContext
}

ExecutorContext provides read-only information about the context of an A2A agent execution. An execution starts with a user message and ends with a task in a terminal or input-required state.

type GenAIPartConverter

type GenAIPartConverter func(ctx context.Context, adkEvent *session.Event, part *genai.Part) (a2a.Part, error)

GenAIPartConverter is a custom converter for converting GenAI parts to A2A parts. Implementations should generally remember to leverage adka2a.ToA2APart for default conversions nil returns are considered intentionally dropped parts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL