Skip to content

Lessons API

Manage agent lessons — distilled insights and knowledge learned from agent experience.

POST /api/lessons

Create a new lesson.

Request Body

json
{
  "title": "Always run tests before deploying",
  "content": "Running the full test suite before deployment catches 90% of regressions. Skip at your peril.",
  "category": "deployment",
  "importance": "high",
  "agentId": "my-agent",
  "context": { "trigger": "deployment failure" },
  "sourceSessionId": "ses_abc123",
  "sourceEventId": "01HXYZ..."
}
FieldTypeRequiredDescription
titlestringLesson title
contentstringLesson content / body
categorystringCategory (default: general)
importancestringlow, normal, high, critical (default: normal)
agentIdstringAgent ID to scope the lesson to
contextobjectAdditional context metadata
sourceSessionIdstringSession ID where this lesson originated
sourceEventIdstringEvent ID where this lesson originated

Response (201)

json
{
  "id": "lesson_abc123",
  "tenantId": "default",
  "title": "Always run tests before deploying",
  "content": "Running the full test suite before deployment catches 90% of regressions.",
  "category": "deployment",
  "importance": "high",
  "agentId": "my-agent",
  "context": { "trigger": "deployment failure" },
  "sourceSessionId": "ses_abc123",
  "accessCount": 0,
  "createdAt": "2026-02-08T10:00:00.000Z",
  "updatedAt": "2026-02-08T10:00:00.000Z"
}

GET /api/lessons

List lessons with optional filters.

Query Parameters

ParameterTypeDefaultDescription
categorystringFilter by category
importancestringFilter by importance level
agentIdstringFilter by agent ID
searchstringText search in title and content
limitnumber50Results per page (max: 500)
offsetnumber0Pagination offset
includeArchivedbooleanfalseInclude archived (deleted) lessons

Response (200)

json
{
  "lessons": [
    {
      "id": "lesson_abc123",
      "tenantId": "default",
      "title": "Always run tests before deploying",
      "content": "Running the full test suite...",
      "category": "deployment",
      "importance": "high",
      "agentId": "my-agent",
      "context": {},
      "accessCount": 5,
      "lastAccessedAt": "2026-02-08T12:00:00.000Z",
      "createdAt": "2026-02-01T10:00:00.000Z",
      "updatedAt": "2026-02-05T15:30:00.000Z"
    }
  ],
  "total": 42
}

GET /api/lessons/:id

Get a single lesson by ID.

Response (200)

Returns the full lesson object (same schema as the create response).

Errors

StatusCause
404Lesson not found

PUT /api/lessons/:id

Update an existing lesson.

Request Body

All fields are optional — only include the fields you want to change.

json
{
  "title": "Updated title",
  "content": "Updated content",
  "category": "security",
  "importance": "critical"
}

Response (200)

Returns the updated lesson object.

Errors

StatusCause
404Lesson not found

DELETE /api/lessons/:id

Archive a lesson (soft delete).

Response (200)

json
{
  "id": "lesson_abc123",
  "archived": true
}

Errors

StatusCause
404Lesson not found

curl Examples

bash
# Create a lesson
curl -X POST http://localhost:3400/api/lessons \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer als_your_key" \
  -d '{
    "title": "Always validate input",
    "content": "User inputs must be validated before processing to prevent injection attacks.",
    "category": "security",
    "importance": "high"
  }'

# List lessons filtered by category
curl "http://localhost:3400/api/lessons?category=security&importance=high" \
  -H "Authorization: Bearer als_your_key"

# Search lessons
curl "http://localhost:3400/api/lessons?search=deployment%20best%20practices" \
  -H "Authorization: Bearer als_your_key"

# Get a specific lesson
curl "http://localhost:3400/api/lessons/lesson_abc123" \
  -H "Authorization: Bearer als_your_key"

# Update a lesson
curl -X PUT http://localhost:3400/api/lessons/lesson_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer als_your_key" \
  -d '{ "content": "Updated content with more detail." }'

# Delete a lesson
curl -X DELETE http://localhost:3400/api/lessons/lesson_abc123 \
  -H "Authorization: Bearer als_your_key"

CLI Usage

bash
agentlens lessons list
agentlens lessons list --category deployment --importance high
agentlens lessons create --title "Always run tests" --content "Run test suite before deploying" --category deployment
agentlens lessons get <id>
agentlens lessons update <id> --content "updated content"
agentlens lessons delete <id>
agentlens lessons search "deployment best practices"

SDK Example

typescript
import { AgentLensClient } from '@agentlensai/sdk';

const client = new AgentLensClient({
  url: 'http://localhost:3400',
  apiKey: 'als_your_key',
});

// Create
const lesson = await client.createLesson({
  title: 'Always run tests',
  content: 'Run the full test suite before deploying.',
  category: 'deployment',
  importance: 'high',
});

// List
const { lessons, total } = await client.getLessons({
  category: 'deployment',
  importance: 'high',
});

// Search
const results = await client.getLessons({ search: 'deployment best practices' });

// Update
await client.updateLesson(lesson.id, { content: 'Updated content' });

// Delete
await client.deleteLesson(lesson.id);

Released under the MIT License.