Agent Runs
An agent run executes a configured agent headlessly — no chat UI, no human at the keyboard. Runs are the programmatic core of NexSpace Headless AI: the same durable path backs API-initiated runs, automations (schedule/event triggers), and thenexspace agents run CLI
command.
Every run requires the agents:run scope on the API key.
Lifecycle
Runs are persisted durably (
headless_agent_runs) — state survives server
restarts and is readable across instances. Orphaned runs are reconciled and old
runs are pruned on a schedule.
Start a run
409 AGENT_BUSY — the one-run-per-agent guard prevents overlapping runs.
Run identity
Each run acts asrunAsUserId, which drives tool scope and RBAC — a run can
never do more than that user is permitted. It defaults to the caller; binding a
different user is restricted to internal operators (otherwise
403 RUN_AS_FORBIDDEN).
Poll, list, and cancel
Stream a run
Stream run events as they happen over Server-Sent Events:id. If the connection drops, reconnect with
a Last-Event-ID header to replay the frames you missed — the same resumable
transport described in MCP.
The CLI does this for you: nexspace agents run 42 --output-format stream-json.
Approvals
When a run invokes a tool that requires approval (see autonomy), it transitions topending_approval and exposes
pendingApprovalIds instead of executing unattended. List the pending actions,
then approve or reject — approving resumes the agent loop, it does not merely
run the one tool.
Autonomy
An agent’s autonomy setting decides what happens on a risky write:require_approval— pause atpending_approvaland wait for a human (or an approver workflow wired to the webhook below).auto_execute— perform the write unattended (use only when the writes are safe to run without review).
Lifecycle webhooks
Subscribe to run lifecycle events instead of polling (see Webhooks):agent_run.pending_approvalagent_run.completedagent_run.failed
See also
- Automations — fire runs on a schedule or business event.
- MCP — the tool layer runs invoke.
- CLI commands —
nexspace agents run.

