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
- func Describe(m *a2a.Message) string
- func FetchCard(ctx context.Context, client *http.Client, base string) (*a2a.AgentCard, error)
- func Preview(parts []*a2a.Part, n int) string
- func Tags(m *a2a.Message) map[string]string
- func Text(m *a2a.Message) string
- type Link
- type Links
- func (s *Links) Children(ctx context.Context, taskID a2a.TaskID) ([]*Link, error)
- func (s *Links) Create(ctx context.Context, l *Link) error
- func (s *Links) Get(ctx context.Context, taskID a2a.TaskID) (*Link, error)
- func (s *Links) SetParent(ctx context.Context, child, parent a2a.TaskID) error
- func (s *Links) SetRemote(ctx context.Context, taskID, remoteTaskID a2a.TaskID, remoteContextID string) error
- func (s *Links) ValidParent(ctx context.Context, parent a2a.TaskID, sender string) bool
- type Relay
- type Waiting
Constants ¶
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" )
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 ¶
Describe summarizes a message for the activity log: its text, or else its data and files, shortened.
func FetchCard ¶
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 ¶
Preview renders parts for the activity log, up to n runes: text as is, data as JSON, files by name.
Types ¶
type Link ¶
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 ¶
type Links struct {
// contains filtered or unexported fields
}
Links stores Link rows.
func (*Links) SetParent ¶
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).
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.
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.