Example use case
Your users create knowledge bases for a project, a research area, or a team. They feed each one documents and selected chats, share it with colleagues, and ask it questions, either in your app or from inside another assistant that uses it as context.Set up
- One project for the app, with a service account that holds the Project admin role, so your code can create agents and delete files and memories. See Set up your organization.
- One agent per knowledge base. Memory never crosses agents, so two knowledge bases never mix. A user can own several.
- Your app decides who opens which knowledge base. Store each knowledge base’s
agent_idand its members on your server. - Send
X-SP-End-Userwith the member’s id on every call made for that member. Each member’s conversations are then their own threads on the shared agent.
/v2/agents/ until status is ready:
Flow 1: add files
Upload files with multipart POST…/observe, with one file part per document and the speaker who uploaded them. Use one uploads thread per knowledge base, or one per member.
- An agent reads one file at a time. Further uploads queue and report
queued. Poll each observation untilcommittedbefore you tell the user the file is ready. - Uploading the same file twice to one agent returns
409 document_already_ingested. It is already learned. - Answers cite the uploaded files, with a download link.
- To replace a document, delete the old file with DELETE
/v2/agents//files/, wait until its memories are forgotten, then upload the new version.
Flow 2: add chats
Users choose which of their chats feed which knowledge base. Each chat becomes its own thread on the agent, so recent context never mixes between chats. Send its messages withobserve, oldest first, each with speaker, speaker_id, and the original timestamp.
- Turn on for a chat: send the chat’s history, then each new message as it happens.
- Share when done: send the whole chat in one go.
- Send one message: a single message or exchange.
speaker, so the knowledge base can tell what a person said from what a model wrote. Send an Idempotency-Key on each request, and wait for committed before you send the next batch to the same agent.
Flow 3: answer questions
With a learning call, the question itself is learned. In a shared knowledge base, every member’s questions then feed the shared memory.
Flow 4: remove content
- A document: DELETE
…/files/removes the file and every memory made from it. - Something a member said: list memories with GET
/v2/agents//memoriesfiltered bythread_idorspeaker_id, then delete the turn with DELETE…/memories/. - A whole knowledge base: DELETE
/v2/agents/. It cannot be undone.
What goes wrong
X-SP-End-Usertreated as a memory boundary: it separates thread lists and rate-limit windows, not memory. Use separate agents for content that must stay apart.- The key in a browser or app bundle: anyone who loads the page can read it. Call Priors from your server only.
Calls used
- Guides: Service accounts, Files, Answering, Memories
- API reference: Create agent, Learn messages or a file, Learn and answer, Recall memories, Delete file, Forget a memory