---
title: "Update a session (status/goal/metadata)"
method: PATCH
path: "/api/agent/sessions/{id}"
tags: ["Agent"]
---

# Update a session (status/goal/metadata)

`PATCH /api/agent/sessions/{id}`

## Request

- Base URL: `http://localhost:38200`
- URL: `http://localhost:38200/api/agent/sessions/{id}`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `token`

## Path parameters

- `id` integer, required

## Request body

- object
  - `status` 'active' | 'paused' | 'completed' | 'stalled' | 'abandoned'
  - `goal` string
  - `metadata` object

## Response `200`

Updated session.

- AgentSession: The `agent_sessions` row (src/db/schema.ts), as returned by boot/session endpoints.
  - `id` integer
  - `tenantId` integer
  - `agentId` integer
  - `workspaceId` integer, nullable
  - `projectId` integer, nullable
  - `goal` string, nullable
  - `role` string, nullable: Inferred at boot from the matched goal node's owner_role.
  - `status` 'active' | 'paused' | 'completed' | 'stalled' | 'abandoned'
  - `parentSessionId` integer, nullable
  - `lastCheckpointId` integer, nullable
  - `handoffContextId` integer, nullable
  - `metadata` object
  - `startedAt` string, date-time
  - `endedAt` string, date-time, nullable

## Other responses

- `400`: Request body/query failed Zod validation.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or not visible to the caller).

---

[API](https://skmtc.dev/contextq/apis/contextq-api.md) · [All operations](https://skmtc.dev/contextq/apis/contextq-api/llms.txt) · [OpenAPI document](https://skmtc.dev/contextq/apis/contextq-api/revisions/7afc44056a22?raw)
