---
title: "Record a lesson"
method: POST
path: "/api/agent/sessions/{id}/lessons"
tags: ["Agent"]
---

# Record a lesson

`POST /api/agent/sessions/{id}/lessons`

## Request

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

## Path parameters

- `id` integer, required

## Request body

- object
  - `what_failed` string, required
  - `why` string
  - `try_instead` string
  - `scope` 'session' | 'agent' | 'workspace'

## Response `201`

Created lesson.

- AgentLesson: The `agent_lessons` row — "fail once, not twice". Embedded server-side; the embedding is never serialized in the response.
  - `id` integer
  - `tenantId` integer
  - `sessionId` integer, nullable
  - `agentId` integer
  - `scope` 'session' | 'agent' | 'workspace'
  - `whatFailed` string
  - `why` string, nullable
  - `tryInstead` string, nullable
  - `createdAt` string, date-time

## Other responses

- `400`: Request body/query failed Zod validation.
- `401`: Missing or invalid credentials.

---

[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)
