{ "openapi": "3.0.3", "info": { "title": "Agent Memory API", "version": "1.0.0-phase3", "description": "Universal AI Agent Memory platform, phases 1-3: memories with revisions and verification, sessions with checkpoints, Markdown/text document ingestion with chunk locators, lexical search and recall, health. Authenticate with `Authorization: Bearer `; the tenant is derived from the key. Anything the caller cannot see is reported as 404. Phase 3: POST /context assembles a budgeted task briefing. Retrieval is hybrid (lexical + embeddings via a local Ollama model and a Qdrant index) and degrades to lexical with a warning. Relevance scores are ranking signals: negated bm25 when lexical, reciprocal-rank-fusion values when hybrid. Learning loop: experiences (POST /sessions/{id}/events), candidates proposed with POST /learn and reviewed by another principal (POST /candidates/{id}/review), evidence (GET /memories/{id}/sources) and feedback on retrieval results (POST /feedback, using the query_id of recall/search/context)." }, "servers": [ { "url": "/api/v1" } ], "components": { "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer" } }, "schemas": { "Error": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" }, "details": { "type": "array", "items": { "type": "string" } }, "request_id": { "type": "string" } } } } }, "RememberRequest": { "type": "object", "required": [ "namespace_id", "type", "title", "content" ], "properties": { "namespace_id": { "type": "string", "format": "uuid" }, "type": { "type": "string", "enum": [ "working", "episodic", "semantic", "procedural", "preference", "decision", "constraint", "lesson", "hypothesis", "goal", "solution" ] }, "title": { "type": "string", "maxLength": 200 }, "content": { "type": "string", "maxLength": 100000 }, "summary": { "type": "string", "maxLength": 2000, "nullable": true }, "tags": { "type": "array", "items": { "type": "string", "maxLength": 64 }, "maxItems": 32 }, "attributes": { "type": "object", "description": "Free-form JSON object, max 16 KB" }, "confidence": { "type": "number", "minimum": 0, "maximum": 1 }, "importance": { "type": "number", "minimum": 0, "maximum": 1 } } }, "RememberResponse": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "revision": { "type": "integer" }, "status": { "type": "string" }, "verification_status": { "type": "string" }, "indexing_status": { "type": "string", "example": "not_indexed" }, "duplicate": { "type": "boolean", "description": "true when an identical active memory already existed (HTTP 200)" } } }, "Memory": { "type": "object", "properties": { "id": { "type": "string" }, "namespace_id": { "type": "string" }, "type": { "type": "string" }, "status": { "type": "string", "enum": [ "active", "retired", "superseded" ] }, "current_revision": { "type": "integer" }, "revision": { "type": "integer" }, "verification_status": { "type": "string", "enum": [ "unverified", "verified", "disputed", "rejected" ] }, "title": { "type": "string" }, "summary": { "type": "string", "nullable": true }, "content": { "type": "string" }, "attributes": { "type": "object", "nullable": true }, "tags": { "type": "array", "items": { "type": "string" } }, "confidence": { "type": "number", "nullable": true }, "importance": { "type": "number", "nullable": true }, "change_reason": { "type": "string", "nullable": true }, "created_by": { "type": "string" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" } } }, "IngestRequest": { "type": "object", "required": [ "namespace_id", "title", "content" ], "properties": { "namespace_id": { "type": "string", "format": "uuid" }, "title": { "type": "string", "maxLength": 200 }, "content": { "type": "string", "maxLength": 262144 }, "format": { "type": "string", "enum": [ "markdown", "text" ], "default": "markdown" }, "source_uri": { "type": "string", "maxLength": 500, "description": "Identifier only; never fetched. The same source_uri in a namespace is one document." } } }, "IngestResponse": { "type": "object", "properties": { "job": { "type": "object", "properties": { "id": { "type": "string" }, "type": { "type": "string" }, "state": { "type": "string" } } }, "document_id": { "type": "string" }, "revision": { "type": "integer" }, "chunk_count": { "type": "integer" }, "unchanged": { "type": "boolean", "description": "true when identical text was already the current revision (no new chunks)" }, "indexing_status": { "type": "string", "example": "lexical_indexed" } } }, "SearchRequest": { "type": "object", "required": [ "query" ], "properties": { "query": { "type": "string", "maxLength": 1000 }, "namespace_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } }, "max_results": { "type": "integer", "minimum": 1, "maximum": 50 }, "detail_level": { "type": "string", "enum": [ "full", "snippet" ] } } }, "RecallRequest": { "type": "object", "required": [ "query" ], "properties": { "query": { "type": "string", "maxLength": 1000 }, "namespace_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } }, "types": { "type": "array", "items": { "type": "string" } }, "tags": { "type": "array", "items": { "type": "string" } }, "max_results": { "type": "integer" }, "detail_level": { "type": "string", "enum": [ "full", "summary" ] }, "verification_filter": { "type": "string", "enum": [ "verified_only", "include_unverified" ], "default": "verified_only" } } }, "VerifyRequest": { "type": "object", "required": [ "result", "method", "revision" ], "properties": { "result": { "type": "string", "enum": [ "verified", "disputed", "rejected" ] }, "method": { "type": "string", "maxLength": 200 }, "notes": { "type": "string", "maxLength": 2000 }, "revision": { "type": "integer", "description": "Must be the current revision" } } }, "SaveStateRequest": { "type": "object", "required": [ "state" ], "properties": { "state": { "type": "object", "description": "Structured working state, max 64 KB" }, "expected_revision": { "type": "integer" } } }, "ContextRequest": { "type": "object", "required": [ "task" ], "properties": { "task": { "type": "string", "maxLength": 2000, "description": "What the agent is about to do; used as the lexical query for decisions, lessons, knowledge and references." }, "namespace_ids": { "type": "array", "items": { "type": "string" }, "description": "Restrict to these namespaces (intersected with what the caller can read)." }, "session_id": { "type": "string", "description": "Include the session's latest checkpoint as working_state. 404 when the session is not visible." }, "include": { "type": "array", "items": { "type": "string", "enum": [ "constraints", "preferences", "decisions", "lessons", "knowledge", "references", "working_state" ] }, "description": "Sections to assemble (default all). Constraints and conflicts are always included." }, "verification_filter": { "type": "string", "enum": [ "verified_only", "include_unverified" ], "default": "verified_only" }, "detail_level": { "type": "string", "enum": [ "full", "summary" ], "default": "full", "description": "summary returns the stored summary (or first 240 characters); constraints are always full." }, "max_context_tokens": { "type": "integer", "minimum": 100, "maximum": 32000, "default": 4000 }, "max_items": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10, "description": "Per-section cap for conflicts, decisions, lessons, knowledge and unverified (preferences: 50)." }, "max_references": { "type": "integer", "minimum": 0, "maximum": 20, "default": 5 }, "format": { "type": "string", "enum": [ "structured" ], "default": "structured" } }, "example": { "task": "Implement a customer repository", "session_id": "", "include": [ "constraints", "decisions", "preferences", "lessons", "references", "working_state" ], "max_context_tokens": 4000 } }, "ContextResponse": { "type": "object", "description": "Sections in budget priority order: constraints (required), working_state, preferences, conflicts, decisions, lessons, knowledge, references, unverified. Memory items carry id, revision, type, namespace_id, title, content|summary, verification_status, content_trust (verified_memory|unverified_memory|disputed_memory), authority (policy for verified constraints), tags, confidence, importance, relevance_score (lexical matches), valid_until, provenance {created_by, updated_at} and token_estimate. References carry chunk/document ids, locator, content and content_trust untrusted_reference.", "properties": { "context_id": { "type": "string" }, "task": { "type": "string" }, "strategy": { "type": "string", "enum": [ "hybrid", "lexical" ], "description": "hybrid when semantic retrieval ran for every section; lexical (with a warning) when it is not configured or unavailable" }, "budget": { "type": "object", "properties": { "max_context_tokens": { "type": "integer" }, "used_tokens": { "type": "integer" }, "counting_method": { "type": "string", "example": "estimate_chars_div_4" }, "complete": { "type": "boolean", "description": "False when not every applicable constraint/preference could be considered; do not treat the briefing as complete." }, "truncated": { "type": "boolean", "description": "True when items were left out to fit the budget." } } }, "omitted": { "type": "object", "properties": { "over_budget": { "type": "integer" }, "over_limit": { "type": "integer" }, "duplicates": { "type": "integer" }, "unverified_excluded": { "type": "integer" } } }, "constraints": { "type": "array", "items": { "type": "object" } }, "working_state": { "type": "object", "nullable": true }, "preferences": { "type": "array", "items": { "type": "object" } }, "conflicts": { "type": "array", "items": { "type": "object" } }, "decisions": { "type": "array", "items": { "type": "object" } }, "lessons": { "type": "array", "items": { "type": "object" } }, "knowledge": { "type": "array", "items": { "type": "object" } }, "references": { "type": "array", "items": { "type": "object" } }, "unverified": { "type": "array", "items": { "type": "object" }, "description": "Only with verification_filter include_unverified." }, "warnings": { "type": "array", "items": { "type": "string" } }, "query_id": { "type": "string", "description": "Pass to POST /feedback to rate an included memory or reference" } } }, "EvidenceInput": { "type": "object", "required": [ "kind", "id" ], "properties": { "kind": { "type": "string", "enum": [ "experience", "chunk", "memory", "document" ] }, "id": { "type": "string", "format": "uuid" }, "role": { "type": "string", "enum": [ "supports", "contradicts", "context" ], "default": "supports" }, "excerpt": { "type": "string", "maxLength": 2000 } } }, "ExperienceRequest": { "type": "object", "required": [ "task", "outcome" ], "properties": { "task": { "type": "string", "maxLength": 2000 }, "outcome": { "type": "string", "enum": [ "success", "failure", "partial", "unknown" ] }, "problem": { "type": "string", "maxLength": 4000 }, "action": { "type": "string", "maxLength": 4000 }, "result": { "type": "string", "maxLength": 4000 }, "environment": { "type": "object", "description": "Free-form JSON object, max 16 KB" } } }, "Experience": { "type": "object", "properties": { "id": { "type": "string" }, "task": { "type": "string" }, "problem": { "type": "string" }, "action": { "type": "string" }, "result": { "type": "string" }, "outcome": { "type": "string" }, "recorded_by": { "type": "string" }, "created_at": { "type": "string" }, "environment": { "type": "object", "nullable": true } } }, "LearnRequest": { "type": "object", "required": [ "namespace_id", "type", "title", "content" ], "properties": { "namespace_id": { "type": "string", "format": "uuid" }, "type": { "type": "string" }, "title": { "type": "string", "maxLength": 200 }, "content": { "type": "string", "maxLength": 100000 }, "summary": { "type": "string", "maxLength": 2000 }, "tags": { "type": "array", "items": { "type": "string" }, "maxItems": 32 }, "confidence": { "type": "number", "minimum": 0, "maximum": 1 }, "target_memory_id": { "type": "string", "format": "uuid", "description": "Propose a new revision of this memory (same namespace and type)" }, "base_revision": { "type": "integer", "description": "Required with target_memory_id: the revision the proposal is based on" }, "evidence": { "type": "array", "maxItems": 20, "items": { "$ref": "#/components/schemas/EvidenceInput" } } } }, "Candidate": { "type": "object", "properties": { "id": { "type": "string" }, "namespace_id": { "type": "string" }, "type": { "type": "string" }, "title": { "type": "string" }, "summary": { "type": "string", "nullable": true }, "content": { "type": "string", "description": "Detail only" }, "tags": { "type": "array", "items": { "type": "string" } }, "confidence": { "type": "number", "nullable": true }, "target_memory_id": { "type": "string", "nullable": true }, "base_revision": { "type": "integer", "nullable": true }, "state": { "type": "string", "enum": [ "proposed", "accepted", "rejected" ] }, "author": { "type": "string" }, "reviewer": { "type": "string", "nullable": true }, "review_notes": { "type": "string", "nullable": true }, "resulting_memory_id": { "type": "string", "nullable": true }, "resulting_revision": { "type": "integer", "nullable": true }, "created_at": { "type": "string" }, "reviewed_at": { "type": "string", "nullable": true }, "content_trust": { "type": "string", "enum": [ "proposed_knowledge" ] }, "evidence": { "type": "array", "items": { "$ref": "#/components/schemas/EvidenceItem" }, "description": "Detail only" } } }, "EvidenceItem": { "type": "object", "properties": { "kind": { "type": "string" }, "id": { "type": "string", "description": "Omitted when available is false" }, "revision": { "type": "integer", "nullable": true, "description": "Target revision pinned when the link was made" }, "available": { "type": "boolean", "description": "False when the target is gone or the caller cannot read it" }, "role": { "type": "string" }, "excerpt": { "type": "string", "nullable": true }, "content_trust": { "type": "string", "enum": [ "evidence", "untrusted_reference" ] } } }, "ReviewRequest": { "type": "object", "required": [ "decision" ], "properties": { "decision": { "type": "string", "enum": [ "accept", "reject" ] }, "notes": { "type": "string", "maxLength": 2000 }, "verify": { "type": "boolean", "default": false, "description": "Accept as verified (records a verification by the reviewer)" } } }, "Sources": { "type": "object", "properties": { "memory_id": { "type": "string" }, "revision": { "type": "integer" }, "current_revision": { "type": "integer" }, "from_candidate": { "type": "string", "nullable": true }, "evidence": { "type": "array", "items": { "$ref": "#/components/schemas/EvidenceItem" } }, "verifications": { "type": "array", "items": { "type": "object", "properties": { "method": { "type": "string" }, "result": { "type": "string" }, "notes": { "type": "string" }, "reviewer": { "type": "string" }, "created_at": { "type": "string" } } } } } }, "FeedbackRequest": { "type": "object", "required": [ "query_id", "result_id", "usefulness" ], "properties": { "query_id": { "type": "string", "description": "query_id returned by recall, search or context" }, "result_id": { "type": "string", "format": "uuid", "description": "Memory id or chunk id from that response" }, "usefulness": { "type": "string", "enum": [ "useful", "not_useful", "incorrect", "harmful" ] }, "comment": { "type": "string", "maxLength": 2000 } } }, "Feedback": { "type": "object", "properties": { "id": { "type": "string" }, "query_id": { "type": "string" }, "target_kind": { "type": "string", "enum": [ "memory", "chunk" ] }, "target_id": { "type": "string" }, "target_revision": { "type": "integer" }, "usefulness": { "type": "string" } } } } }, "paths": { "/remember": { "post": { "summary": "Create a memory", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "Idempotency-Key", "in": "header", "required": false, "description": "Replays the stored response for an identical body; a different body with the same key is 409.", "schema": { "type": "string", "maxLength": 200 } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RememberRequest" } } } }, "responses": { "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RememberResponse" } } } }, "200": { "description": "Exact duplicate (or idempotent replay of a 200)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RememberResponse" } } } }, "400": { "description": "Invalid JSON / body", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "Idempotency-Key reused with a different body", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories": { "get": { "summary": "List memories (newest first)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "namespace_id", "in": "query", "schema": { "type": "string", "format": "uuid" } }, { "name": "type", "in": "query", "schema": { "type": "string" } }, { "name": "status", "in": "query", "schema": { "type": "string", "enum": [ "active", "retired", "superseded", "all" ], "default": "active" } }, { "name": "verification_status", "in": "query", "schema": { "type": "string", "enum": [ "unverified", "verified", "disputed", "rejected" ] } }, { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 } }, { "name": "cursor", "in": "query", "description": "next_cursor from the previous page", "schema": { "type": "string" } } ], "responses": { "200": { "description": "Page of memories", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Memory" } }, "next_cursor": { "type": "string", "nullable": true } } } } } }, "400": { "description": "Invalid cursor", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Invalid filter", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories/{id}": { "get": { "summary": "Get a memory (optionally an older revision)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "revision", "in": "query", "schema": { "type": "integer" } } ], "responses": { "200": { "description": "The memory", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Memory" } } } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } }, "patch": { "summary": "Correct a memory: creates the next revision, unverified", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "If-Match", "in": "header", "required": false, "description": "Current revision number (quoted ETag form accepted). Required unless expected_revision is in the body.", "schema": { "type": "string" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "title": { "type": "string" }, "summary": { "type": "string" }, "content": { "type": "string" }, "tags": { "type": "array", "items": { "type": "string" } }, "attributes": { "type": "object" }, "confidence": { "type": "number" }, "importance": { "type": "number" }, "change_reason": { "type": "string" }, "expected_revision": { "type": "integer" } } } } } }, "responses": { "200": { "description": "New revision", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RememberResponse" } } } }, "400": { "description": "Bad body / revision", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "Memory is not active", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "412": { "description": "Stale revision (ETag header carries the current one)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "428": { "description": "If-Match missing", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } }, "delete": { "summary": "Forget: permanently delete the memory and its revisions (needs delete permission)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Deleted" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories/{id}/retire": { "post": { "summary": "Retire: exclude from ordinary listing", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Retired" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories/{id}/versions": { "get": { "summary": "Revision history, newest first", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Revisions" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/sessions": { "post": { "summary": "Start a session", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "Idempotency-Key", "in": "header", "required": false, "description": "Replays the stored response for an identical body; a different body with the same key is 409.", "schema": { "type": "string", "maxLength": 200 } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": [ "namespace_id", "objective" ], "properties": { "namespace_id": { "type": "string", "format": "uuid" }, "objective": { "type": "string", "maxLength": 2000 } } } } } }, "responses": { "201": { "description": "Started" }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "Idempotency conflict", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/sessions/{id}/state": { "get": { "summary": "Restore the latest checkpoint (revision 0 / state null when none)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Checkpoint; ETag = revision" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } }, "put": { "summary": "Save a checkpoint (If-Match = current checkpoint revision, 0 for the first)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "If-Match", "in": "header", "required": false, "description": "Current revision number (quoted ETag form accepted). Required unless expected_revision is in the body.", "schema": { "type": "string" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SaveStateRequest" } } } }, "responses": { "200": { "description": "Saved; ETag = new revision" }, "409": { "description": "Session closed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "412": { "description": "Stale revision", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "428": { "description": "If-Match missing", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/sessions/{id}/complete": { "post": { "summary": "Complete a session", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "properties": { "outcome": { "type": "string", "maxLength": 4000 } } } } } }, "responses": { "200": { "description": "Completed" }, "409": { "description": "Already closed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories/{id}/verifications": { "post": { "summary": "Record a verification of the current revision (needs the verify permission)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VerifyRequest" } } } }, "responses": { "200": { "description": "Recorded; returns the new verification_status" }, "409": { "description": "Not the current revision", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/recall": { "post": { "summary": "Hybrid recall over active memories (FTS5/bm25 fused with vector similarity by reciprocal rank fusion; lexical only, with a warning, when the embedding provider is off or down). Unverified memories are hidden unless verification_filter=include_unverified", "security": [ { "bearerAuth": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RecallRequest" } } } }, "responses": { "200": { "description": "Ranked results with warnings" }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/ingestion/jobs": { "post": { "summary": "Ingest a Markdown/text document (chunked, indexed)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "Idempotency-Key", "in": "header", "required": false, "description": "Replays the stored response for an identical body; a different body with the same key is 409.", "schema": { "type": "string", "maxLength": 200 } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/IngestRequest" } } } }, "responses": { "201": { "description": "Ingested (new document or new revision)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/IngestResponse" } } } }, "200": { "description": "Unchanged or idempotent replay", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/IngestResponse" } } } }, "400": { "description": "Invalid JSON", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "Idempotency-Key reused with a different body", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/jobs/{id}": { "get": { "summary": "Ingestion job state", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Job" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/documents/{id}": { "get": { "summary": "Document metadata (?include_content=true adds the normalized text)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "include_content", "in": "query", "schema": { "type": "boolean" } } ], "responses": { "200": { "description": "Document" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/chunks/{id}": { "get": { "summary": "One chunk with heading path and source locator (character offsets into the normalized document text)", "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Chunk" }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/search": { "post": { "summary": "Hybrid search over current document chunks (lexical fused with vector similarity; lexical only, with a warning, when the embedding provider is off or down). Results are untrusted reference content", "security": [ { "bearerAuth": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchRequest" } } } }, "responses": { "200": { "description": "Ranked chunks with locators and content_trust" }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/health/live": { "get": { "summary": "Liveness", "responses": { "200": { "description": "Live" } } } }, "/health/ready": { "get": { "summary": "Readiness (database reachable)", "responses": { "200": { "description": "Ready" }, "503": { "description": "Unavailable" } } } }, "/context": { "post": { "summary": "Assemble a token-budgeted task briefing: constraints by scope, working state, preferences, conflicts, hybrid matches and reference passages", "security": [ { "bearerAuth": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContextRequest" } } } }, "responses": { "200": { "description": "Briefing", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContextResponse" } } } }, "400": { "description": "Empty body or invalid JSON", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "session_id not found or not visible to the caller", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed, unsupported_character (code points above U+FFFF), or context_budget_exceeded (the applicable constraints do not fit max_context_tokens; the error also carries required_tokens)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/sessions/{id}/events": { "post": { "summary": "Record an experience (task, problem, action, result, outcome) in an active session", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string", "maxLength": 200 }, "description": "Replays the stored response for a repeated request; 409 if reused with a different body." } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ExperienceRequest" } } } }, "responses": { "201": { "description": "Recorded", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "string" }, "session_id": { "type": "string" }, "outcome": { "type": "string" }, "created_at": { "type": "string" } } } } } }, "400": { "description": "Empty body, invalid JSON or invalid Idempotency-Key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Session not found, or no write permission on its namespace", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "session_not_active (completed session) or idempotency_conflict", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed or unsupported_character", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } }, "get": { "summary": "List the experiences of a session, oldest first (max 200)", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Experiences", "content": { "application/json": { "schema": { "type": "object", "properties": { "session_id": { "type": "string" }, "data": { "type": "array", "items": { "$ref": "#/components/schemas/Experience" } } } } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Session not found or not readable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/learn": { "post": { "summary": "Propose knowledge as a learning candidate (a new memory, or a new revision of target_memory_id at base_revision), with evidence", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string", "maxLength": 200 }, "description": "Replays the stored response for a repeated request; 409 if reused with a different body." } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LearnRequest" } } } }, "responses": { "201": { "description": "Candidate proposed", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "string" }, "state": { "type": "string", "enum": [ "proposed" ] }, "namespace_id": { "type": "string" }, "type": { "type": "string" }, "evidence_count": { "type": "integer" } } } } } }, "400": { "description": "Empty body, invalid JSON or invalid Idempotency-Key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Namespace not found or no write permission", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "idempotency_conflict", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed (unknown type, bad target/base_revision, evidence that is unknown, in another tenant or not readable by the caller) or unsupported_character", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/candidates": { "get": { "summary": "List learning candidates in namespaces the caller can read, newest first", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "namespace_id", "in": "query", "schema": { "type": "string", "format": "uuid" } }, { "name": "state", "in": "query", "schema": { "type": "string", "enum": [ "proposed", "accepted", "rejected" ] } }, { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200, "default": 50 } } ], "responses": { "200": { "description": "Candidates (without content)", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Candidate" } } } } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Bad state or namespace_id", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/candidates/{id}": { "get": { "summary": "One candidate with content and evidence", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "responses": { "200": { "description": "Candidate", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Candidate" } } } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Not found or not readable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/candidates/{id}/review": { "post": { "summary": "Accept or reject a proposed candidate. Needs verify permission; the author cannot review its own candidate without admin. Accepting creates the memory (an identical active memory is reused) or a new revision of the target, copies the evidence and, with verify true, records a verification by the reviewer.", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ReviewRequest" } } } }, "responses": { "200": { "description": "Reviewed", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "string" }, "state": { "type": "string", "enum": [ "accepted", "rejected" ] }, "resulting_memory_id": { "type": "string" }, "resulting_revision": { "type": "integer" }, "verification_status": { "type": "string" }, "duplicate": { "type": "boolean" } } } } } }, "400": { "description": "Empty body or invalid JSON", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "403": { "description": "self_review_not_allowed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Candidate not found or no verify permission", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "409": { "description": "candidate_already_reviewed, stale_candidate (target memory changed since base_revision), target_memory_missing or target_memory_not_active", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/memories/{id}/sources": { "get": { "summary": "Evidence and verifications behind a memory revision. Evidence the caller cannot read is listed with available false and no id.", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "name": "revision", "in": "query", "schema": { "type": "integer", "minimum": 1 }, "description": "Default: current revision" } ], "responses": { "200": { "description": "Sources", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Sources" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "Memory not found or not readable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "revision out of range", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } }, "/feedback": { "post": { "summary": "Rate one result of a recall, search or context call (by its query_id). One rating per principal, query and result; a new rating replaces the earlier one (200). Pinned to the revision that was returned.", "tags": [ "learning" ], "security": [ { "bearerAuth": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FeedbackRequest" } } } }, "responses": { "200": { "description": "Updated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Feedback" } } } }, "201": { "description": "Recorded", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Feedback" } } } }, "400": { "description": "Empty body or invalid JSON", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "401": { "description": "Missing, invalid, revoked or expired API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "404": { "description": "result_not_found: the result was not returned by that query, is gone, or is not readable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "422": { "description": "Validation failed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }, "500": { "description": "Internal error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } } } } }