All pages

Guides

Knowledge

Keep what your agents answer from in step with your own documents.

View as Markdown

A knowledge base is what an agent answers from when a question is about your business: your files, the pages of your website, and topics written in the console. Bases are made and attached to agents in the console; through the API you keep their files up to date and have their websites read again.

Reading needs knowledge:read. Changing needs knowledge:write and a live key: agents answer real callers from these files. A knowledge base belongs to its whole project, so a key limited to some agents cannot reach one.

Find the base

List knowledge bases
#!/bin/sh
# List knowledge bases
curl -sS --fail-with-body -X GET "https://api.aigently.ai/v1/knowledge-bases?project_id=0b1c2d3e-4f5a-6b7c-8d9e-0f1a2b3c4d5e" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"
Add a file to a knowledge base
#!/bin/sh
# Add a file to a knowledge base. With a live key. It is indexed in the background: read it until it says indexed.
curl -sS --fail-with-body -X POST "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY" \
  -F "file=@opening-hours.md;type=text/markdown"

Send one file as multipart/form-data, in a field called file: text, Markdown, CSV, JSON, PDF or Word, with its extension in the name. The answer is 202 with the source, pending. It is indexed in the background, and agents answer from it once it reads indexed:

Read a source's indexing status
#!/bin/sh
# Read a source's indexing status
curl -sS --fail-with-body -X GET "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents/7f9b1d3e-5a7c-4e9f-b1d3-5f7b9d1f3b5d" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"
status What it means
pending Waiting for the indexer.
processing Being read now.
indexed Agents answer from it.
failed It could not be indexed, and error says why.
held A website page waiting for review in the console.

The same bytes twice in one base are refused with duplicate_source. A base holds a set number of sources; past it, a file is refused with source_limit_reached.

Replace a file

Replace a file with a new version
#!/bin/sh
# Replace a file with a new version. It keeps its id; agents answer from the old version until the new one is indexed.
curl -sS --fail-with-body -X PUT "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents/7f9b1d3e-5a7c-4e9f-b1d3-5f7b9d1f3b5d" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY" \
  -F "file=@opening-hours.md;type=text/markdown"

A new version keeps its id and goes back to pending. Agents keep answering from the old version until the new one is indexed. If the new version fails, the old one stays, and error says what went wrong. Only a file can be replaced; a website page changes when the website is read again.

Delete a source

Delete a source
#!/bin/sh
# Delete a source
curl -sS --fail-with-body -X DELETE "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents/7f9b1d3e-5a7c-4e9f-b1d3-5f7b9d1f3b5d" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"

Agents stop answering from it on their next turn.

Everything in a base

List what a knowledge base holds
#!/bin/sh
# List what a knowledge base holds
curl -sS --fail-with-body -X GET "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents?status=failed" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"

Read a website again

Websites are given to a base in the console. Read one again when it has changed:

List the websites a knowledge base reads
#!/bin/sh
# List the websites a knowledge base reads
curl -sS --fail-with-body -X GET "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/crawls" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"
Read a website again
#!/bin/sh
# Read a website again. Pages that have not changed are skipped.
curl -sS --fail-with-body -X POST "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/crawls/8a0c2e4f-6b8d-4f0a-c2e4-6a8c0e2a4c6e/refresh" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY"

Pages that have not changed are skipped, so a refresh costs only what changed. Asking while it is already being read is crawl_running.