Agent API
API endpoints for listing agents, retrieving agent details, and performing agent actions like suspend, resume, restart, and set autonomy level.
Agent API
Manage the lifecycle of CodeSpar agents. Each project has a persistent Project Agent and may spawn ephemeral agents (Task, Review, Deploy, Incident) as needed.
List All Agents
Retrieve all agents in the current context.
Request
With multi-tenant scoping:
Response
Response Schema
| Field | Type | Description |
|---|---|---|
id | string | Unique agent identifier |
type | string | Agent type: project, task, review, deploy, incident, coordinator |
status | string | Current state: ACTIVE, IDLE, SUSPENDED, ERROR |
autonomyLevel | number | Current autonomy level (0–5) |
projectId | string | Linked project ID (if applicable) |
uptime | number | Seconds since agent started |
lastActivity | string | ISO 8601 timestamp of last activity |
channels | string[] | Connected channels (project agents only) |
task | string | Current task description (task agents only) |
Get Agent Details
Retrieve detailed information about a specific agent.
Request
Response
Response Schema
Includes all fields from the list endpoint, plus:
| Field | Type | Description |
|---|---|---|
project | object | Linked project details |
project.id | string | Project identifier |
project.name | string | Project display name |
project.repo | string | GitHub repo (owner/name) |
project.defaultBranch | string | Default branch name |
stats | object | Aggregate statistics |
stats.messagesProcessed | number | Total messages handled |
stats.tasksCompleted | number | Coding tasks completed |
stats.reviewsPerformed | number | PRs reviewed |
stats.deploysTriggered | number | Deployments triggered |
stats.incidentsHandled | number | Incidents investigated |
memory | object | Memory/vector store usage |
memory.embeddings | number | Number of stored embeddings |
memory.storageMB | number | Storage used in megabytes |
Error Response
Perform Agent Action
Execute an action on a specific agent: suspend, resume, restart, or change autonomy level.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
action | string | Yes | One of: suspend, resume, restart, set_autonomy |
params | object | Depends | Additional parameters (required for set_autonomy) |
params.level | number | For set_autonomy | Autonomy level (0–5) |
Suspend an Agent
Pause all agent activity. The agent stops processing messages and events but retains its state.
Response:
Resume an Agent
Resume a suspended agent. It will begin processing queued messages and events.
Response:
Restart an Agent
Stop and restart an agent. This clears in-flight tasks and reloads configuration.
Response:
Set Autonomy Level
Change the agent's autonomy level. See Graduated Autonomy for details on each level.
Response:
Error Responses
Invalid action:
Invalid autonomy level:
Agent not found:
Create an Agent
Create a new agent programmatically.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name for the agent |
type | string | Yes | Agent type: project, task, review, deploy, incident, coordinator |
projectId | string | No | Project to link (required for project agents) |
autonomyLevel | number | No | Initial autonomy level (0-5, default: 1) |
Request
Response
Delete an Agent
Remove an agent. Active agents are stopped before removal. Ephemeral agents are cleaned up automatically, but this endpoint can be used for immediate removal.
Request
Response
Error Response
List Agent Types
Retrieve all registered agent types, including custom types added via the plugin registry.
Request
Response
Agent State Persistence
Agent state changes (suspend, resume, autonomy level updates) are automatically persisted to disk. This means agent states survive server restarts without manual intervention.
How It Works
- When an agent action is performed (suspend, resume, set_autonomy), the new state is saved immediately
- State is stored in
.codespar/agent-states.jsonin the working directory - On server startup, the agent supervisor reads this file and restores each agent to its last known state
- If the file does not exist (first run), agents start with their default state (ACTIVE, L1)
Storage Format
Each entry in agent-states.json follows the AgentStateEntry type:
Example File
Notes
- The file is written atomically (write to temp file, then rename) to prevent corruption on crash
- Agents that no longer exist in the registry are ignored during restore
- State persistence applies to all agent types (project, task, review, deploy, incident, coordinator)
Next Steps
- Audit API -- Query the audit trail
- Project API -- Manage project links
- Graduated Autonomy -- Understand autonomy levels