a2abridge

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentMetadataFromCard

func AgentMetadataFromCard(card *a2a.AgentCard, cfgName, cfgDescription string) (name, description string)

AgentMetadataFromCard composes the AX-side (Name, Description) for a registered A2A agent from its AgentCard plus optional config-supplied overrides.

func AuthRequiredError

func AuthRequiredError(agentID string, taskID a2a.TaskID, statusMsg *a2a.Message) error

AuthRequiredError formats a user-facing error for TaskStateAuthRequired. Surfaces any hint the agent included in Status.Message. Temporary for now.

func ClearStateMarker

func ClearStateMarker(conversationID string, o agent.OutputHandler) error

ClearStateMarker writes a final state marker indicating no active task.

func EmitConfirmation

func EmitConfirmation(conversationID, toolCallID string, taskID a2a.TaskID, task *a2a.Task, emittedArtifactIDs []string, o agent.OutputHandler) error

EmitConfirmation surfaces a HITL prompt to the AX client and persists the state marker so the bridge can resume the same task on the user's reply.

ConfirmationContentID is set to toolCallID so the planner can correlate the user's reply back to the call via a strict ID match. If toolCallID is empty (the bridge was invoked without a planner), we fall back to string(taskID).

func EmitTaskArtifacts

func EmitTaskArtifacts(task *a2a.Task, o agent.OutputHandler) error

EmitTaskArtifacts emits all artifacts from a completed task to the client.

func FindConfirmationAnswer

func FindConfirmationAnswer(history []*proto.Message, confID string) (answered, approved bool)

FindConfirmationAnswer scans the history (most recent first) for a user reply to the ConfirmationContent we emitted with the given confID. Returns (true, approved) if a matching answer is found, (false, false) otherwise.

func FindToolCallID

func FindToolCallID(agentID string, messages []*proto.Message) string

FindToolCallID returns the ID of the most recent ToolCall in history whose function name matches agentID. Returns "" when no matching ToolCall is found - e.g. the bridge was invoked without a planner.

func IterateStream

func IterateStream(
	ctx context.Context,
	client *a2aclient.Client,
	agentID string,
	conversationID string,
	toolCallID string,
	events iter.Seq2[a2a.Event, error],
	o agent.OutputHandler,
) error

IterateStream walks the SDK's iter.Seq2 stream of events, dispatches each to the appropriate handler, and returns once the stream ends or a fatal error is encountered. If the stream ends with the active task still in a non-terminal state, falls back to polling GetTask via PollUntilTerminal until the task reaches a terminal state.

client and agentID are passed through to the polling fallback so it can issue GetTask calls and format error messages.

func LatestUserInputParts

func LatestUserInputParts(msgs []*proto.Message) []*a2a.Part

LatestUserInputParts returns the most recent user-role input as a single A2A Part - i.e. what the AX user just typed. The walk goes backward from the end of msgs and returns as soon as it finds a user-role message with usable content (text/file/data).

func MessagesToA2AParts

func MessagesToA2AParts(msgs []*proto.Message) []*a2a.Part

MessagesToA2AParts converts AX message history into a flat list of A2A Parts. Internal-only AX content are skipped.

func NewInterceptor

func NewInterceptor(card *a2a.AgentCard, a auth.Auth, h auth.Headers) (a2aclient.CallInterceptor, error)

NewInterceptor builds an a2aclient.CallInterceptor that injects the merged auth + user headers on every outgoing call. Returns (nil, nil) when no headers are configured.

func OverrideCardHosts

func OverrideCardHosts(card *a2a.AgentCard, addr string) error

OverrideCardHosts rewrites the host:port portion of every URL in card.SupportedInterfaces[] to match the host:port of addr. Used for A2A agents whose AgentCard typically declares localhost URLs that must be redirected to the actual worker address discovered at connect time.

func PollUntilTerminal

func PollUntilTerminal(
	ctx context.Context,
	client *a2aclient.Client,
	agentID string,
	conversationID string,
	toolCallID string,
	taskID a2a.TaskID,
	lastSeen *a2a.Task,
	alreadyEmitted []string,
	o agent.OutputHandler,
) error

PollUntilTerminal polls GetTask with exponential backoff until the task reaches a terminal state, the context is canceled, or an error occurs. Newly discovered artifacts and status changes are emitted to the client.

client and agentID identify the SDK client and the bridge's registered agent ID for issuing GetTask and constructing user-facing errors.

toolCallID is forwarded to EmitConfirmation if the task transitions to INPUT_REQUIRED while we are polling.

alreadyEmitted seeds the dedup set with artifact IDs already emitted by the caller. It prevents re-emission across the streaming<->polling handoff and across invocation boundaries.

func RecoverA2AState

func RecoverA2AState(msgs []*proto.Message) (conversationID, activeTaskID string, emittedArtifactIDs []string, found bool)

RecoverA2AState scans the message history for the most recent A2A state marker and returns its conversation_id, active_task_id, and the list of artifact IDs already emitted by the prior bridge invocation. The most recent marker wins so successive resume cycles see the latest state.

Types

This section is empty.

Jump to

Keyboard shortcuts

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