Skip to main content

Voice Pipeline

Status: Ready

Truth label: Current

Audience: Fleet operator, System designer

Reader outcome: Configure and inspect the voice pipeline: sources, lenses and registers, blending, linting, polish, generation controls, and the pack formats.

Last verified: 2026-09-13

This guide explains how Brain uses your books and your approved writing to shape an answer without training a new model.

The Cortex writing guide covers the implemented draft editor, learning approval, version history, profile editing, and persisted operator default.

The definitions live in a voice pack, a directory of TOML files you supply and name in VOICE_PACK_DIR. The built-in pack ships definitions only and no personal content. Section 11 is the pack format reference.

The main idea is separation:

  • A reasoning lens changes what the model considers.
  • A voice register changes how the answer is expressed.
  • Knowledge retrieval supplies facts and source passages.
  • Voice examples demonstrate delivery patterns only.
  • The output linter enforces safe mechanical rules.
  • Voice polish is an optional local rewrite with exact spans and meaning checks.

This separation lets you combine Sun Tzu reasoning with your own direct voice, or Machiavelli reasoning with a measured voice, without treating a book's prose as your prose.

Response flow​

User message and chat history
|
v
Resolve provider, model, reasoning lens, voice register, and sampling controls
|
+----------------------+----------------------+
| |
v v
Retrieve factual context Retrieve approved
from knowledge and influence books style-only examples
| |
+----------------------+----------------------+
v
Assemble the trusted prompt and clearly marked evidence
|
v
Primary model response
|
v
Protected-span mechanical output linter
|
v
Optional Voice polish with exact spans and meaning review
|
v
Final answer plus generation_settings report

1. Reasoning from PDF, EPUB, and text sources​

For reviewed imports and explicit source inclusion/exclusion, open Sources in Cortex. The influence library supports PDF/EPUB text review, publication, saved selections, and exact passage inspection. Choices apply to both automatic and bound tool retrieval without changing the voice register. The CLI/path workflow below remains available and bypasses extraction review.

Place influence files under the directory named by INFLUENCE_LIBRARY_DIR, which you create at installation with agent influences init, or ingest another path through Cortex Memory or POST /knowledge/ingest. Brain supports text, PDF, and EPUB files.

During ingestion:

  • PDF text is extracted by page. Retrieved passages retain the page number.
  • EPUB text is extracted in book reading order. Retrieved passages retain title, author, chapter, and spine order. EPUB page numbers are not stable across readers, so Brain does not invent them.
  • Plain text and Markdown retain their file source.
  • Image-only books are rejected as requiring OCR.
  • Extracted content is stored as untrusted evidence. A sentence inside a book cannot override the system prompt or issue instructions to Brain.

When a reasoning lens is selected, retrieval favors only the influence sources mapped to that lens. Untagged personal knowledge can still supply relevant facts.

PDF and EPUB duplicates​

If two same-named files differ only by .pdf and .epub, directory ingestion selects the EPUB and reports the PDF as skipped. You do not need to delete either file for correctness. Deleting the duplicate PDF can reduce clutter and storage. Keep both when they are different editions, translations, annotations, or page references you need. Give materially different versions distinct filenames so the ingestion process does not classify them as the same edition.

2. Reasoning lens and voice register​

The two controls are independent.

ControlChangesDoes not change
Reasoning lensThe principles, questions, and retrieved influence sources used for analysisThe facts available in evidence or the required answer format
Voice registerDirectness, pacing, wording, and level of formalityFacts, numbers, citations, quotations, recommendations, or uncertainty

The built-in pack defines the lenses none (reserved), strategic-council, sun-tzu, machiavelli, negotiation, and power, and the registers default (reserved), measured, plainspoken, tactical-calm, realistic-direct, and strategic-direct. Your pack adds its own or shadows any of these by id. GET /chat/influences returns whatever resolved.

The older influence_profile request field still works. It selects a lens and that profile's historical register. New clients should send reasoning_lens and voice_register separately.

Omitting voice_register uses the persisted Cortex operator default, then the configured fallback. The Chat dropdown provides a visible per-page override.

3. How your writing is blended​

Brain has two kinds of voice examples.

Stable examples​

A register may declare exemplars in its pack, as exemplars/<register-id>.toml. Each is an approved example exchange that shows delivery rather than describing it. The built-in pack ships none, so a fresh install has zero until you add them. They are trusted prompt components placed in the SystemMessage above the untrusted <retrieved_context> fence, and they are not searchable factual documents.

Each exemplar declares privacy, which is required and has no default. A local-only exemplar is withheld when the chat provider is not local.

Retrieved examples​

Your own approved writing belongs in the dedicated voice_examples Chroma collection. For each request, Brain can retrieve up to three examples that match the topic and selected register.

Each example records:

  • Topic and response type.
  • The original user message and approved assistant response.
  • Voice register.
  • Approval state.
  • Privacy state: local-only or cloud-allowed.
  • Source label.

Only approved examples are eligible. A local Ollama endpoint can receive both privacy classes. Remote Ollama endpoints and cloud providers require cloud-allowed examples. Format and audience can constrain selection. Studio draft examples also require current canonical approval and a matching revision. The prompt tells the model to copy delivery patterns, never the examples' facts or recommendations.

For the best blend, save short, representative user and response pairs. Include examples of how you explain, disagree, advise, and write casual messages. Do not add a text sample to the factual influence library when its purpose is style only.

The current Cortex UI reports retrieved examples but does not manage them. Use the API to create, approve, update, or delete them.

curl -X POST http://localhost:8081/chat/voice-examples \
-H "Content-Type: application/json" \
-d '{
"topic": "business advice",
"response_type": "recommendation",
"register_id": "your-register",
"user_message": "Should I accept this partnership?",
"assistant_response": "Not yet. Get the decision rights and exit terms in writing first.",
"approved": true,
"privacy": "local-only",
"source": "approved sample"
}'

Management routes:

GET /chat/voice-examples
POST /chat/voice-examples
PUT /chat/voice-examples/{example_id}
DELETE /chat/voice-examples/{example_id}

New examples default to unapproved and local-only unless the request says otherwise. Use cloud-allowed only when you are comfortable sending that sample to the selected cloud model.

4. Mechanical output linting​

The linter runs after the primary model response and is enabled by default. It:

  • Removes known filler openings such as "Certainly" and "Great question".
  • Replaces prose em dash characters with a regular hyphen.
  • Reports banned filler words without guessing at a factual rewrite.

Code blocks, inline code, URLs, Markdown links, citations, quotations, and block quotes are protected. These mechanical rules do not inspect or rewrite their exact text.

The linter has no model call, so it adds no provider latency or token cost.

5. Optional Voice polish​

Voice polish is a second pass through a local Ollama model. It runs after linting, even when the primary response came from a cloud provider.

Modes are:

  • off: never run the revision model.
  • auto: run for any eligible register when lint findings or a low deterministic tone score trigger the gate.
  • always: run for every response under an eligible register.

A register is eligible when its definition sets revision_eligible and it carries delivery instructions to rewrite toward. The neutral default register is not eligible, because there is nothing to rewrite toward. Every built-in register except default is eligible, and a pack sets the flag for its own; GET /chat/influences publishes the flag per register. Eligibility used to be a comparison against one register id, so auto and always were inert for every register but one. Widening it means auto can now trigger a local Ollama call on turns that previously never made one, which costs latency.

The register's own instructions are passed to the revision model as a fenced style description, explicitly demoted to reference text. They are authored as guidance for the generating model, and some of them direct substance rather than delivery, so the editor is told to ignore anything in them that reads like a task and forbidden to add analysis or commentary of its own.

The Cortex Voice polish checkbox opts the current request into always. It does not change the saved environment default.

Before revision, Brain locks exact code, URLs, citations, quotations and numbers. Clause checks reject detected inversions, swapped relationships and lost/added claims. Modality, predicate and sequence uncertainty requires review. Explicit request coverage and format checks prevent new regressions. The optional local verifier can reject a meaning change but cannot override a deterministic flag. Rejected or uncertain candidates keep the linted draft. Cortex shows both texts and records the operator's choice. See polish meaning review for the checks, settings, private cases and known limits.

Polish remains off by default. The 20-case acceptance run found better mechanical compliance in some cases, but added latency and did not consistently improve directness or factual preservation. The recordings now live in the external voice pack; see the acceptance evidence index for their location and the limits of comparisons with later runs.

6. Generation controls and percentages​

Cortex and the API can set provider-aware sampling controls. Brain validates them before sending a request to a provider.

ProviderTemperatureTop-pFrequency penaltySeedMaximum stop sequences
Ollama0 to 20 to 1NoYes4
OpenAI0 to 20 to 1-2 to 2Yes4
Anthropic0 to 1Disabled by Brain policyNoNo4
Google0 to 20 to 1NoYes5

Set temperature or top-p, not both. This keeps one sampling change measurable at a time. Leaving a field blank delegates to the provider default.

The reported percentages have narrow meanings:

  • Temperature percentage is the configured value divided by Brain's supported maximum for that provider. Temperature 0.2 on a 0..2 range reports 10%.
  • Top-p 0.85 reports 85% because top-p uses a 0..1 range.
  • Token percentages are measured input, output, and cache shares when the provider reports usage.
  • Influence-source percentages are each source's share of retrieved influence passages by count.

Reasoning lens and voice register show strength_percent: null. There is no honest causal percentage for how much a prompt instruction influenced sampled text. Brain reports the exact lens, register, example ids, retrieved-source mix, and sampling values instead.

Provider capabilities are available from:

GET /chat/generation-controls

7. Using the Cortex controls​

In the Chat toolbar:

  1. Select the provider and model.
  2. Select a reasoning lens for how Brain should analyze the request.
  3. Select a voice register for how Brain should express the answer.
  4. Enable Voice polish only when the extra local pass is worth the latency.
  5. Open sampling controls if you need temperature, top-p, frequency penalty, seed, or stop sequences.
  6. Send the message.
  7. Expand Generation settings below the answer to inspect what was used.

The report includes provider, model, resolved lens, register, stable and retrieved example ids, retrieval counts, sampling values and normalized percentages, token usage, lint findings, revision decisions and token use, tone score, and assistant prefill status.

Assistant prefill is disabled in production. Current Claude 4.6 and later models are not eligible, and the older provider-specific path has not been enabled in Brain's tool loop.

8. Chat API example​

curl -X POST http://localhost:8081/chat \
-H "Content-Type: application/json" \
-d '{
"message": "How should I handle a supplier who keeps moving the deadline?",
"provider": "ollama",
"model": "qwen3-coder",
"reasoning_lens": "sun-tzu",
"voice_register": "your-register",
"voice_polish": false,
"temperature": 0.2
}'

The regular response includes response, reasoning_lens, voice_register, generation_settings, output_lint, and voice_revision. The final done event from /chat/stream carries the same settings report.

9. Environment defaults​

VariableDefaultPurpose
REASONING_LENSblankIndependent default lens. Blank preserves migration behavior.
VOICE_REGISTERblankIndependent default register. Blank preserves migration behavior.
INFLUENCE_PROFILEnoneLegacy paired default.
VOICE_LINT_ENABLEDtrueEnable protected-span mechanical linting.
VOICE_EXAMPLE_RETRIEVAL_ENABLEDtrueRetrieve approved voice examples.
VOICE_EXAMPLE_LIMIT3Maximum retrieved examples, capped at three.
VOICE_REVISION_MODEoffLocal revision mode: off, auto, or always.
VOICE_REVISION_MODELqwen3-coderOllama model for revision only.
VOICE_REVISION_MIN_SCORE85Auto-mode deterministic tone threshold.
VOICE_REVISION_TEMPERATURE0.2Sampling temperature for the revision pass.
VOICE_VERIFIER_MODEadvisoryMeaning check: off, advisory or required.
VOICE_VERIFIER_MODELblankOptional Ollama checker; blank uses the polish model.

The four revision settings were renamed once; the old spellings are no longer read and the preflight warns if one survives in your .env.

Per-request sampling values override the corresponding environment values. See .env.example for the full application configuration.

10. Storage, audit, and limits​

  • Influence documents and voice examples are persisted in separate Chroma collections under <DATA_DIR>/chroma/.
  • File hashes used for change detection are stored in <DATA_DIR>/file_hashes.json.
  • Per-response provider, token, control, lint, and revision metadata is appended to <DATA_DIR>/chat_usage.jsonl.
  • Chat trace manifests include the resolved generation settings and can be read from GET /chat/turns/{turn_id}/trace.
  • The generation report records settings and measured counts. It does not prove which prompt component caused a phrase.
  • Fact locks protect the optional rewrite. They cannot repair a false claim that the primary model already wrote.
  • Tone controls can make output more consistent with approved writing. They are not a guarantee about third-party AI detectors.

11. Voice pack format reference​

A voice pack is a directory of TOML files. VOICE_PACK_DIR names yours; VOICE_PACKS optionally names extra packs loaded after it. Nothing is discovered by scanning, so a directory does nothing until a setting names it.

TOML specifically, not JSON or YAML. JSON, YAML, and markdown files are all ingestible source extensions, so a manifest in any of them sitting in a content directory would be embedded as an untagged document and surface under every lens. .toml is not in that set, so a manifest is invisible to discovery by construction rather than by a deny-list. tomllib is stdlib at Python 3.11 and rejects duplicate keys natively, so a reviewer approving the first instructions array cannot silently get the last one.

Layout​

voice_pack.toml # the manifest, the only required file
lenses/<id>.toml # reasoning lenses
registers/<id>.toml # delivery registers
exemplars/<register>.toml # approved example exchanges
style/rules.toml # the mechanical style vocabulary

tone/corpus.toml # a tone eval corpus

Only voice_pack.toml is required. A pack that supplies nothing is valid and loads the built-in definitions unchanged.

The manifest​

schema_version = 1
id = "my-pack"
label = "My pack"
description = "Personal lenses and registers."

lenses = ["lenses/close-reading.toml"]
registers = ["registers/plain-direct.toml"]
exemplars = ["exemplars/plain-direct.toml"]
style_rules = "style/rules.toml"
tone_corpus = "tone/corpus.toml"

Every path is resolved inside the pack root. A path escaping the root is a load error, not a warning.

A register, and an exemplar​

# registers/plain-direct.toml
id = "plain-direct"
label = "Plain and direct"
description = "Short sentences. No throat-clearing."
revision_eligible = true
instructions = [
"Lead with the answer, then the reason.",
"Cut hedges that do not change the claim.",
]
# exemplars/plain-direct.toml
[[exemplar]]
id = "plain-direct-01"
category = "advice"
register_id = "plain-direct"
approval_set = "v1"
privacy = "local-only"
user_message = "Should we rewrite the billing service?"
assistant_response = "No. Fix the two slow queries first and measure again."

privacy is required and has no default. local-only is withheld when the chat provider is not local. There is no approved field: approval is the directory being named in VOICE_PACK_DIR, and a pack declaring approved fails to load, because a self-asserted flag inside the artifact it authorizes proves nothing.

Load order and shadowing​

The built-in pack loads first, then VOICE_PACK_DIR, then each entry of VOICE_PACKS in order. A later pack shadows an earlier one by id, last writer wins, and each pack reports what it shadowed in shadowed_ids. That is how you replace a built-in lens rather than only adding to it.

Reserved ids​

none and default are reserved. The rest of the system assumes both exist, so a pack that defines either fails to load rather than silently redefining the neutral case. They are still real definitions you can read; they are just not yours to replace.

Caps and string safety​

A pack is configuration, not a program. Ids match [a-z0-9][a-z0-9-]{0,63}. Lists and string lengths are capped, and every string is checked at load:

  • Control characters and the Unicode separators U+0085, U+2028, U+2029 are rejected, so a value cannot forge a line break inside the assembled prompt.
  • Leading structural markers are rejected, so a value cannot open what looks like a new prompt section.
  • Values are escaped at render, attributes and bodies by their own rules.

A malformed regex in style/rules.toml fails at load, not on the first response that reaches the linter.

The register boundary sentences are not pack-supplied​

The sentences that bar a register from changing facts, numbers, quotations, citations, recommendations, or uncertainty are emitted by Brain, not by the pack, and they are emitted last, after the pack's own instructions. A pack cannot weaken them by ordering, and cannot restate or remove them at all.

Reloading​

POST /voice/reload rebinds the registries from disk without restarting Brain. A degraded load keeps serving the previous definitions and reports the errors in load_errors, which Cortex surfaces in the generation settings panel.

12. Influence pack format​

influence_pack.toml sits at the influence library root and declares how files are tagged. A tag is what lets a reasoning lens retrieve from a source, so without this file every file is untagged and reachable by no lens.

schema_version = 1
pack_id = "my-library"
strict_library = false

[[source]]
id = "sun-tzu"
label = "Sun Tzu"
match = ["art of war", "sun tzu"]
glob = ["*/sun-tzu/*.epub"]
dir = ["strategy/sun-tzu"]
roots = ["library"]

For explicit Cortex membership, a group may instead use:

[[source]]
id = "my-reading"
label = "My reading"
manual = true

manual defaults to false for existing manifests. A manual group must have no match, glob, or dir rules and never tags a file automatically. Its declared ID is available to lenses and the source editor. This optional field requires the updated loader; older strict loaders reject it. Cortex now edits groups and lens principles directly in the external packs. See the editor workflow.

For automatic groups, three rule kinds are checked in that order, first declaration wins:

  • match, a substring of the root-relative path, at least four characters, because a two-character substring matches most of a library by accident.
  • glob, an fnmatch pattern against the same relative path.
  • dir, a directory prefix.

Matching is on the path relative to the root, not the absolute path. A library at D:\books\machiavelli would otherwise tag everything inside it machiavelli.

A lens claiming an undeclared source group is a load error, since that lens would retrieve nothing and look like a model quality problem. A rule whose id no lens claims is a warning, since it destroys nothing and you may be mid-edit.

Use this as the default:

  • Keep output linting on.
  • Keep approved voice-example retrieval on.
  • Keep Voice polish off and enable it per request when needed.
  • Start with one register from your pack plus one reasoning lens.
  • Add several real approved examples across different response types.
  • Mark private writing local-only.
  • Keep one representative book edition per lens, plus any translation whose differences matter.
  • Review the Generation settings panel when tuning. Change one sampling control at a time.