Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Teams API

Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.

Team management for multi-agent collaboration. Spawn teams of persistent agents that communicate and coordinate on shared tasks.

Overview

Teams are groups of persistent Luna agents that share a work queue and can communicate via the agent mailbox system. Each team has a configurable size (default 3, max 10). Teammates persist across multiple tasks until stop_team is called. Teams use ACP for inter-agent messaging.

Authentication

Requires Authorization: Bearer <token>. Team create/destroy and member/mail mutations are gated to the team creator or an admin (teams:manage at the middleware; ensure_team_mutator handler-side); team detail, members list, and mail read (incl. ?mine=1) are open to members whose user_uuid matches the caller, plus owner/admin.

Endpoints

Create Team

POST /api/v1/teams

Admin only. Creates a new team from a name plus options. Returns 201 on success.

Request Body:

{
  "name": "research-team",
  "size": 3,
  "model": "claude-sonnet-4-20250514",
  "mode": "coordinate",
  "system_prompt": "You are a research team. Collaborate on literature review."
}

Response:

{
  "ok": true,
  "team_id": "team-abc123"
}

403 if not admin; 400 if name is missing.

List Teams

GET /api/v1/teams

Returns all teams.

{
  "ok": true,
  "teams": [ ]
}

Get Team Details

GET /api/v1/teams/:id

Returns team status, member agents, and queue depth. Creator, admin, or team members.

Destroy Team

DELETE /api/v1/teams/:id

Admin or team creator. Stops all team members and cleans up resources.

{
  "ok": true,
  "team_id": "team-abc123"
}

List Members

GET /api/v1/teams/:id/members

Returns the team’s member list. Creator, admin, or team members.

{
  "ok": true,
  "members": [ ]
}

Add Member

POST /api/v1/teams/:id
POST /api/v1/teams/:id/members

Admin or team creator. Both route forms dispatch the same add_member action. Body must include worker_id.

{ "worker_id": "agent-4", "role": "researcher" }

Response: { "ok": true, "member_id": "..." }.

Remove Member

DELETE /api/v1/teams/:id/members/:worker_id

Admin or team creator. Removes a worker from the team (accepts either the canonical tm_* id or the member’s worker_id). Response: { "ok": true }.

Read Team Mail

GET /api/v1/teams/:id/mail

Returns all mailbox messages for the team. Creator, admin, or team members (?mine=1 scopes to the caller’s own mail).

{
  "ok": true,
  "messages": [ ]
}

Send Team Mail

POST /api/v1/teams/:id/mail

Admin or team creator. Posts a message to the team mailbox. Body must include body; from, to, subject, priority are optional (to defaults to all, priority to normal).

{ "from": "agent-1", "to": "all", "subject": "sync", "body": { }, "priority": "normal" }

Response: { "ok": true, "msg_id": "..." }.

Acknowledge Team Mail

POST /api/v1/teams/:id/mail/:message_id/ack

Admin or team creator. Marks one mailbox message acknowledged . Response: { "ok": true }; 404 wrong_team when the message does not belong to the team.

Team Communication:

Agents within a team communicate through the agent mailbox system (agent_mailbox.lua). Messages are routed via ACP:

Agent A  ──send──►  Mailbox A  ──►  TeamQueue  ──►  Agent B
                                                    Agent C

The team queue (team_queue.lua) provides FIFO work distribution with get_idle/mark_busy/mark_idle states. Teammates poll for work every 500ms.

Error Codes:

CodeDescription
400Invalid team parameters
401Authentication required
404Team not found
409Team already at max size

Examples:

curl -X POST http://127.0.0.1:21434/api/v1/teams \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "research", "size": 3, "model": "claude-sonnet-4-20250514"}'

curl http://127.0.0.1:21434/api/v1/teams/team-abc123/members \
  -H "Authorization: Bearer $TOKEN"