Docs / How it works

The knowledge loop: answer, gap, report, KB fix, import

Status: in use from 2026-11-14 (owner ask, the owner's instance docs). Skills: triage-mail, bulk-drafts (read and report), kb-review (merge and propose), knowledge-import (index; one-time migration). Shared rules for the agent: skills/triage-mail/references/kb-gaps.md. Background: doc 16 (projects, knowledge, knowledge_search).

1. The loop

The knowledge base is the folder projects/<slug>/knowledge/files/: Markdown entries edited by hand, indexed locally and searched with knowledge_search. The agent answers only from it. It never reads Notion or any other source for a fact. In an attended session it reads and edits the entry files directly too (owner, 2026-11-24; skills/README.md, "Reading and writing files"): it checks brands: itself, and opens a fact it states with knowledge_get, because the evidence ledger credits only the tools until P140.

client mail -> draft needs a fact
   1 knowledge_search (local index)   usable hit: state it
   2 nothing usable                   [Owner: ...] in the draft, no invented fact
        |
        v  every miss, stale hit, conflict, repeated question, placeholder
   gap record -> reports/kb/YYYY-MM-DD-<run>.md   (local disk)
        |
        v  "что улучшить в базе знаний X"  (kb-review)
   merged, ranked list + draft entries   (owner supplies the facts)
        |
        v  the owner, or the agent on his word, adds or fixes the entry files (approval is his), reindex
   the next run finds the fact

The loop closes with the owner: the agent writes or edits an entry only on his word and always as approved: false unless he approved it in that session; it never approves one. After the edit the server refreshes the index by itself (file change and server start, P140 K1); hub knowledge index <slug> does it by hand.

2. Order of sources for a fact

  1. knowledge_search (bound to the project); in a knowledge.scope by-brand project also brand = the brand of the mail (message_show), or ANY for an unbranded mail (doc 16 section 5, "Brands"). Usable only with use: STATE, approved: true, expired: false. A draft that used an entry of another brand gets the red safety result fact_other_brand at draft_write's record. Freshness is judged from the local entry: a valid_until that is near or passed, an old last_confirmed, or a contradiction by the mail or the client's profile makes the hit stale (a gap is recorded; the fact is stated only while it is still usable).
  2. Nothing usable: a [Owner: ...] placeholder. The agent never invents, never answers from memory, never promotes a figure from a client's mail to a fact.

Notion is not a source. An old Notion Knowledge database is migrated into files once (knowledge-import) and then ignored; the index is rebuilt from the files, so a fact the owner just added is found as soon as the index is refreshed.

3. Gap types

Per-client rule (P28): every reply, in a batch of any size, is written after reading that client's own thread and Notion profile (skills/triage-mail/references/per-client.md); the owner's purpose and tone are a brief, never a body.

type meaning
missing no usable entry anywhere
stale exists but expired, past review, or contradicted by newer evidence
conflict two entries, or an entry and project.md or our earlier reply, disagree; the agent states neither
repeated-question the same question from two or more clients in a run (kb-review: across runs); the fix may be phrasings or a clearer title
profile-empty the client's Notion record was empty or absent when the reply was written (the draft rests on the thread alone); proposal names profile fields, not a Knowledge entry
placeholder a [Owner: ...] that the other types do not explain; may need no KB entry (a per-client decision)

Priority: high (a draft is blocked on a price, date, term or policy, or a conflict could produce a wrong statement), medium (stale, repeated, a missing answer that blocked nothing), low (background). Three or more clients rise one level.

4. Report format

One markdown file per run: front matter (project, date, run, window, gaps), a table (id | type | topic | seen | priority), then one block per gap with seen, tried, proposal, priority. Exact template and field rules: kb-gaps.md sections 3 and 4. proposal is a Knowledge page in outline: Question, Audiences, Category, Kind, Use, Phrasings, answer outline; a fact the agent does not have is owner to supply. kb-review writes review-YYYY-MM-DD.md in the same folder.

Triage prints a block "KB: что улучшить" (1 to 5 top gaps, the file path). Chain and bulk print the same block for their own run.

5. Where reports live: the local disk, one path

Owner decision (2026-11-14): agent reports are kept on the local disk only. One home per project, git-ignored:

projects/<slug>/reports/
  kb/        KB-gap reports of a run (YYYY-MM-DD-<run>.md, <run> = triage, bulk; -2 for a second run)
             and kb-review summaries (review-YYYY-MM-DD.md)
  problems/  problem reports (the same YYYY-MM-DD-<kind>.md naming)
  runs/      run reports

This document defines kb/; problems/ and runs/ are reserved under the same root so that every agent report has one place. Files are created on demand, only when there is something to report. Notion is not used for them: its Documents of Type Report stay for meeting reports, no skill writes an agent report there, and there is no project setting for it. If the owner asks in a session ("выгрузи в Notion"), the agent makes one page by hand (table and details, no client data); nothing else.

6. Privacy

7. Open owner decisions

Source: @docs/core/18-kb-loop.md