Skip to main content

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_id and its members on your server.
  • Send X-SP-End-User with the member’s id on every call made for that member. Each member’s conversations are then their own threads on the shared agent.
Create the agent when a user creates a knowledge base, then poll GET/v2/agents/ until status is ready:
Everything one member adds to a shared knowledge base can be answered back to every member. Say so in your app when a user shares a knowledge base or adds content to one.

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 until committed before 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.
Formats and size limits are in Files.

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 with observe, 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.
If you include an assistant’s replies, give them their own 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

What goes wrong

Your server decides who opens which knowledge base. One service-account key reaches every public agent in its project. Never accept an agent_id from the client without checking it against the member list on your server. Without that check, one user can read another’s knowledge base by changing an id.
  • X-SP-End-User treated 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