His branching design (22-23/10, consolidated; now coded): when an expert returns SEVERAL defensible readings of one question (the knowledge ablation audit's ambiguous + alternatives payload), a question that DEPENDS on that row must not inherit the coin-flip. The old behaviour: alternatives were passed in the router context (rejected — it only moves the guess into answer_kg) or collapsed inside the ANSWER prompt (run L: 'Papandreou was the predecessor' — the exact rejected behaviour). The mechanism (floop/branches.py + machine._run_branch): - LAZY: a branch is born only when the ambiguous row has an OPEN dependent subtree (open_subtree, frozen at fork time so every branch of the fork copies the same questions); an ambiguity nobody needs stays a note. - A branch is a WORLD, not a fork of the run: the dependent subtree is re-created inside the branch with branch-scoped qids (B1.Q2), and the shared evidence table is read through a BranchView that BINDS the ambiguous row to the branch's reading (a VIEW — the table is never mutated, the original row keeps all readings) and hides other branches' rows. - SHARED: acquired knowledge lands in the ONE table, tagged provenance['branch']; the KG/seen-index live in the expert, shared by construction. A later branch reuses an earlier one's gathering. - DEATH: by contradiction, dead end (all branch questions failed) or NATURAL MERGE (same normalized answer as another branch — one conclusion, recorded merged). Never an absurdity judge. - NESTING: an ambiguous row answered inside a branch (with its own dependent) opens sub-branches under it (origin=<branch id>); the parent carries its children's conditional as its answer. Branch cap (6) drops and NAMES extra readings — never silent. - CONDITIONAL ANSWER: _finish composes the final answer by FIXED CODE over surviving branches — 'if you meant X -> A | if you meant Y -> B'; single survivor renders plain. Never a synthesis prompt choosing a reading inside itself. - WARNINGS: FORK/BRANCH lines on screen AND log ([W]) — the fork is a machine judgement worth a human's eye, and META's lessons bank counts them. Docs: ALGORITHM.md §6-bis (the mechanism as a law); README honest map row. Tests: tests/branches.py — 5 E2E (fork+conditional, lazy no-fork, dead-branch honesty, natural merge, nested sub-branches). Suite 18/18. Live smoke (ollama-cloud, warm agent KG): the Pedro question runs clean through the new paths (8 calls, 52s, honest answer; the fork did not fire — the audit found no second reading in that KG; the mechanism is proven by the E2E tests, the real-detector proof is his local run over his accumulated KG).
218 lines
14 KiB
Markdown
218 lines
14 KiB
Markdown
# ALGORITHM.md — the machine in words
|
||
|
||
How floop serves any goal: the general loop, tool action, the generic expert, recursion,
|
||
stopping, failure, and how every LLM call gets its context composed.
|
||
|
||
## 0. The whole machine in one paragraph
|
||
|
||
A goal arrives (a question to answer, a tool to call, a chat to hold, a maintenance task
|
||
to run) — possibly wrapped in far more material than the model's window holds, and of
|
||
unknown format. The **INTAKE** stage resolves the boundary first: the original is stored
|
||
whole on disk, known formats are split structurally by fixed code, unknown formats are
|
||
compressed in stages (chunked summarization within the window, a cheaper large-window
|
||
model fronting the first pass if configured), and the request itself — the goal — is
|
||
separated early from the material it refers to. Only then the loop starts. floop never
|
||
"thinks a goal through" in one pass: the goal reduces to open questions until one is
|
||
small enough for a single expert call; answers flow back up and are assembled into the
|
||
response. Three kinds of parts do the work. **The LLMs** propose: read the request, type
|
||
the response expected, decompose the goal into subquestions, translate between language
|
||
and formal formats, compose the final prose. They never decide, never compute, never
|
||
assert facts. **The engines** — solvers, provers, retrieval, the knowledge graph — do the
|
||
deciding: deterministic, typed inputs in, typed payloads and traces out. **The machine** —
|
||
plain fixed code — owns the state: the open-question stack, the dependency order, the
|
||
budget, the retries, the stopping rule, and the per-call context composition. One law
|
||
runs through everything: a claim enters the state only as a typed row with provenance —
|
||
never as free-form model prose.
|
||
|
||
## 1. RECEPTION — intake, then typing the goal
|
||
|
||
INTAKE (ARCHITECTURE.md §3) runs first, always: whatever arrives — a short question, or a
|
||
million-token document with the request buried at the end — is stored verbatim as a run
|
||
artifact; known formats are split structurally (JSON walked, markdown sectioned, plain
|
||
text sentence-split), unknown formats are compressed in stages within the model's window
|
||
(chunked summarization; a cheaper large-window model may front the first pass); and the
|
||
goal is separated from the material early, by a bounded LLM task when the boundary is not
|
||
structurally obvious. The material becomes typed rows pointing into the stored original;
|
||
the goal drives the loop. Known callers are cheaper: harness templates (Hermes Agent
|
||
first) type the digest directly when the incoming shape matches, and sessions cache
|
||
digested material by content hash so each call processes only its delta
|
||
(ARCHITECTURE.md §3).
|
||
|
||
Then the typing call, which now operates on clean typed state rather than raw text: a
|
||
request arrives with (possibly) a tool list. One LLM call reads the goal statement and
|
||
declares the **response type expected by the requester**: `answer` (a question to
|
||
answer), `tool_call` (an action to take), `chat` (conversation to hold), `meta` (a
|
||
floop-maintenance task), `plan_only` (a plan without execution). This typing annotates
|
||
the goal — like `answer_type`, it may be tightened later by evidence. It is NOT a path switch:
|
||
whatever the type, the goal is served by the same loop below. The typing costs one cheap
|
||
call and buys a contract: the output is checked against the declared type on arrival, and
|
||
a mismatch is a refusal-replan, not a silent guess.
|
||
|
||
**Language at the boundary (ARCHITECTURE.md §3).** The typing pass also declares the
|
||
input's **source language**; if it is not English, one bounded LLM task translates the
|
||
goal statement into English — the machine's working language — while the original is
|
||
kept verbatim on disk and the run is flagged `source_language`. From here on everything
|
||
inside is English: subquestions, routing, evidence, the final composed answer. The
|
||
caller's language returns only at the last step (§8).
|
||
|
||
## 2. The main loop
|
||
|
||
The machine keeps the **stack of open questions**, each declaring its answer type and its
|
||
dependencies (which questions it waits on). The loop, in words:
|
||
|
||
1. **Stop check.** No open questions? Ask the prover: is the goal derivable from the
|
||
evidence table? Yes → synthesize the response. No → the decomposition was incomplete:
|
||
one more LLM call asks "what is still missing?" and new questions open. Stopping is a
|
||
formal condition, never a model's feeling.
|
||
2. **Pick.** Take the first question whose dependencies are all answered. If none can be
|
||
picked, a question is waiting on a failed answer: handle the failure (re-open,
|
||
re-decompose, escalate to the user). There is no search: dependency order IS execution
|
||
order.
|
||
3. **Route.** One cheap LLM judgement, with the expert catalogue in view, picks who
|
||
attends the question: a base expert, floop itself (recurse — too big for one call), or
|
||
the user (expert of last resort).
|
||
4. **Execute.** The attendant runs. Its result is checked on arrival: type must match,
|
||
claim must not contradict the table. A mismatch is refused — bounded reformulation
|
||
attempts; a contradiction triggers dependency-directed backtracking (§6). Nothing
|
||
untyped or unprovenanced is ever appended.
|
||
5. **Tick the budget.** Every LLM call and engine run costs. When the budget dies, the
|
||
loop stops and the LLM answers directly from what the table holds — explicitly
|
||
marked `Unverified`.
|
||
|
||
## 3. Tool action — an output of the loop, not an alternative to it
|
||
|
||
When the goal type is `tool_call`, the loop does not change: the harness's tool schemas
|
||
are evidence rows; "which tool satisfies the goal?", "what arguments does it need?",
|
||
"which of the previous observations are relevant?" are **ordinary subquestions**, routed
|
||
to experts like any other — logic reasons over schemas, analytic/numeric compute argument
|
||
values, knowledge supplies world facts. The loop's output is a `tool_call` row (tool,
|
||
arguments) whose provenance cites the schema rows and evidence that justify it; fixed
|
||
code validates it against the schema before emission. The harness executes the tool and
|
||
returns the observation, which enters the table as a `tool_result` row (a user-side fact,
|
||
never "verified", never silently retracted). Then the loop iterates on the new
|
||
observation — the next decision may be another tool, an expert, or stop. This is the ReAct
|
||
pattern with every step typed, evidenced and auditable; for the harness it looks exactly
|
||
like an LLM deciding tool calls. The prover's stopping predicate for tool goals: "the
|
||
evidence supports a concrete (tool, arguments)".
|
||
|
||
## 4. The generic expert
|
||
|
||
Every expert is the same shape: **translate → check → solve → return**.
|
||
|
||
- An LLM call (a dspy Signature) turns the question plus its referenced evidence into the
|
||
expert's formal format — the call receives a purpose-built context (§7), never the
|
||
whole state.
|
||
- A cheap formal check runs (well-typed, consistent units, well-formed query, trusted
|
||
source); failures go back to the translating LLM for bounded retries (≤3).
|
||
- The deterministic engine solves — no LLM inside. Out comes a typed payload with a
|
||
trace: a proof, a derivation, a verbatim quote with URL and access date.
|
||
- If nothing passes after the retries, the expert returns `Unverified` — the honest
|
||
fallback; the loop decides what to do with the hole.
|
||
|
||
Fleet specializations (formal formats, checks, engines, payloads) live in
|
||
ARCHITECTURE.md §7. Two laws bear repeating: the LLM never computes — not even a
|
||
multiplication (`numeric` exists to enforce this); and `knowledge` never paraphrases —
|
||
its payload is the verbatim quote with provenance.
|
||
|
||
## 5. Recursion — floop inside floop
|
||
|
||
A question too big for one expert call recurses: a child floop run on that question,
|
||
knowing its parent goal. Same loop, same discipline, two differences: **context shapes
|
||
adequacy** (the child knows why it is asked, so it knows when its answer is good enough)
|
||
and **budget is partitioned** (a slice of the parent's, plus a depth cap; a child that
|
||
cannot finish returns Unverified upward). The recursion bottoms out at the expert
|
||
catalogue — base case: one expert call; recursive case: one more level of the same
|
||
machine. There is no separate planner component: the plan is the open-question stack,
|
||
planning is proposing reductions of it, execution is answering from it.
|
||
|
||
## 6. Failure and backtracking
|
||
|
||
Failure is information. A contradiction in the table walks the provenance graph to the
|
||
culprit assumption, marks it retracted, and retracts exactly its downstream rows —
|
||
dependency-directed, not chronological; work that never depended on the dead assumption
|
||
survives; the corpse stays for inspection and learning (append-only). Factual hypotheses
|
||
(refutable by evidence) open branches; parameter assumptions (no evidence could refute
|
||
them) are dimensions of the answer function, never branches. And one thing can never be
|
||
retracted: the user. A user-supplied fact colliding with a source is presented verbatim
|
||
to the user — never silently resolved.
|
||
|
||
## 6-bis. Execution branches over ambiguity (2026-10-23, coded)
|
||
|
||
When an expert answers with SEVERAL defensible readings (the knowledge ablation audit
|
||
flags `ambiguous` + named alternatives), a question that DEPENDS on that row does not
|
||
inherit the coin-flip. The machine opens ONE EXECUTION BRANCH PER READING:
|
||
|
||
- **Lazy.** The branch is born only when the ambiguous row has an open dependent
|
||
subtree — an ambiguity nobody downstream needs stays a note; the picked reading rides.
|
||
The subtree is frozen at fork time: every branch of the fork copies the same questions.
|
||
- **A branch is a world, not a fork of the run.** The branch reads the shared evidence
|
||
table through a VIEW that binds the ambiguous row to its reading (the same law as the
|
||
ablation mask: the table is never mutated — the original row keeps all its readings)
|
||
and hides other branches' rows. Acquired knowledge (new rows, KG facts, fetched
|
||
articles, conclusions) lands in the ONE shared store, tagged with the branch id —
|
||
a later branch reuses an earlier branch's gathering for free.
|
||
- **Death is honest.** A branch dies by contradiction, dead end (all its questions
|
||
failed — UNKNOWN), or natural merge (its answer equals another branch's — deduped by
|
||
normalized value, one conclusion). Never by an absurdity judge: surprising-but-cited
|
||
answers render.
|
||
- **Nesting composes.** An ambiguous row answered INSIDE a branch (with its own
|
||
dependent) opens sub-branches under it, under the same branch cap; a parent carries
|
||
its children's conditional as its answer.
|
||
- **The final answer is conditional, composed by fixed code** — `if you meant the
|
||
PM-of-Spain reading -> Rajoy | if you meant Socialist International -> Papandreou`.
|
||
Never one reading chosen inside a synthesis prompt; never the alternatives handed to
|
||
the next question's context (that only moves the coin-flip into answer_kg).
|
||
- Clarifying with the user instead of running the branches is a POLICY ABOVE this
|
||
mechanism (layer 3): asking = picking one branch upstairs. The mechanism itself
|
||
always runs the worlds it needs.
|
||
|
||
Budget: branches share the run's `llm_calls` pool (a fork of N readings costs ~N× the
|
||
dependent subtree — leave headroom or the later branches die by budget, honestly noted);
|
||
branch count is capped (extra readings are dropped and NAMED, never silent).
|
||
|
||
## 7. Per-call context composition
|
||
|
||
Every LLM call gets its own purpose-built context, assembled by fixed code within the
|
||
model's window:
|
||
|
||
- The machine state (evidence table, question stack, knowledge graph) is machine-sized —
|
||
disk, database, RAM — and can exceed any window. **No call ever receives the whole
|
||
state.**
|
||
- For each call the composer assembles: the task (the Signature's inputs), the referenced
|
||
rows (by id, compact summaries), the orientation the task needs (parent goal, section
|
||
headers, document chunk). What went in is logged.
|
||
- When the needed background exceeds the window, the machine **synthesizes** rather than
|
||
truncates: compact row summaries, structured KG subgraphs, chunked documents
|
||
(KNOWLEDGE.md). The callee gets what its function needs — not everything floop knows.
|
||
- Different calls to the same Signature may carry different context sizes: the contract
|
||
is the fields, not the window.
|
||
|
||
## 8. Stopping and responding
|
||
|
||
The stop condition is formal (prover over the table; for tool goals: a concrete
|
||
justified (tool, args) is derivable). Then — and only then — one final LLM pass composes
|
||
the response in natural language from the evidence rows and traces: every number carries
|
||
its source, every derivation its steps, every assumption its mark. If the budget died
|
||
first, the response is composed anyway from what the table holds — explicitly marked
|
||
`Unverified`. The product is the same in both cases: a reply that tells you exactly which
|
||
parts are proven and which are, honestly, a guess.
|
||
|
||
One last boundary task follows: if the run's `source_language` is not English, a bounded
|
||
LLM pass renders the composed English response into that language — facts, numbers and
|
||
citations carried across traceable to the English rows; quotes stay verbatim in their
|
||
source language (ARCHITECTURE.md §3). If it is English, nothing happens. The harness sees
|
||
a reply in its own language either way.
|
||
|
||
## 9. Who does what
|
||
|
||
- **LLM, always**: reading and typing requests; proposing subquestions; translating
|
||
between language and formal formats — and between human languages at the two
|
||
boundary tasks (inbound English-ization, outbound rendering); the routing
|
||
judgement; composing responses.
|
||
- **Fixed code, always**: the question stack and dependency ordering; budget partition;
|
||
bounded retries; arrival checks; contradiction detection and retraction; refusing to
|
||
stop; per-call context composition.
|
||
- **The prover (a solver, not a model), always**: the stop condition; "answered" for any
|
||
question; the final derivability check.
|
||
- **Never the LLM**: computing values; deciding when it is finished; writing free-form
|
||
rows into the state; silently picking between conflicting facts. |