relay

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relay is Lagrange's A2A executor. Every address on the platform is an A2A tenant served by one a2a-go handler, and the relay is what runs a task for it:

  • For an agent, it forwards the task to the agent (through the agent's tunnel, or directly to a public endpoint), and re-stamps the agent's events with the platform's task and context IDs. The platform owns the task, so the task survives the agent going offline, waits in the mailbox until the agent is back, and is visible to the inbox and the graph.
  • For a person, it parks the task as INPUT_REQUIRED in their inbox until they answer.

Every event is written to the activity log as it happens.

Index

Constants

View Source
const (
	// HeaderTask is set on every request the relay sends to an agent: the platform task
	// the agent is working on. An agent that propagates it on its own outgoing calls
	// (a2aext.NewServerPropagator and NewClientPropagator) lets the platform nest those
	// calls under the task.
	HeaderTask = delegate.HeaderTask
	// HeaderSender is set on requests to an agent: the address that sent the task.
	HeaderSender = "Lagrange-Sender"

	// AwaitingKey in a status message's metadata names the address the task waits for.
	AwaitingKey = "https://threeagents.dev/ext/awaiting/v1"
	// AnsweredByKey in a message's metadata names the person who answered from the inbox.
	AnsweredByKey = "https://threeagents.dev/ext/answered-by/v1"
	// FailureKey in a FAILED status message's metadata says why Lagrange could not deliver
	// the task: {"kind": Failure*, "address": handle, "detail": text}. Failures an agent
	// reports itself don't carry it.
	FailureKey = "https://threeagents.dev/ext/delivery-failure/v1"
	// TagsKey is delegate.TagsKey: the sender's tags for a message, which the activity
	// log records with the task.
	TagsKey = delegate.TagsKey

	// AttrAnsweredBy, in the a2asrv.User attributes of an inbox answer, names the person
	// answering on the task owner's behalf. Only the platform's own API sets it.
	AttrAnsweredBy = "lagrange.answeredBy"
	// AttrAnswersFor, with AttrAnsweredBy, names the person an answer is given for: an
	// escalation lets someone else answer in their place. Only the platform's API sets it.
	AttrAnswersFor = "lagrange.answersFor"
	// AttrDecision is "reject" when the person declined.
	AttrDecision = "lagrange.decision"
)
View Source
const (
	// FailureAgentDown: the agent's tunnel is connected, but nothing answers behind it.
	FailureAgentDown = "agent-down"
	// FailureUnreachable: Lagrange could not connect to the agent's endpoint.
	FailureUnreachable = "unreachable"
	// FailureTimeout: the agent did not answer in time.
	FailureTimeout = "timeout"
	// FailureTaskLost: the agent no longer knows the task (it restarted and keeps tasks in memory).
	FailureTaskLost = "task-lost"
	// FailureAgentError: the agent answered with an error, or with something that isn't A2A.
	FailureAgentError = "agent-error"
)

Delivery failure kinds, in FailureKey metadata.

Variables

This section is empty.

Functions

func Describe

func Describe(m *a2a.Message) string

Describe summarizes a message for the activity log: its text, or else its data and files, shortened.

func FetchCard

func FetchCard(ctx context.Context, client *http.Client, base string) (*a2a.AgentCard, error)

FetchCard gets an agent's card from base (empty means "whatever is behind this client's transport", used for tunnels) at the well-known path.

func Preview

func Preview(parts []*a2a.Part, n int) string

Preview renders parts for the activity log, up to n runes: text as is, data as JSON, files by name.

func Tags

func Tags(m *a2a.Message) map[string]string

Tags returns the tags of a message (TagsKey in its metadata), cut to the limits the activity log keeps, or nil. Values that aren't strings are written as JSON.

func Text

func Text(m *a2a.Message) string

Text joins the text parts of a message.

Types

type Link struct {
	TaskID       a2a.TaskID `json:"taskId"`
	Sender       string     `json:"sender"`
	Recipient    string     `json:"recipient"`
	ParentTaskID a2a.TaskID `json:"parentTaskId,omitempty"`
	// RemoteTaskID and RemoteContextID are the agent's own IDs for the task, behind the
	// tunnel. They stay empty for people and for agents that answered with a message.
	RemoteTaskID    a2a.TaskID `json:"-"`
	RemoteContextID string     `json:"-"`
}

Link is what the relay knows about a platform task beyond the A2A task itself.

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

Links stores Link rows.

func NewLinks(db *pg.DB) *Links

NewLinks returns a link store on db.

func (*Links) Children

func (s *Links) Children(ctx context.Context, taskID a2a.TaskID) ([]*Link, error)

Children returns the links whose parent is taskID.

func (*Links) Create

func (s *Links) Create(ctx context.Context, l *Link) error

Create stores l unless the task already has a link.

func (*Links) Get

func (s *Links) Get(ctx context.Context, taskID a2a.TaskID) (*Link, error)

Get returns the link of a task, or nil.

func (*Links) SetParent

func (s *Links) SetParent(ctx context.Context, child, parent a2a.TaskID) error

SetParent records that child was delegated from parent, if child doesn't have a parent yet and was sent by parent's recipient (so an agent can only claim its own calls).

func (*Links) SetRemote

func (s *Links) SetRemote(ctx context.Context, taskID, remoteTaskID a2a.TaskID, remoteContextID string) error

SetRemote records the agent's own task and context IDs.

func (*Links) ValidParent

func (s *Links) ValidParent(ctx context.Context, parent a2a.TaskID, sender string) bool

ValidParent reports whether parent is a task that sender is currently the recipient of, which is what makes "sender is delegating from parent" believable.

type Relay

type Relay struct {
	Directory *directory.Directory
	Links     *Links
	Activity  *activity.Log
	Mailbox   *mailbox.Mailbox
	// Direct is the HTTP client for agents with a public endpoint.
	Direct *http.Client
	// OnWaiting, if set, is called when a task stops on INPUT_REQUIRED or AUTH_REQUIRED.
	OnWaiting func(ctx context.Context, w Waiting)
	Logger    *slog.Logger
}

Relay implements a2asrv.AgentExecutor for every address.

func (*Relay) Cancel

Cancel implements a2asrv.AgentExecutor.

func (*Relay) Execute

func (r *Relay) Execute(ctx context.Context, ec *a2asrv.ExecutorContext) iter.Seq2[a2a.Event, error]

Execute implements a2asrv.AgentExecutor.

type Waiting

type Waiting struct {
	// Entry is the task's activity entry: its state, sender, recipient and awaiting.
	Entry *activity.Entry
	// Question is what is asked: the agent's status message, or, for a task addressed
	// to a person, the sender's message.
	Question *a2a.Message
}

Waiting is a task that just stopped to wait on someone.

Jump to

Keyboard shortcuts

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