Agents and runs

Agent specs, the three ways to use an agent, pauses for people, and how a run ends.

Next release

The runtime operations (sessions, messages, runs and approvals) are defined in the contract and answer 501 not_implemented until the agent runtime ships. The shapes below are final for contract 0.5.0.

Agent specs

An agent is data, not code: a spec stored in Sparq and published in a Release. Required fields are name, version, job, who_can_use, model (a model class) and instructions. Optional fields include:

  • mode: react (default), deep, research, workflow or loop;
  • tools and skills: what the agent may call, and know-how loaded only when relevant (a skill never grants a tool);
  • knowledge: the collections the agent may search;
  • limits: model calls, tool calls, delegation depth and run time;
  • approvals: which actions wait for a person;
  • tests: what a new version must pass before it can be published.

loop mode runs Discover, Plan, Execute, Verify, Iterate, and the verifier is never the agent that did the work.

Three ways to use an agent

PatternCallsYou get
Chat panelPOST /v1/sessions, then POST /v1/sessions/{id}/messagesA stream of events per message
Action buttonPOST /v1/runs with "wait": trueOne typed result matching the agent's output
Background jobPOST /v1/runs, then GET /v1/runs/{id}/streamThe run's stream, from any process
curl -X POST "$SPARQ_API_URL/v1/runs" \
  -H "Authorization: Bearer $USER_TOKEN" -H "Content-Type: application/json" \
  -d '{ "agent": "ticket-triage", "input": { "ticket_id": "T-1042" }, "wait": true,
        "idempotency_key": "triage-T-1042-1" }'

Send an idempotency_key (8 to 128 characters) with runs and messages so a retried request does not start a second run.

Pauses

A run can stop to ask a question or to request an approval, then resume later, in any process. Writes and destructive actions always wait for a person.

# Answer a question
curl -X POST "$SPARQ_API_URL/v1/runs/$RUN_ID/resume" \
  -H "Authorization: Bearer $USER_TOKEN" -H "Content-Type: application/json" \
  -d '{ "question_id": "'$QUESTION_ID'", "choice": "annual" }'

# Decide an approval: approve, reject, or edit the arguments first
curl -X POST "$SPARQ_API_URL/v1/approvals/$APPROVAL_ID" \
  -H "Authorization: Bearer $USER_TOKEN" -H "Content-Type: application/json" \
  -d '{ "decision": "approve", "comment": "Refund confirmed with the customer" }'

How a run ends

RunStatus is a closed set. queued, running and awaiting_input are in progress; the rest are terminal:

StatusMeaning
completedFinished with an output
cancelledCancelled by a caller
limit_hitReached a run limit (model calls, tool calls, depth or time)
budget_exceededA hard budget stopped it
tool_unavailableA required tool could not be reached
verify_failedThe verify step rejected the result
awaiting_input_expiredNobody answered a question or approval in time
errorFailed for another reason; the error field holds a problem object

On this page