Agent API
The port between the server and an agent: Reply, Resume, the turn that an agent returns, and how the server runs turns.
For agent authors
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)
}
Replyis called when a message addresses the agent.historyis the conversation’s events so far.Resumeis called after an approval the agent requested has been answered.approvedis the answer.
The turn
An agent returns an AgentTurn:
| Field | Meaning |
|---|---|
Parts | The reply: text, data, a URL or raw bytes |
Approval | An approval request, instead of or before a reply. The server opens an obligation. |
Outcome | succeeded 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
Resumereports an approval.
The Write an agent guide and the Server SDK example show a complete agent.
Next steps
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.