Knowledge API
Repository knowledge inventory, statistics, details, and create, update, and delete for entries and Scene/Agent links.
Knowledge has two types:
- File-based:
source=system/agent, stored by repository + file - Entry-based:
source=manual, entered by users in the console and located byknowledge_id
Read endpoints are dual; session tokens are accepted, but the repository bound to the token must match repo (takeover tko_ sessions read through their bound repository as well). Write endpoints are user_only, and tk_ returns 403.
Endpoints
| Method | Path | Purpose | Authentication |
|---|---|---|---|
GET |
/api/knowledge |
Knowledge inventory | dual |
GET |
/api/knowledge/stats |
Statistics by category | dual |
GET |
/api/knowledge/{knowledge_id} |
Knowledge details | dual |
POST |
/api/knowledge/entry |
Create entry | User-level |
PUT |
/api/knowledge/{knowledge_id} |
Edit entry | User-level |
DELETE |
/api/knowledge/{knowledge_id} |
Delete entry | User-level |
GET |
/api/knowledge/{knowledge_id}/refs |
List links | User-level |
POST |
/api/knowledge/{knowledge_id}/refs |
Add link | User-level |
POST |
/api/knowledge/{knowledge_id}/refs/batch |
Add links in bulk | User-level |
PUT |
/api/knowledge/ref/{ref_id} |
Update link | User-level |
DELETE |
/api/knowledge/ref/{ref_id} |
Delete link | User-level |
"User-level" means a grape_ API key or a web JWT.
GET /api/knowledge
Query
| Parameter | Required | Description |
|---|---|---|
repo |
Yes | Repository; accepts a repo_key or the unprefixed form |
source |
No | system / agent / manual |
page / page_size |
No | Defaults 1 / 50 |
sort |
No | latest sorts by update time in descending order |
q |
No | Matches name and description |
Response
{"repo_key":"<owner>/<repo>","knowledge":[],"total":0,"page":1,"page_size":50}
Each row includes refs and ref_summary, which indicate the enabled and disabled Scene and Agent links.
GET /api/knowledge/stats
Query: repo (required).
Response
{"system":0,"agent":2,"manual":1,"unlinked":0,"content_limit_bytes":5242880,"content_limit_display":"5MB"}
GET /api/knowledge/{knowledge_id}
Returns the full knowledge object, including content and the link summary. Returns 404 if it does not exist.
POST /api/knowledge/entry
Creates a manual entry.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Name, ≤50 characters |
content |
string | Yes | Body, ≤5MB by default |
repo |
string | Yes | Owning repository |
description |
string | No | Description, ≤200 characters |
agent_type |
string | No | Linked Agent type |
scene_ids |
array | No | Bind Scenes in bulk |
agent_types |
array | No | Bind Agent types in bulk |
Response
{"ok":true,"message":"Knowledge created","file_path":"...","id":1}
PUT /api/knowledge/{knowledge_id}
Only source=manual entries are editable.
Request body: name (required, ≤50), content (required), description (optional, ≤200).
Response: {"ok":true,"message":"Knowledge updated"}.
DELETE /api/knowledge/{knowledge_id}
Only source=manual entries created by the current user can be deleted. Response {"ok":true,"message":"Knowledge deleted"}.
Link endpoints
| Endpoint | Request body | Description |
|---|---|---|
POST /refs |
{scene_id, agent_type} |
Add one link |
POST /refs/batch |
{scene_ids:[], agent_types:[]} |
Add in bulk; existing links are skipped |
PUT /ref/{ref_id} |
{enabled: bool} |
Enable or disable a link |
DELETE /ref/{ref_id} |
— | Delete a link |
The bulk add response includes the added count.
Common errors
| Status | Cause |
|---|---|
| 400 | Missing repo / name / content, or a value is too long |
| 403 | Repository scope mismatch; system-generated knowledge is not editable; not the creator |
| 404 | Knowledge entry or link does not exist |
| 409 | The knowledge entry is already bound to this Scene or Agent |
Related
Scenes and engine configuration | Agents in detail | Authentication and credentials