Skip to main content
Trinity
API Reference

Agents API

Core REST API endpoints for agent lifecycle management, configuration, files, and metadata. All endpoints require JWT Bearer token unless noted. See Authentication for details.

Full request/response schemas available at http://localhost:8000/docs when running locally (Swagger UI).

Authentication

# All requests require a Bearer token
curl -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents

Agent CRUD and Lifecycle

EndpointMethodDescription
/api/agentsGETList all agents
/api/agentsPOSTCreate agent
/api/agents/{name}GETGet agent details
/api/agents/{name}DELETEDelete agent
/api/agents/{name}/startPOSTStart container
/api/agents/{name}/stopPOSTStop container
/api/agents/{name}/renamePUTRename agent
GET

/api/agents

List all agents accessible to the current user. Supports filtering by tags.

NameTypeRequiredDescription
tagsstringNoComma-separated tag filter (OR logic), e.g. ?tags=prod,staging
curl -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents

# Response
[
  {
    "name": "research-agent",
    "type": "business-assistant",
    "status": "running",
    "port": 2222,
    "created": "2026-01-15T10:30:00Z",
    "runtime": "claude-code",
    "tags": ["research", "prod"]
  }
]
POST

/api/agents

Create a new agent. The agent will be deployed as an isolated Docker container.

NameTypeRequiredDescription
namestringYesUnique agent name
typestringNoAgent type (default: "business-assistant")
templatestringNoTemplate to initialize from
runtimestringNo"claude-code" or "gemini-cli"
runtime_modelstringNoModel override (e.g. "sonnet-4.5")
resourcesobjectNo{"cpu": "2", "memory": "4g"}
custom_instructionsstringNoCustom system prompt
github_repostringNoGitHub repo (e.g. "Org/repo")
curl -X POST -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "research-agent",
    "template": "business-assistant",
    "runtime": "claude-code",
    "resources": {"cpu": "2", "memory": "4g"}
  }' \
  http://localhost:8000/api/agents

# Response: AgentStatus
{
  "name": "research-agent",
  "type": "business-assistant",
  "status": "running",
  "port": 2222,
  "created": "2026-03-26T12:00:00Z",
  "runtime": "claude-code"
}
GET

/api/agents/:name

Get details of a specific agent including ownership, sharing, and autonomy status.

curl -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents/research-agent

# Response
{
  "name": "research-agent",
  "status": "running",
  "port": 2222,
  "owner": "admin",
  "is_owner": true,
  "autonomy_enabled": true,
  "read_only_enabled": false,
  "runtime": "claude-code",
  "avatar_url": "/api/agents/research-agent/avatar?v=1706..."
}
DELETE

/api/agents/:name

Delete an agent and all associated resources (container, volume, schedules, skills, tags). System agents cannot be deleted.

curl -X DELETE -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents/research-agent

# Response
{"message": "Agent research-agent deleted"}
POST

/api/agents/:name/start

Start an agent container. Injects credentials and broadcasts a WebSocket event.

curl -X POST -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents/research-agent/start

# Response
{
  "message": "Agent research-agent started",
  "credentials_injection": "success"
}
POST

/api/agents/:name/stop

Stop an agent container gracefully.

curl -X POST -H "Authorization: Bearer <token>" \
  http://localhost:8000/api/agents/research-agent/stop

# Response
{"message": "Agent research-agent stopped"}
PUT

/api/agents/:name/rename

Rename an agent. Updates all references including container name, volume, and schedules.

Agent Info and Files

EndpointMethodDescription
/api/agents/{name}/infoGETTemplate metadata
/api/agents/{name}/filesGETWorkspace file tree
/api/agents/{name}/files/downloadGETDownload file
/api/agents/{name}/logsGETContainer logs
/api/agents/{name}/statsGETLive telemetry
/api/agents/{name}/analyticsGETMulti-day execution analytics for the Overview tab
GET

/api/agents/:name/logs

Get agent container logs. Useful for debugging startup issues.

NameTypeRequiredDescription
tailintegerNoNumber of log lines to return (default: 100)
curl -H "Authorization: Bearer <token>" \
  "http://localhost:8000/api/agents/research-agent/logs?tail=50"

# Response
{"logs": "Starting agent server...\n..."}
GET

/api/agents/:name/stats

Get live container stats including CPU usage, memory, and network I/O.

GET

/api/agents/:name/analytics

Multi-day execution analytics for the Overview tab.

NameTypeRequiredDescription
windowstringNo"7d", "14d", or "30d" (default: "7d")
GET

/api/agents/:name/info

Get template metadata for an agent including capabilities and configuration details.

GET

/api/agents/:name/files

Get the workspace file tree for an agent container.

GET

/api/agents/:name/files/download

Download a file from the agent's workspace.

Configuration

EndpointMethodDescription
/api/agents/{name}/autonomyGET/PUTAutonomy mode
/api/agents/{name}/read-onlyGET/PUTRead-only mode
/api/agents/{name}/timeoutGET/PUTExecution timeout (PUT rejects a cap below any active schedule's timeout with 400)
/api/agents/{name}/ssh-accessPOSTGenerate SSH credentials
/api/agents/{name}/circuit-breakerGET/PUTCircuit breaker state / per-agent enable-disable (owner-only)
/api/agents/{name}/circuit-breaker/resetPOSTReset both breakers to closed (admin-only)
GET/PUT

/api/agents/:name/autonomy

Get or set the autonomy mode for an agent. When enabled, the agent can execute tasks without manual approval.

GET/PUT

/api/agents/:name/read-only

Get or set read-only mode. When enabled, the agent cannot modify its workspace files.

GET/PUT

/api/agents/:name/timeout

Get or set the execution timeout for an agent. PUT rejects a cap below any active schedule's timeout with 400.

POST

/api/agents/:name/ssh-access

Generate SSH credentials for direct container access.

GET/PUT

/api/agents/:name/circuit-breaker

Get the circuit breaker state, or enable/disable the breaker per agent (owner-only).

POST

/api/agents/:name/circuit-breaker/reset

Reset both breakers to closed (admin-only).

Credentials

EndpointMethodDescription
/api/agents/{name}/credentials/statusGETCheck credential files
/api/agents/{name}/credentials/injectPOSTInject credentials
/api/agents/{name}/credentials/exportPOSTExport encrypted
/api/agents/{name}/credentials/importPOSTImport encrypted
GET

/api/agents/:name/credentials/status

Check which credential files exist in the agent container.

POST

/api/agents/:name/credentials/inject

Inject credentials into a running agent container. Copies credential files from the host.

POST

/api/agents/:name/credentials/export

Export agent credentials as an encrypted bundle for backup or transfer.

POST

/api/agents/:name/credentials/import

Import credentials from an encrypted bundle into the agent.

Sharing

EndpointMethodDescription
/api/agents/{name}/sharePOSTShare with email
/api/agents/{name}/share/{email}DELETERemove share
/api/agents/{name}/sharesGETList shares
POST

/api/agents/:name/share

Share an agent with another user by email address.

DELETE

/api/agents/:name/share/:email

Remove a share for a specific email address.

GET

/api/agents/:name/shares

List all users an agent is shared with.

Loops

Sequential bounded task execution against one agent.

EndpointMethodDescription
/api/agents/{name}/loopsPOSTStart a loop (202 with loop_id)
/api/agents/{name}/loopsGETList the agent's loops
/api/loops/{loop_id}GETLoop status, per-run summaries, last response
/api/loops/{loop_id}/stopPOSTGraceful stop (current iteration finishes)

Start-loop request body

message (required), max_runs (1–100, required), and optional stop_signal, delay_seconds, timeout_per_run, max_duration_seconds (wall-clock deadline), max_cost_usd (> 0; total USD budget), model, and allowed_tools.

The cost budget and the deadline are both iteration-boundary stops — checked between runs, so the current run always finishes (one run, including the first, can overshoot).

The loop's stop_reason is one of max_runs_reached, stop_signal_matched, user_stopped, deadline_exceeded, budget_exhausted, error, or interrupted. GET /api/loops/{loop_id} also returns max_cost_usd and total_cost (sum of per-run cost, 0.0 for a zero-run loop).

GET

/api/agents/:name/loops

List the agent's loops.

NameTypeRequiredDescription
statusstringNoFilter by loop status
limitintegerNoMax results

VoIP

Outbound phone calls — flag-gated, off by default.

EndpointMethodDescription
/api/agents/{name}/voipGET/PUT/DELETEVoice binding status / configure / remove (owner)
/api/agents/{name}/voip/callPOSTPlace an outbound call (rate-limited, daily-capped; accepts Idempotency-Key)

Shared Folders

EndpointMethodDescription
/api/agents/{name}/foldersGET/PUTFolder config
/api/agents/{name}/folders/availableGETMountable folders
/api/agents/{name}/folders/consumersGETConsuming agents
GET/PUT

/api/agents/:name/folders

Get or update the shared folder configuration for an agent.

GET

/api/agents/:name/folders/available

List folders available for mounting (published by other agents).

GET

/api/agents/:name/folders/consumers

List agents that are consuming this agent's shared folders.

Bulk / Fleet Operations

EndpointMethodDescription
/api/agents/context-statsGETAll agents context stats
/api/agents/autonomy-statusGETAll agents autonomy
/api/executionsGETPaginated fleet execution list
/api/executions/statsGETFleet execution stat cards (windowed by hours; live running/queued counts)
GET

/api/agents/context-stats

Get context window usage statistics for all agents at once.

GET

/api/agents/autonomy-status

Get autonomy mode status for all agents at once.

GET

/api/executions

Paginated fleet execution list.

NameTypeRequiredDescription
statusstringNoFilter by execution status
triggered_bystringNoFilter by trigger source
hoursintegerNoTime window filter
agentstringNoFilter by agent name
searchstringNoText search filter
GET

/api/executions/stats

Fleet execution stat cards. Windowed by hours; includes live running/queued counts.

Agent-Internal

EndpointMethodDescription
/api/agents/{name}/heartbeatPOSTLiveness heartbeat posted by the agent container every 5s

The heartbeat endpoint is authenticated with the agent's own agent-scoped MCP key. Not for external callers.

Idempotency

Execution-triggering endpoints accept an optional Idempotency-Key header for safe retries — see Chat API → Idempotency.

Agent Model

FieldTypeDescription
namestringUnique agent name
typestringAgent type (default: "business-assistant")
statusstringrunning, stopped, or exited
portintegerSSH port for the agent container
createddatetimeISO 8601 creation timestamp
runtimestring"claude-code" or "gemini-cli"
resourcesobjectCPU and memory limits, e.g. {"cpu": "2", "memory": "4g"}
templatestring?Template used for initialization
container_idstring?Docker container ID

Error Responses

StatusMeaning
401Invalid or missing JWT token
403Permission denied (not owner/admin, or system agent)
404Agent not found
500Server error (e.g. Docker failure)