Documentation
¶
Overview ¶
Package a2a implements the server half of the Agent2Agent (A2A) protocol v1.0 (Linux Foundation) over its JSON-RPC 2.0 binding: the public Agent Card, the request/response envelope, the Task object, and the mapping from Lectern's board columns onto the protocol's task states.
The HTTP wiring — which Lectern project a message names, which agent runs it, auth — lives in internal/api/a2a.go. This package stays transport-free so the card and the state mapping are testable on their own, and so nothing here can accidentally depend on the control plane's internals.
Index ¶
- Constants
- Variables
- func TaskID(id string) (int64, bool)
- func TaskState(status string) string
- func Timestamp(unixSeconds float64) string
- type AgentCapabilities
- type AgentCard
- type AgentInterface
- type AgentSkill
- type Artifact
- type CancelTaskParams
- type Error
- type GetTaskParams
- type ListTasksParams
- type Message
- type Part
- type Request
- type Response
- type SecurityScheme
- type SendMessageParams
- type Task
- type TaskStatus
Constants ¶
const ( // CardPath is where the Agent Card is served. It is unauthenticated // public metadata; internal/api serves it outside the auth gate. CardPath = "/.well-known/agent-card.json" // InterfacePath is the JSON-RPC binding this card points at. InterfacePath = "/a2a/v1" )
The two paths the protocol is served at, relative to the server root.
const ( MethodSendMessage = "SendMessage" MethodGetTask = "GetTask" MethodListTasks = "ListTasks" MethodCancelTask = "CancelTask" )
Method names. A2A fixes these to PascalCase; they are not Lectern's choice, and a client that sends anything else gets CodeMethodNotFound.
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 CodeTaskNotFound = -32001 )
JSON-RPC 2.0 error codes. The binding additionally fixes CodeTaskNotFound for "that task id does not exist".
const ( RoleUser = "ROLE_USER" RoleAgent = "ROLE_AGENT" )
Roles a message part can carry. Parts use member presence as their discriminator — a text part is {"text": "..."} — so this package models exactly one member: Text.
const ( StateSubmitted = "TASK_STATE_SUBMITTED" StateWorking = "TASK_STATE_WORKING" StateInputRequired = "TASK_STATE_INPUT_REQUIRED" StateCompleted = "TASK_STATE_COMPLETED" StateFailed = "TASK_STATE_FAILED" StateCanceled = "TASK_STATE_CANCELED" StateRejected = "TASK_STATE_REJECTED" )
Task states. A Lectern board column is not one of these; TaskState maps the column onto the closest state the protocol defines.
const ProtocolBinding = "JSONRPC"
ProtocolBinding is the transport binding of the interface in the card. Lectern serves JSON-RPC 2.0 over HTTP POST at InterfacePath.
const ProtocolVersion = "1.0"
ProtocolVersion is the A2A protocol version this server speaks.
Variables ¶
var Methods = []string{MethodSendMessage, MethodGetTask, MethodListTasks, MethodCancelTask}
Methods is the served set, in the order they are advertised.
Functions ¶
func TaskState ¶
TaskState maps a Lectern task status (internal/state.Statuses: backlog, queued, running, review, done, failed, cancelled) onto an A2A task state.
queued -> TASK_STATE_SUBMITTED accepted, not started
running -> TASK_STATE_WORKING
review -> TASK_STATE_INPUT_REQUIRED the agent stopped and a human owes
it a decision (accept, or send it back)
done -> TASK_STATE_COMPLETED
failed -> TASK_STATE_FAILED
cancelled -> TASK_STATE_CANCELED
"backlog" — a card that exists but was never queued — reads as SUBMITTED: from outside, it is accepted work that has not started. An unrecognised status (there is none today) also reads as SUBMITTED rather than inventing a state the protocol does not define.
Types ¶
type AgentCapabilities ¶
type AgentCapabilities struct {
Streaming bool `json:"streaming"`
PushNotifications bool `json:"pushNotifications"`
}
AgentCapabilities describes optional protocol features. Lectern sets both false: a dispatch is a long-running task you poll (or wait on over the REST API), so there is no streaming binding and no A2A push registration here.
type AgentCard ¶
type AgentCard struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
SupportedInterfaces []AgentInterface `json:"supportedInterfaces"`
Capabilities AgentCapabilities `json:"capabilities"`
DefaultInputModes []string `json:"defaultInputModes"`
DefaultOutputModes []string `json:"defaultOutputModes"`
Skills []AgentSkill `json:"skills"`
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes"`
Security []map[string][]string `json:"security"`
}
AgentCard is the public metadata a client reads before it sends anything: who this agent is, where its interface is, what it can do, and what credentials it accepts. It carries nothing secret — no project names, no ports, no tokens — because it is served unauthenticated.
type AgentInterface ¶
type AgentInterface struct {
URL string `json:"url"`
ProtocolBinding string `json:"protocolBinding"`
ProtocolVersion string `json:"protocolVersion"`
}
AgentInterface is one advertised way to reach this agent.
type AgentSkill ¶
type AgentSkill struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Examples []string `json:"examples"`
}
AgentSkill is one thing a client can ask this agent for.
type Artifact ¶
type Artifact struct {
ArtifactID string `json:"artifactId"`
Name string `json:"name"`
Parts []Part `json:"parts"`
}
Artifact is something a task produced. Lectern's artifacts are text: the attempt's report and its diff summary.
type CancelTaskParams ¶
type CancelTaskParams struct {
ID string `json:"id"`
}
CancelTaskParams names the task to cancel.
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error is a JSON-RPC error object.
type GetTaskParams ¶
type GetTaskParams struct {
ID string `json:"id"`
}
GetTaskParams and CancelTaskParams both name one task.
type ListTasksParams ¶
type ListTasksParams struct {
ContextID string `json:"contextId,omitempty"`
Limit int `json:"limit,omitempty"`
}
ListTasksParams narrows the list. ContextID is a project name — the same value GetTask reports as a task's contextId — and an empty ContextID lists every project.
type Message ¶
type Message struct {
MessageID string `json:"messageId,omitempty"`
Role string `json:"role"`
Parts []Part `json:"parts"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Message is one turn in a task's history, or the status message on a task.
type Part ¶
type Part struct {
Text *string `json:"text,omitempty"`
}
Part is one piece of a message. Member presence is the discriminator: this is a text part exactly when Text is present, at any length — hence the pointer, which distinguishes "absent" from "present and empty".
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request is one JSON-RPC 2.0 call. ID is kept raw so a client's numeric or string id is echoed back byte-identical, as the spec requires.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id"`
Result any `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response is one JSON-RPC 2.0 result or error. Exactly one of Result and Error is set.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"`
Scheme string `json:"scheme,omitempty"`
In string `json:"in,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description"`
}
SecurityScheme is one accepted credential, in the OpenAPI 3 shape A2A reuses. SecurityScheme.Type is "http", "apiKey", "openIdConnect", "oauth2" or "mutualTLS".
type SendMessageParams ¶
type SendMessageParams struct {
Message Message `json:"message"`
}
SendMessageParams is the SendMessage request body. Lectern reads the project, agent, model and best-of-N variants from the message metadata.
type Task ¶
type Task struct {
ID string `json:"id"`
ContextID string `json:"contextId"`
Status TaskStatus `json:"status"`
Artifacts []Artifact `json:"artifacts"`
History []Message `json:"history,omitempty"`
}
Task is the protocol's unit of work. ID is Lectern's task id in decimal, so it can also be looked up over the REST API; ContextID is the project name.
type TaskStatus ¶
type TaskStatus struct {
State string `json:"state"`
Message *Message `json:"message,omitempty"`
Timestamp string `json:"timestamp"`
}
TaskStatus is a task's state plus, optionally, the agent's own message about it — A2A's way of carrying "why" alongside "what".