Agent API

The port between the server and an agent: Reply, Resume, the turn that an agent returns, and how the server runs turns.

The Agent API is a Go interface in protocol/server today. Its shape is stable within version 1; another language can implement the same behavior behind a gateway, as long as the turn semantics below hold.

The port

type Agent interface {
    Reply(ctx context.Context, history []protocol.Event) (protocol.AgentTurn, error)
    Resume(ctx context.Context, history []protocol.Event, req protocol.ApprovalRequest, approved bool) (protocol.AgentTurn, error)
}
  • Reply is called when a message addresses the agent. history is the conversation’s events so far.
  • Resume is called after an approval the agent requested has been answered. approved is the answer.

The turn

An agent returns an AgentTurn:

FieldMeaning
PartsThe reply: text, data, a URL or raw bytes
ApprovalAn approval request, instead of or before a reply. The server opens an obligation.
Outcomesucceeded or failed. The server records a robotelos.outcome event.

A turn either replies, asks for approval, or both. An agent MUST return an outcome when it finishes its work.

How the server runs turns

  • A turn is claimed by one worker, which renews a lease while it works. The default lease is 30 seconds.
  • A turn whose worker stops renewing is claimed again by another worker, up to MaxTurnAttempts (default 3). After that the turn ends as a failed outcome.
  • A turn’s events are committed in one transaction when it finishes. A turn that fails midway does not leave partial events.
  • The server cancels the context when the turn is abandoned. An agent MUST return promptly after cancellation.
  • Agent output is a proposal. The server validates it, applies the approval rules, and records it.

What an agent must not do

  • An agent MUST NOT assume that a client is connected. Replies are recorded whether or not anyone is watching.
  • An agent MUST NOT keep customer data in memory across turns as the record. The journal is the record.
  • An agent MUST NOT execute an approval-gated operation before Resume reports an approval.

The Write an agent guide and the Server SDK example show a complete agent.

Next steps