The knowledge-base website

A bot's knowledge/ directory has two readers. The model searches it. People read it as a website, generated from the identical files and served by the same Worker as the bot — one deployment, one hostname, one thing to keep current.

GET  https://acme-bot.example.com/pricing/plans.html   the article
POST https://acme-bot.example.com/slack/events         the bot

That works because Cloudflare serves a matching static asset before the Worker runs. A webhook path matches no file, so it falls through to the bot. Nothing routes it by hand.

Building it

pnpm site bots/acme-support

writes bots/acme-support/site/, which the bot's wrangler.jsonc points at:

"assets": { "directory": "./site", "binding": "SITE", "not_found_handling": "404-page" }

The directory is generated, not edited, and is not committed. pnpm release rebuilds it and ships it inside the package, so a customer deploying the zip gets the documentation along with the bot.

Generating needs a JDK and Maven — the generator is a pinned artifact, the same one behind our other documentation sites, so a bot's knowledge base looks like the rest of them. None of it reaches the Worker, and wrangler dev needs none of it.

Writing for both readers

Directories become sections; a file named after its own directory is that section's front page. See The knowledge base for the frontmatter both readers share.

The rule that matters: write it as documentation, not as bot input. A page that reads as notes-to-a-model reads badly to the person who opens the link, and the bot answers no better for it.

Linking answers to articles

KNOWLEDGE_SITE_URL is the site's public address. Set it and the bot ends answers with a link to the article it quoted:

const tools = knowledgeBaseTools(knowledge, {
  siteUrl: siteUrlFromEnv(conversation.env, conversation.origin),
});

Left unset, the bot falls back to the origin the webhook arrived at — which is the same Worker, so links work on workers.dev with no configuration. Set the variable when the documentation lives on a hostname of its own.

To link to an article from your own code rather than through the model:

import { articleUrl, siteUrlFromEnv } from "@wingman/knowledge-base";

const doc = await knowledge.read("pricing/plans.md");
const url = articleUrl(doc?.href ?? null, siteUrlFromEnv(conversation.env, conversation.origin));

articleUrl returns null when the deployment has no site, so a bot that is not publishing one simply answers without links.

Try it: How do I deploy a bot? — the answer ends with a link to the article it came from.

Asking the bot from a page

Every page of the site carries the chat panel, so an article can let its reader watch the bot do what the section describes. In the Markdown, link to the chat with ?ask:

Try it: [How do I deploy a bot?](/chat?ask)
[Ask about deploying](/chat?ask=How%20do%20I%20deploy%20a%20bot%3F)

A bare ?ask asks the link's own words; a value asks that instead. pnpm site marks every such link so a click asks the question in the panel on the page, and the link itself still opens the full-page chat for a reader the panel does not reach — a new tab, no JavaScript. The bot reads the same link as a link, and it is not a document, so it never counts as a broken one. Put these links under a section heading rather than in an article's opening paragraphs: those are what a menu button quotes into chat, where there is no panel to ask in.

Any page of your own application can carry the panel too, and ask the bot a question for the reader — mark a link with the question it should ask:

<a href="#chat" data-wingman-ask="How do I change my plan?">Ask the bot about plans</a>

A click opens the panel and sends the question as though the reader typed it; data-wingman-open opens the panel without asking anything. A page with its own JavaScript drives the panel through wingman(…) — wingman("send", "…"), wingman("setDraft", "…"), wingman("on", "message", …), wingman("setTheme", "dark"), wingman("configure", { strings: { title: "Billing help" } }) to fit the panel's colours and words to the page — documented in full in the @wingman/embed package's README, under The API.

Explaining terms

A reader who selects text containing a term the site defines sees, beside the article, what the term means and a link to the page that explains it. The terms live in knowledge/_dictionary.json; each article has a companion file (slack.json beside slack.md) saying where it mentions which of them. Neither file is published as it is, and neither reaches the bot.

You do not write offsets by hand. Have the configured model propose terms for the articles that have none yet, and mark every mention:

pnpm dictionary bots/acme-support

A description that reads wrong is fixed by editing _dictionary.json — the command keeps what you wrote, and only --refresh asks the model to reword known terms. A term's wordings list is what gets marked; remove a wording, or the whole term, and its marks go. After editing an article, move the marks to where the words now are with --no-model; --check only reports what is out of date.

Appearance

knowledge/_template.md configures the whole site — colours for light and dark, favicon, theme behaviour, default metadata. It is frontmatter only, and it is a partial: files whose name starts with _ never become knowledge the model can retrieve.

Related: The knowledge base, Deploying a bot.

← The knowledge baseRecording what people ask →