Documentation
¶
Overview ¶
Package client calls a Lagrange server's HTTP API with a personal API key (lgk_…). The CLI and the MCP server use it; the API itself is described at /api/openapi.yaml.
Index ¶
- Constants
- func ShortState(s string) string
- func StatusOf(err error) int
- func Waiting(s a2a.TaskState) bool
- type Address
- type Answer
- type Client
- func (c *Client) Addresses(ctx context.Context) ([]*Address, error)
- func (c *Client) Answer(ctx context.Context, id string, a *Answer) error
- func (c *Client) ConnectTelegram(ctx context.Context, token string) (*Telegram, error)
- func (c *Client) CreateAgent(ctx context.Context, handle string) (string, error)
- func (c *Client) DisconnectTelegram(ctx context.Context) error
- func (c *Client) Do(ctx context.Context, method, path string, body, out any) error
- func (c *Client) Follow(ctx context.Context, id string, wait, poll time.Duration, ...) (*Task, bool, error)
- func (c *Client) Me(ctx context.Context) (*Me, error)
- func (c *Client) MintToken(ctx context.Context, handle, label string) (string, error)
- func (c *Client) PairTelegram(ctx context.Context) (*Telegram, error)
- func (c *Client) Run(ctx context.Context, id string) (*RunDetail, error)
- func (c *Client) Runs(ctx context.Context, f RunFilter) ([]*Run, error)
- func (c *Client) Send(ctx context.Context, m *Send) (*SendResult, error)
- func (c *Client) SetTelegramLevel(ctx context.Context, level string) (*Telegram, error)
- func (c *Client) Task(ctx context.Context, id string) (*Task, error)
- func (c *Client) Telegram(ctx context.Context) (*Telegram, error)
- func (c *Client) TestTelegram(ctx context.Context) error
- func (c *Client) Waiting(ctx context.Context) ([]*Wait, error)
- type Error
- type File
- type Login
- type Me
- type Result
- type Run
- type RunDetail
- type RunFilter
- type Send
- type SendResult
- type Task
- type Telegram
- type Wait
Constants ¶
const AnsweredByKey = "https://threeagents.dev/ext/answered-by/v1"
AnsweredByKey is the message metadata key that says who answered from the inbox.
Variables ¶
This section is empty.
Functions ¶
func ShortState ¶
ShortState turns "TASK_STATE_INPUT_REQUIRED" into "input-required".
Types ¶
type Address ¶
type Address struct {
Handle string `json:"handle"`
Kind string `json:"kind"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
Online bool `json:"online"`
Card json.RawMessage `json:"card,omitempty"`
}
Address is an agent or a person.
type Answer ¶
type Answer struct {
Text string `json:"text,omitempty"`
Data map[string]any `json:"data,omitempty"`
Decision string `json:"decision,omitempty"`
}
Answer is the answer to a task waiting for input.
type Client ¶
type Client struct {
// Server is the base URL, e.g. https://lagrange.example.com.
Server string
// Key is a personal API key.
Key string
// HTTP is the client to use; nil means one with a 30-second timeout.
HTTP *http.Client
}
Client calls one server as one key.
func (*Client) ConnectTelegram ¶
ConnectTelegram checks a bot token from @BotFather, connects the bot (replacing any other) and returns the link that pairs it.
func (*Client) CreateAgent ¶
CreateAgent creates an agent address and returns its first tunnel token.
func (*Client) DisconnectTelegram ¶
DisconnectTelegram removes the bot.
func (*Client) Do ¶
Do calls method path with body as JSON and decodes the answer into out (if not nil).
func (*Client) Follow ¶
func (c *Client) Follow(ctx context.Context, id string, wait, poll time.Duration, stop func(*Task) bool) (*Task, bool, error)
Follow polls a task every poll (zero: one second) until stop says so or wait runs out, and returns the task as it last saw it, and whether stop said so.
func (*Client) PairTelegram ¶
PairTelegram makes a new pairing link.
func (*Client) Send ¶
Send sends a message and returns the task it started (or continued), or the address's direct answer.
func (*Client) SetTelegramLevel ¶
SetTelegramLevel sets what the bot sends besides questions: "questions" or "milestones".
func (*Client) TestTelegram ¶
TestTelegram sends a test message to the paired chat.
type File ¶
type File struct {
Name string `json:"name,omitempty"`
MediaType string `json:"mediaType,omitempty"` // guessed from the name or content if empty
Data []byte `json:"data,omitempty"`
URL string `json:"url,omitempty"`
}
File is a file in a message: its bytes, or a URL the recipient fetches. The request carries the bytes base64-encoded, and is limited to 8 MB.
type Login ¶
type Login struct {
Key string `json:"key"`
Workspace string `json:"workspace"`
Role string `json:"role"`
Server string `json:"server"`
}
Login is a key from `lagrange login`.
func ClaimLogin ¶
ClaimLogin trades a `lagrange login` code and its PKCE verifier for a key. It needs no key.
func PasswordLogin ¶
func PasswordLogin(ctx context.Context, server, email, password, workspace, name string) (*Login, error)
PasswordLogin makes an API key with an email and a password, for a machine without a browser: it logs in (a session cookie), makes a key named name in workspace (its slug; empty: the person's first workspace) with their role there, and logs the session out. Accounts that sign in only with GitHub or Google can't use it.
type Me ¶
type Me struct {
User struct {
ID int64 `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Handle string `json:"handle"`
} `json:"user"`
Key struct {
Workspace string `json:"workspace"`
Role string `json:"role"`
} `json:"key"`
}
Me is who a key acts as.
type Result ¶
type Result struct {
TaskID string `json:"taskId"`
ContextID string `json:"contextId,omitempty"`
State string `json:"state" jsonschema:"submitted, working, input-required, auth-required, completed, failed, canceled or rejected"`
// Done is true once the task reached a final state.
Done bool `json:"done"`
// Text is the latest status message and any text artifacts.
Text string `json:"text,omitempty"`
// Data holds structured parts of the answer.
Data []any `json:"data,omitempty"`
AnsweredBy string `json:"answeredBy,omitempty"`
// WaitingOn is the address a waiting task waits for.
WaitingOn string `json:"waitingOn,omitempty"`
Note string `json:"note,omitempty"`
}
Result is a task's state and what it answered, flattened for people, scripts and models.
func MessageResult ¶
MessageResult flattens a direct answer that started no task.
type Run ¶
type Run struct {
ID string `json:"id"`
// ContextID is the root task's context: Send into it to continue the conversation.
ContextID string `json:"contextId,omitempty"`
Title string `json:"title"`
Outcome string `json:"outcome,omitempty"`
Starter string `json:"starter"`
Recipient string `json:"recipient"`
State string `json:"state"`
Waiting []string `json:"waiting"`
Participants []string `json:"participants"`
Tasks int `json:"tasks"`
StartedAt time.Time `json:"startedAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Cost is what the run's agents reported spending on it, in Currency.
Cost float64 `json:"cost,omitempty"`
Currency string `json:"currency,omitempty"`
// Report is the run's latest situation report (lagrange/report), if it has one.
Report *report.Report `json:"report,omitempty"`
}
Run is a root task and everything it caused.
type Send ¶
type Send struct {
To string `json:"to"`
Text string `json:"text,omitempty"`
Data map[string]any `json:"data,omitempty"`
Files []File `json:"files,omitempty"`
TaskID string `json:"taskId,omitempty"`
ContextID string `json:"contextId,omitempty"`
// Tags are recorded with the task in the activity log (data.tags), for clients
// to group and label tasks: up to 16 short strings.
Tags map[string]string `json:"tags,omitempty"`
// Metadata is the message's metadata, e.g. {"acpSettings": {"model": "opus"}}
// for a coding agent that lets senders pick its model.
Metadata map[string]any `json:"metadata,omitempty"`
}
Send is a message to an address.
type SendResult ¶
SendResult is what an address answered: a task to follow, or a plain message.
type Task ¶
type Task struct {
ID string `json:"id"`
ContextID string `json:"contextId"`
State string `json:"state"`
Sender string `json:"sender"`
Recipient string `json:"recipient"`
ParentTaskID string `json:"parentTaskId,omitempty"`
Summary string `json:"summary"`
Status string `json:"status,omitempty"`
Awaiting string `json:"awaiting,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Task *a2a.Task `json:"task,omitempty"`
}
Task is a task as the API shows it, with the full A2A task.
type Telegram ¶
type Telegram struct {
Connected bool `json:"connected"`
BotUsername string `json:"botUsername,omitempty"`
Paired bool `json:"paired"`
ChatUsername string `json:"chatUsername,omitempty"`
// PairLink opens the bot with a fresh pairing code (only right after Connect or Pair).
PairLink string `json:"pairLink,omitempty"`
PairExpiresAt *time.Time `json:"pairExpiresAt,omitempty"`
// Level is "questions" or "milestones".
Level string `json:"level,omitempty"`
MutedUntil *time.Time `json:"mutedUntil,omitempty"`
}
Telegram is the key's person's Telegram bot connection. It never carries the token.
type Wait ¶
type Wait struct {
Task *Task `json:"task"`
RunID string `json:"runId"`
Who string `json:"who"`
Asker string `json:"asker"`
Person bool `json:"person"`
Since time.Time `json:"since"`
Reminders int `json:"reminders"`
EscalatedTo string `json:"escalatedTo,omitempty"`
}
Wait is a task waiting for an answer.