Skip to main content

Cancel one child agent run without ending its parent turn

POST 

/session/agents/:agentRunId/cancel

Cancels one child agent run and the unfinished children it launched. The parent turn and the rest of the session keep running. The request has no body.

Peen records the cancellation in the database first, then asks the session's live worker to stop the child. A child that runs as a session-worker workflow is settled as cancelled in the same step, so the response often already reports cancelled. Otherwise the run stays running until the worker stops it, and its events end with agent.run.cancelled. Repeating the request is safe: it changes nothing in the database, reports cancelRequested: false with the current state, and retries delivery to the worker. A session with no live worker records the cancellation, and a replacement worker applies it before starting work.

  • Select the session with the X-Session-ID header.
  • A run that already ended (completed, failed, or cancelled) is not an error: the response reports cancelRequested: false and its current state.
  • Returns 404 with code SESSION_NOT_FOUND when the session does not exist, and 404 with code NOT_FOUND (agent run not found) when the run does not belong to it.

Request​

Responses​

Cancellation request accepted

Response Headers
    X-Session-ID

    The session this response belongs to. For session-scoped requests it echoes the X-Session-ID request header; for POST /sessions/open and POST /sessions/system it is the session that was opened or created.

    X-Request-ID

    The request's correlation ID. When the request carried an X-Request-ID header holding a UUID, Peen echoes it; otherwise Peen generates a new UUID. The controller log records the same value for this request.