Files
floop/code
onibot 9eab127727 knowledge: table fragments for extract + exact prompt log (run G fixes)
Run G hung at call 8/80 for minutes with no way to see what was sent.
Reproducing it found TWO root causes, both fixed here:

1. THE 22K TABLE CHUNK WAS A PARSER BUG, not just a size problem. The
   world-rivers table marks each data row's leading cell with
   '!scope="row"|' (a row-label th); parse_tables flagged any row that
   touched a '!' as a header row, so all 227 data rows collapsed into ONE
   header of 1,825 cells and zero rows. tables_as_text then flattened
   that monster into a single 22,021-char prose chunk. Fix: a row is a
   header row only if ALL its cells are '!' cells; mixed rows are data
   rows. Live: the world table now parses as 8 cols x 227 rows.

2. NO PROMPT OBSERVABILITY. The log's CALL/OUTPUT lines never carried
   what the LM actually received. floop/llm.py now installs a dspy global
   callback (PromptLogCallback): every LM call's exact rendered prompt
   lands in runs/<ts>/prompts/NN-stage.txt (NN mirrors the budget counter
   -- 08-EXTRACT.txt IS call 8/80), plus size/duration lines in run.log.
   Stage comes from a module stack (dspy fires on_module_start with a
   DIFFERENT call_id than the inner LM call -- verified with DummyLM
   probes), not a call_id map.

Plus the design Emili steered (tables reach the extractor as typed
fragments, never prose dumps):
- tables_as_chunks: per-table fragments of <=40 rows, EVERY fragment
  repeats header + caption, part i/N markers; the extractor always knows
  which table ('troç 2/10') it is reading.
- STOP_TABLE: the extractor may early-skip a table whose subject is
  wrong for the question after one fragment; fixed code skips the rest
  of THAT table. ExtractSignature teaches the protocol.
- fetch_rich no longer appends the '== Tables ==' enrichment to prose
  (the giant chunk's birthplace; also let verify_count cite the table as
  'prose'). Tables reach the extract path only as fragments; LIST and
  harvest keep reading page.tables directly.
- fragment candidates pass the same containment check against prose +
  full table text; LIST answer's table never re-enters extract.

Tests: knowledge/tests/tablefrags.py (fragment generation/render,
STOP_TABLE skipping, fragment extraction with containment, prompt log
files + log lines). Live smoke: world article 10 chunks none >5k; world
table = 6 fragments (max 5,787c); Italy discharge fragment intact
(Po/1540). Full suite 47/47.
2026-10-20 20:22:29 +02:00
..

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

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) -> TRANSLATE (queries+entities from context) -> 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
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).