Skip to navigation

Knowledge

Add sources to an agent's library and publish them for use in calls.

Summary

Knowledge gives an agent content to answer from: web pages, text you send and uploaded documents. This guide adds a workspace source and an agent-owned source, links the workspace source into the agent’s library, waits for the sources to be ready and publishes the agent, which freezes the library’s content for new calls. It does not cover the rest of the draft or explicit snapshots; see Build and publish an agent and Deprecations.

Facts

ItemValue
OperationscreateKnowledgeSource, createAgentKnowledgeSource, addAgentKnowledgeSource, getKnowledgeSource, getAgentDraft, publishAgent
PathsPOST /knowledge/sources, POST /agents/{agent_id}/knowledge/sources, PUT /agents/{agent_id}/knowledge/sources/{source_id}, GET /knowledge/sources/{source_id}, GET /agents/{agent_id}/draft, POST /agents/{agent_id}/publish
Related operationsuploadKnowledgeSource, uploadAgentKnowledgeSource, listKnowledgeSources, listAgentKnowledgeSources, removeAgentKnowledgeSource, reingestKnowledgeSource, archiveKnowledgeSource, deleteKnowledgeSource
Capabilityknowledge.write for source and library changes; config.read for reads; agents.publish for publish
Required headersAuthorization on every request; Idempotency-Key on every write; If-Match on reingest (the source ETag) and on publish (the draft ETag)
Source kindsurl (HTTPS only), text (at most 262,144 characters), file (multipart upload, at most 20 MiB; PDF, plain text, Markdown or DOCX)
Create answer202: ingestion has started and the source is not ready yet
Source statepending, ingesting, ready, failed, archived; an open list
Library relationowned for the agent’s own sources, shared for linked workspace sources
resource_keyOptional, create-only, unique among the workspace’s sources
EnvironmentRASEN_API_BASE (the base URL, ending in /v1), RASEN_API_KEY, AGENT_ID, SOURCE_ID, ETAG
Python3.10 or later, with the httpx package
TypeScriptNode.js 22 or later (built-in fetch)

Steps

Set AGENT_ID to the id of the agent, from listAgents or from the answer of createAgent.

1. Add a workspace source

A workspace source can be linked into the library of any agent of the workspace. The workspace routes need an explicit owner.

curl -sS -X POST "$RASEN_API_BASE/knowledge/sources" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"kind": "url",
"name": "Clinic FAQ",
"url": "https://clinic.example.com/faq",
"owner": {"type": "workspace"},
"resource_key": "kb:clinic-faq"
}'

The answer is 202 with the source. Set SOURCE_ID to its id. A URL that is not a permitted public address is not refused at once: the source later reads state: failed with failure: outbound_destination_refused. To upload a file, send it as multipart to POST /knowledge/sources/upload.

2. Add an agent-owned source

An agent-owned source joins that agent’s library at once and never becomes usable by another agent. The agent routes fix the owner by the path and refuse owner fields in the body.

curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/knowledge/sources" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"kind": "text", "name": "Parking notes", "text": "Parking is free after 6 pm.", "resource_key": "kb:parking:v1"}'

The answer is 202 with the source. To upload a file for the agent, send it as multipart to POST /agents/{agent_id}/knowledge/sources/upload.

curl -sS -X PUT "$RASEN_API_BASE/agents/$AGENT_ID/knowledge/sources/$SOURCE_ID" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"

Linking is set membership: linking a linked source changes nothing. It accepts a workspace source or the agent’s own source, never a source that another agent owns. To unlink a workspace source, send DELETE to the same path with a new Idempotency-Key. Unlinking never deletes content or changes a published version, and an agent’s own source cannot be unlinked: delete or archive the source instead.

4. Wait for the sources to be ready

Read each source until its state is ready. A read never starts ingestion.

curl -sS -i "$RASEN_API_BASE/knowledge/sources/$SOURCE_ID" \
-H "Authorization: Bearer $RASEN_API_KEY"
stateMeaningWhat to do
pending, ingestingIn progressRead it again later.
readyUsable for publication as retrieval data or bounded prompt contextKeep it in the agent library and publish.
failedIngestion failed; failure names a registered reasonInspect the failure; reingest an eligible URL source, or replace text or file content with a new source.
archivedExcluded from new publicationExisting published versions keep working.

state is an open list: treat a value you do not know as unknown, never as success.

5. Publish knowledge

The agent’s direct library determines the next publication’s knowledge. Read the draft for its current publication ETag, then publish with it. Library membership and source state or revision changes all change that ETag.

ETAG=$(curl -sS -D - -o /dev/null "$RASEN_API_BASE/agents/$AGENT_ID/draft" \
-H "Authorization: Bearer $RASEN_API_KEY" \
| awk -F': ' 'tolower($1)=="etag"{print $2}' | tr -d '\r')
curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/publish" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "If-Match: $ETAG"

Publication freezes the library’s content automatically, as retrieval data or bounded prompt context. Library changes and source refreshes take effect in calls after you publish again; existing published versions never change, and calls already running keep their knowledge. See Build and publish an agent for what else a publish freezes.

Rules

  • MUST wait for each library source to be ready before you publish, and resolve a failed source first.
  • MUST read the draft again after a library or source change, and validate or publish with the new ETag.
  • MUST send the source’s ETag in If-Match on reingest.
  • MUST NOT link a source that another agent owns, or an archived source.
  • MUST archive, not delete, a source that a retained snapshot or published version cites.
  • Every source has a fixed owner, chosen when it is created and never changed. Ownership decides which agent may select a source; it is not a permission. Access follows the key’s capabilities.
  • An archived agent refuses library changes and agent-owned source creation with 409 agent_archived.
  • Legacy draft knowledge fields (retrieval_snapshot_id, fallback_source_ids) do not select the knowledge used by publication, and do not block unlinking, archive or delete. See Deprecations.

The agent library

GET /agents/{agent_id}/knowledge/sources lists the agent’s library. Each item has a relation: owned for the agent’s own sources, shared for workspace sources linked into the library. Archived sources are left out unless you ask for state=archived.

OwnerCreated withWho can use it
The workspacePOST /knowledge/sources or /upload with owner workspaceAny agent of the workspace, once the source is linked into that agent’s library
One agentPOST /agents/{agent_id}/knowledge/sources or /upload, or the workspace routes with owner agentThat agent only. It joins that agent’s library at once and never becomes usable by another agent.

Reingest

POST /knowledge/sources/{source_id}/reingest creates a new ingestion revision and answers 202. It takes the source’s ETag (from step 4) in If-Match and a new Idempotency-Key. Existing published versions keep their knowledge, and a state or revision change to a library source changes the publication ETag of each agent that uses it. Reingest keeps ownership: an agent-owned source never becomes usable by another agent.

Archive or delete

Two commands take a source out of use. Choose by whether anything still needs its content.

POST /knowledge/sources/{source_id}/archiveDELETE /knowledge/sources/{source_id}
EffectHides the source from ordinary lists and new selection; keeps its contentPermanently deletes the source, removes it from every agent library and cancels pending ingestion
Snapshots, published versions and call evidence that cite itKeep their revisions and keep workingMust not exist: the delete is refused
Name and resource_keyStay takenFreed by the delete
Repeating itArchiving an archived source returns it unchangedDeleting an absent source is 404 not_found

References are checked inside the same operation, so a publish and a delete cannot race. Delete takes no If-Match. An archived source can still be listed with state=archived.

Resource keys

Archiving keeps a source’s resource_key taken; deleting frees it. A resource_key filter on a list finds the source whatever its owner or state, archived included. See Resource keys.

Verify

curl -sS "$RASEN_API_BASE/agents/$AGENT_ID/knowledge/sources" \
-H "Authorization: Bearer $RASEN_API_KEY"

Expected output after step 4: both sources in items, the linked one with "relation": "shared" and the agent’s own one with "relation": "owned", each with "state": "ready".

{"items": [{"relation": "shared", "source": {"id": "kb_01j00000000000000000000000", "name": "Clinic FAQ", "state": "ready"}}, {"relation": "owned", "source": {"id": "kb_01j00000000000000000000001", "name": "Parking notes", "state": "ready"}}], "next_cursor": null}

Errors

CodeCauseFix
conflict (reason: name_taken)Another source has this name.Use another name, or find the source with a resource_key filter.
resource_key_conflictAnother source has this resource_key. details.existing_id names it.Read that source instead of creating it again.
conflict (reason: source_not_eligible)You linked a source that another agent owns, or an archived source.Link a workspace source, or create an agent-owned source.
revision_requiredReingest without If-Match.Read the source and send its ETag.
conflict (reason: stale_revision)The source changed since you read its ETag.Read the source again and reingest with the new ETag.
conflict (reason: not_reingestable)The source cannot be reingested.Create a new source with the new content.
deletion_blocked (reason: snapshot_reference or published_reference)A retained snapshot or published version cites the source.Archive the source instead.
draft_conflictThe library or a source changed since you read the draft ETag.Read the draft again and publish with the new ETag.
agent_archivedThe agent is archived.Unarchive it first (Archive and restore an agent).
not_foundThe source or agent does not exist.Check SOURCE_ID and AGENT_ID.