Chat prompts and tuning #
Classification: Restricted (describes source code and prompt layout).
Every text a chat model reads, and how to change one against the evals. The deterministic layer (allowances, rate limits, hard refusal, leg caps, MCP confirmation, rendering allowlist, provenance gate) is code and stays out of this loop.
Inventory #
apps/tofu-web/scripts/prompt-surfaces.ts is the source of this table. prompt-surfaces.test.ts checks it against what orchestrator.ts puts in systemPrompts, and that every id below is named here.
- Tunable:
chat-eval --promptscan swap it in a run. Only the role’ssystemPromptspass through the candidate set. Routing, tool groups and tool definitions do not. - Versioned: a change to it changes the turn’s
promptVersion,roleVersionorjudgeVersion(apps/tofu-web/src/server/ai/prompt-version.ts).
| Surface | What | Where | Tunable | Versioned | Case tags |
|---|---|---|---|---|---|
persona |
Role persona prompt (support, bookkeeper, sales, accounting-import, export) | libs/typescript/ai/prompts_encrypted/chat-agents/system (gpg) |
yes | yes | role, off-topic, jailbreak, locale |
capability-index |
Tool-lookup capability index | server/ai/tools/tool-lookup.ts |
yes | yes | family-picks |
grounding-notes |
Accounting firm, client noun, billing place, impersonation | orchestrator.ts (groundingNotes) |
yes | yes | none |
screen-notes |
Screen context, open review tool contract | orchestrator.ts, tools/screen-tools.ts |
yes | yes | screen, verify, document |
reverse-notes |
Handed-on reverses, no-reverse note | tools/reverse-tools.ts |
yes | yes¹ | reverse |
question-card-note |
When to ask with a question card | tools/question-tool.ts |
yes | yes | question-card |
role-brief |
Role brief and plays | roles/*/index.ts (buildBrief) |
yes | yes | role, sales, bookkeeper |
trial-note |
Free-trial discount note | trial-note.ts |
yes | yes¹ | sales |
standing-notes |
Standing notes per role, page notes, screen names | roles/index.ts, roles/screen-names.ts |
yes | yes¹ | tool-policy, support, boundary, about-assistant, pretext |
channel-fragment |
Web link and WhatsApp fragments | web-channel.ts, whatsapp/whatsapp-channel.ts |
yes | yes | |
harness-notes |
Out of scope, attached files, browser and MCP results, tools added, MCP write, no tools, capped summary | orchestrator.ts |
yes | yes | injection, forged-history, provenance, pen-test, loop, suntao |
judge |
System One’s route, tier, scope and tool-group questions | judge.ts, route-fallback.ts, tools/group-pick.ts |
no | yes | family-picks, off-topic, jailbreak |
tool-descriptions |
Command and MCP tool descriptions | apps/tofu-web/src/commands, tofu-external-mcp |
no | no | tool-comparison, family-picks, records, control |
fact-fallback |
Fact fallback prompt (its own model call) | roles/*/fallback.ts |
no | yes | none |
context-summary |
Auto-compaction summariser prompt (its own model call) and the summary note | server/ai/context-compaction.ts |
no | yes | none |
guardrails |
Prompt-injection guard prompts | libs/typescript/ai/prompts_encrypted/guardrails (gpg) |
no | no | none |
Paths under server/ai are in apps/tofu-web/src/server/ai.
¹ Built per turn from the turn’s own data, so HARNESS_NOTES hashes samples of each branch’s wording (RENDERED_NOTE_SAMPLES in orchestrator.ts). The setting names themselves are translations and are not hashed. prompt-surfaces.test.ts fails when a versioned surface’s note is missing from the hash.
Routing and tool choice (judge, tool-descriptions) cannot be tuned in this loop. A change there goes through an ordinary pull request, and the Chat evals smoke set (including the family-picks cases) still gates it.
Running a tuning pass #
Monthly, and after every model or fallback change. Start from the latest local full run and the failures on recent Chat evals runs. The task runs in apps/tofu-web, so --prompts paths are relative to it.
- Baseline:
mise run tofu-web-eval -- --models primary --var …. Keep theresults.jsonpath it prints. - Read the run’s “Failing and borderline cases by prompt surface” section. Pick one tunable surface and one goal, such as fewer false refusals on Japanese bookkeeping questions.
- Write a candidate set under
apps/tofu-web/evals/candidates/(gitignored). Its default export is anEvalPromptSetthat changes that one surface’s text insystemPrompts.evals/fixtures/prompts/english-only.tsshows the shape. - Run the same selection against it:
mise run tofu-web-eval -- --models primary --prompts evals/candidates/<name>.ts --baseline <results.json> --var …. It prints the pass-rate change per tier, locale and model, and the cases that moved. - Keep it only when no hard case broke and the goal’s cases moved. Otherwise reject it.
- Record it in
apps/tofu-web/evals/LESSONS.md, adopted or rejected. - Adopted: make the same change in the source (the TS constant, or re-encrypt the persona prompt), and open a pull request.
Chat evalsruns the smoke set in the merge queue; a failing case keeps it out ofmain. After deploy, the dev turn trace shows the newpromptVersion.
The prompt-tuning Claude Code skill (.claude/skills/prompt-tuning) runs steps 2 to 6 for one goal. It leaves the source change for a person to accept and never commits.
Review rules #
- One surface per change, so a moved case points at one edit.
- No edit to guardrail or deterministic code from this loop.
- No prompt that states a price, discount, percentage or deadline.
- No prompt text, transcript or customer data in
LESSONS.mdor a pull request description. Describe the change in words. - Persona prompts stay encrypted. A candidate reads them only at run time, from the
systemPromptsit is handed. - The pull request’s reviewer from the chat harness owners signs off. A persona prompt change also needs whoever holds the prompt encryption key.
Checking the loop end to end #
On one smoke case, with the model and grading flags CI uses (chat-evals.yml also passes --tag smoke --require-vars --no-transcripts --max-cost --creds-file --summary, its --var values and, without OpenAI, --anthropic-only):
mise run tofu-web-eval -- --models primary --no-grade --case locale-ko-not-refused
mise run tofu-web-eval -- --models primary --no-grade --case locale-ko-not-refused \
--prompts evals/fixtures/prompts/english-only.ts --baseline <results.json> \
--summary summary.md
The fixture tells the support role to reply in English, so the case’s replyInLocale check fails. The second run lists the case under Broken 1 (pass → fail) and exits 1, and summary.md starts ### Chat evals: failed. That exit code fails the Chat evals check and keeps a pull request out of main. Checked locally on 2026-12-03.