Files
floop/code/README.md
T
onibot 004c7974c6 floop: execution branches over ambiguity — fork per reading, conditional answer
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).
2026-10-23 16:29:26 +02:00

87 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# floop/code — v0.1 draft implementation
A **draft**: every deciding stage (formal checks, the prover, real engines) is a
stub, so the draft runs with only LLM calls (as decided) and every answer is
honestly marked **UNVERIFIED**. The architecture — states, laws, control flow —
is the real v0.1 shape; only the formal layer is missing.
## Run
```bash
cd floop/code
uv run run_app.py "What information do I need to plan a trip to Tokyo?" # any question
uv run run_app.py --verbose "..." # + "thinking" on screen, flushed
uv run run_app.py --baseline "..." # A/B control: raw LLM, ONE call, no loop
FLOOP_LM=ollama-cloud uv run run_app.py "..." # cloud LM instead of local
```
### Baselines (Emili, 2026-10-16)
The draft experts are **baseline experts**: the LLM answers each small subquestion
directly from its own knowledge — no engine, no verification yet. Each evidence row
records the honest source: `model_weights` (answered from the LLM's own knowledge) or
`given_evidence` (backed by a verbatim quote from the evidence it was given). When the
real engines arrive (knowledge first), the verification path replaces the baseline path
per expert, and every improvement becomes measurable against this baseline.
`--baseline` is the A/B control: the same LM answers the whole question in ONE raw
call — no decomposition, no experts, no evidence table. Same LM, same budget unit.
Compare: `--baseline` vs the loop's many small directed calls.
- **Always**: `runs/<ts>-<slug>/run.log` (gitignored), written with explicit flush —
`tail -f runs/<latest>/run.log` from another terminal shows progress live.
- **`--verbose`**: the **thinking stream** also prints to the screen, flushed. Thinking is
floop's future user-facing "thinking" output (what floop-as-LLM will stream); it is a
SUBSET of the log — the log keeps all technical detail (budget, provenance, raw payloads),
thinking stays readable. They will diverge over time (Emili, 2026-10-13).
- Screen thinking lines carry the `[T]` marker; recursion depth shows as `>` prefixes.
- The same events will drive the OpenAI-compatible endpoint's streaming mode (ARCHITECTURE.md §5).
`config.yaml` holds the budget knobs and the two LM providers (no keys in code:
`ollama-cloud` reads `OLLAMA_API_KEY` from the environment). Logs live in `runs/`.
## What is real vs stub (the honest map)
| Stage (ALGORITHM.md) | Status | Where |
|---|---|---|
| INIT — epistemic decomposition (LLM call) | real (dspy.Predict) | `floop/dspy_modules.py` |
| MISSING — gap decomposition on stuck goal | real (dspy) | `floop/dspy_modules.py` |
| ROUTE — one LLM judgement over the catalogue | real (dspy) | `floop/dspy_modules.py` |
| Expert attendants (the draft answer) | **BASELINE engine**: LLM answers from its weights; `verified=False`; source recorded (`model_weights`/`given_evidence`) | `floop/engine.py` |
| **knowledge** expert | **REAL pipeline** (2026-10-17): KG probe (entity+relation, stemmed) -> COMPOSE queries (deterministic, from question ∪ evidence — the old TRANSLATE LLM removed 23/10) -> en.wikipedia search -> fetch_rich (text + wikitext tables) -> section chunks -> lexical gate -> EXTRACT (verbatim quotes) -> containment check -> merge (4 contradiction cases) -> answer from quoted rows. Fallback: baseline LLM on pipeline failure. | `knowledge/` + `floop/engine.py:KnowledgeEngine` |
| Arrival check (type check + contradiction) | **STUB**: only UNKNOWN refusal | `machine._append_checked` |
| Execution branches over ambiguity (ALGORITHM §6-bis) | **REAL** (2026-10-23): lazy fork per reading of an ambiguous row with an open dependent; BranchView binds the reading (table never mutated), acquired knowledge shared + branch-tagged; death by contradiction/dead end/natural merge; nested sub-branches; conditional final answer composed by fixed code | `floop/branches.py` + `floop/machine.py:_run_branch` |
| Prover (stop condition, derivability) | **STUB**: question stack terminal | `machine._finish` |
| `user` expert | not wired — explicit failure row | `floop/engine.py` |
| Backtracking / retraction (TMS) | not in the draft (§5 comes with the prover) | — |
| The machine (stack, dependency order, budget, recursion) | real fixed code | `floop/machine.py`, `floop/state.py` |
| Evidence table (append-only, provenance, no prose) | real | `floop/state.py` |
Laws kept: the table only ever receives typed payloads (never LLM prose); rows
carry provenance + trace; the machine — not the LLM — owns sequencing, budget,
retries and stopping; answer synthesis sees only evidence rows and cites them.
## Layout
```
config.yaml budget + LM providers
run_app.py CLI entry
floop/state.py EvidenceTable, QuestionStack, Budget, slot instantiation (#En -> value)
floop/llm.py dspy LM configuration (OpenAI-compatible endpoints)
floop/dspy_modules.py every LLM call as a dspy module (INIT, ROUTE, EXPERT, MISSING, ANSWER)
floop/engine.py engine interface + draft stub engines
floop/machine.py FloopRun — the loop; recursion for the `floop` attendant
tests/state.py unit tests (no LLM)
```
## Next steps (design order from the docs)
1. Real check layer on expert arrival (well-formedness per expert kind) — the
#1 failure mode is misformalization; keep it BEFORE engines.
2. ~~`knowledge` expert with real search + verbatim quotes~~ **DONE 2026-10-17**
(Wikipedia-only, en; DuckDuckGo + general web later).
3. Prover for the stop condition (clingo/Z3) — replaces the stub derivability.
4. Log every run (v2's router will eat these trajectories).
5. Knowledge efficiency: the gather still spends extraction calls on tangential
articles (US river lists matched the "longest river" gate); tune gate/articles.
Also: KG dedupe of noisy entities from early runs (`the loire` vs `loire river`).