feat: baseline experts + --baseline A/B mode (raw LLM)
Per Emili 2026-10-16: the draft experts are baseline experts - the LLM answers each subquestion directly from its own knowledge (no verification yet; engines replace the baseline path per expert later). ExpertSignature no longer forbids weights-based answers; source_quote now means verbatim from GIVEN evidence, empty when answering from weights. Evidence rows record source: model_weights | given_evidence. --baseline mode: the same LM answers the whole question in ONE raw call - the A/B control against the loop's many small directed calls. Also: pyproject fixed (name floop, hatchling backend, package floop/) - uv_build expected src/ layout; runner docs now uv-first; uv.lock regenerated.
This commit is contained in:
+18
-4
@@ -9,11 +9,25 @@ is the real v0.1 shape; only the formal layer is missing.
|
||||
|
||||
```bash
|
||||
cd floop/code
|
||||
.venv/bin/python run_app.py "What information do I need to plan a trip to Tokyo?" # any question
|
||||
.venv/bin/python run_app.py --verbose "..." # + "thinking" on screen, flushed
|
||||
FLOOP_LM=ollama-cloud .venv/bin/python run_app.py "..." # cloud LM instead of local
|
||||
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
|
||||
@@ -33,7 +47,7 @@ FLOOP_LM=ollama-cloud .venv/bin/python run_app.py "..." # cloud LM instead of
|
||||
| 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) | **STUB engine**: LLM call, `verified=False` | `floop/engine.py` |
|
||||
| Expert attendants (the draft answer) | **BASELINE engine**: LLM answers from its weights; `verified=False`; source recorded (`model_weights`/`given_evidence`) | `floop/engine.py` |
|
||||
| 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` |
|
||||
|
||||
@@ -34,18 +34,18 @@ class RouteSignature(dspy.Signature):
|
||||
|
||||
|
||||
class ExpertSignature(dspy.Signature):
|
||||
"""You are an expert ATTENDANT whose draft answer is checked by a machine.
|
||||
You translate the question into a typed answer payload — you do not compute
|
||||
values and you never invent facts. Use the evidence you are given, plus
|
||||
facts literally stated in the parent question; if the answer is not
|
||||
derivable from them, say so."""
|
||||
"""You are an expert attendant answering a small, focused subquestion.
|
||||
Use the evidence rows when they answer it; otherwise answer from your own
|
||||
knowledge. This is a BASELINE draft: no engine verifies you yet, so state
|
||||
your honest confidence. Say UNKNOWN only if you genuinely do not know."""
|
||||
question: str = dspy.InputField()
|
||||
parent_question: str = dspy.InputField(
|
||||
desc="the original user question this subquestion serves; facts literally stated there are permitted sources")
|
||||
expert_kind: str = dspy.InputField(desc="knowledge logic analytic numeric")
|
||||
evidence: str = dspy.InputField(desc="evidence rows this question references")
|
||||
evidence: str = dspy.InputField(desc="evidence rows this question references; may be empty")
|
||||
value: str = dspy.OutputField(desc="the answer value in its declared type, or 'UNKNOWN'")
|
||||
source_quote: str = dspy.OutputField(desc="VERBATIM supporting text (from evidence or the parent question); empty if none")
|
||||
source_quote: str = dspy.OutputField(
|
||||
desc="VERBATIM text from the given evidence if the answer comes from it; EMPTY when answering from your own knowledge")
|
||||
confidence: str = dspy.OutputField(desc="high medium low")
|
||||
|
||||
|
||||
@@ -63,8 +63,9 @@ class MissingSignature(dspy.Signature):
|
||||
|
||||
class AnswerSignature(dspy.Signature):
|
||||
"""You are the ANSWER step of a reasoning machine. Write the final natural
|
||||
language answer to the goal using ONLY the evidence rows. Working only from
|
||||
those rows, cite them; every number or fact carries its row id."""
|
||||
language answer to the goal using ONLY the evidence rows, citing them; every
|
||||
number or fact carries its row id. State the answer plainly — the system
|
||||
marks verification status separately, do not hedge about it."""
|
||||
goal: str = dspy.InputField()
|
||||
evidence: str = dspy.InputField()
|
||||
unverified: str = dspy.InputField(desc="'true' if the prover could not verify derivability")
|
||||
|
||||
@@ -52,7 +52,9 @@ class LLMExpertEngine:
|
||||
payload: dict = {"value": draft["value"]}
|
||||
if draft["source_quote"]:
|
||||
payload["quote"] = draft["source_quote"]
|
||||
prov = {"expert": self.kind, "note": "draft v0.1 — no real engine, no check layer"}
|
||||
prov = {"expert": self.kind,
|
||||
"source": "model_weights" if not draft["source_quote"] else "given_evidence",
|
||||
"note": "baseline v0.1 — LLM answers directly; engines come later"}
|
||||
if parent_question:
|
||||
prov["parent_question"] = parent_question
|
||||
return EvidenceRow(
|
||||
|
||||
@@ -37,5 +37,17 @@ def configure_lm() -> dict:
|
||||
"api_key": os.environ.get(p.get("api_key_env", ""), "empty"),
|
||||
}
|
||||
lm = dspy.LM(**kwargs)
|
||||
global _ACTIVE
|
||||
_ACTIVE = lm
|
||||
dspy.configure(lm=lm)
|
||||
return {"provider": provider, "model": p["model"], "base_url": p["base_url"]}
|
||||
|
||||
|
||||
_ACTIVE: "dspy.LM | None" = None
|
||||
|
||||
|
||||
def active_lm() -> "dspy.LM":
|
||||
"""The configured dspy.LM, configuring it lazily if needed (baseline mode uses it raw)."""
|
||||
if _ACTIVE is None:
|
||||
configure_lm()
|
||||
return _ACTIVE
|
||||
+8
-5
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "code"
|
||||
name = "floop"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
description = "Fractal loop: LLMs do the language, algorithms do the thinking"
|
||||
readme = "README.md"
|
||||
authors = [
|
||||
{ name = "OniricApps", email = "emili@oniricapps.com" }
|
||||
@@ -13,8 +13,11 @@ dependencies = [
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
code = "code:main"
|
||||
floop = "floop.__main__:main"
|
||||
|
||||
[build-system]
|
||||
requires = ["uv_build>=0.12.10,<0.13.0"]
|
||||
build-backend = "uv_build"
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["floop"]
|
||||
+35
-5
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the floop draft on a question.
|
||||
|
||||
.venv/bin/python run_app.py "Per què el cel és blau?" # log only
|
||||
.venv/bin/python run_app.py --verbose "Per què el cel és blau?" # + thinking on screen
|
||||
FLOOP_LM=ollama-cloud .venv/bin/python run_app.py "..."
|
||||
uv run run_app.py "Per què el cel és blau?" # log only
|
||||
uv run run_app.py --verbose "Per què el cel és blau?" # + thinking on screen
|
||||
uv run run_app.py --baseline "Per què el cel és blau?" # raw LLM, one call (A/B comparison)
|
||||
FLOOP_LM=ollama-cloud uv run run_app.py "..."
|
||||
|
||||
Always: runs/<ts>-<slug>/run.log written with flush -> `tail -f` it from another
|
||||
terminal. With --verbose, the "thinking" stream (the future floop-as-LLM thinking
|
||||
@@ -12,6 +13,7 @@ output — a subset of the log) also prints to the screen, flushed.
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
@@ -24,10 +26,27 @@ from floop.state import Budget # noqa: E402
|
||||
from floop.stream import RunStreams # noqa: E402
|
||||
|
||||
|
||||
def run_baseline(question: str, streams: RunStreams) -> str:
|
||||
"""The A/B control: the raw LM answers in ONE call — no decomposition, no
|
||||
experts, no evidence. Same LM, same budget unit (1 call) as the loop's init."""
|
||||
from floop.llm import active_lm
|
||||
streams.call("BASELINE", f"single raw LM call: {question[:80]}",
|
||||
think=f"raw LM: {question[:90]}")
|
||||
t0 = time.time()
|
||||
raw = active_lm()(messages=[{"role": "user", "content": question}])
|
||||
first = raw[0] if isinstance(raw, list) else raw.outputs[0]
|
||||
answer = first["text"] if isinstance(first, dict) and "text" in first else first.get("content") or str(first)
|
||||
dt = round(time.time() - t0, 1)
|
||||
streams.output("BASELINE", answer)
|
||||
streams.log(f"baseline time={dt}s")
|
||||
return answer
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = sys.argv[1:]
|
||||
verbose = "--verbose" in args
|
||||
args = [a for a in args if a != "--verbose"]
|
||||
baseline = "--baseline" in args
|
||||
args = [a for a in args if a not in ("--verbose", "--baseline")]
|
||||
if not args:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
@@ -42,7 +61,18 @@ def main() -> None:
|
||||
|
||||
lm_info = configure_lm()
|
||||
streams = RunStreams(question, verbose=verbose, runs_dir=code_dir / "runs")
|
||||
streams.log(f"lm={lm_info['provider']}/{lm_info['model']} verbose={verbose}")
|
||||
streams.log(f"lm={lm_info['provider']}/{lm_info['model']} verbose={verbose} baseline={baseline}")
|
||||
|
||||
if baseline:
|
||||
answer = run_baseline(question, streams)
|
||||
streams.close()
|
||||
print(f"goal: {question}")
|
||||
print(f"lm: {lm_info['provider']} / {lm_info['model']} | mode=baseline (raw LLM, 1 call)")
|
||||
print("\nraw LM answer:")
|
||||
print(answer)
|
||||
print(f"\nrun log: {streams.run_dir / 'run.log'}")
|
||||
return
|
||||
|
||||
try:
|
||||
report: RunReport = FloopRun(question, budget, streams=streams).run()
|
||||
finally:
|
||||
|
||||
Generated
+15
-15
@@ -360,21 +360,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/88/39/799be3f2f0f38cc727ee3b4f1445fe6d5e4133064ec2e4115069418a5bb6/cloudpickle-3.1.2-py3-none-any.whl", hash = "sha256:9acb47f6afd73f60dc1df93bb801b472f05ff42fa6c84167d25cb206be1fbf4a", size = 22228, upload-time = "2025-11-03T09:25:25.534Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "code"
|
||||
version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "dspy" },
|
||||
{ name = "pyyaml" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "dspy", specifier = ">=3.4.1" },
|
||||
{ name = "pyyaml", specifier = ">=6.0.3" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
@@ -468,6 +453,21 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/15/df/31098c5aeb4d966b553641472bd55fcf5fdfac953549894b8a765ba44e91/filelock-3.32.7-py3-none-any.whl", hash = "sha256:65ff0d0190ea42038b32bda4b77834fb05be2cad4c5b9b01aa4dfb3614536e52", size = 100157, upload-time = "2026-09-16T00:24:19.543Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "floop"
|
||||
version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "dspy" },
|
||||
{ name = "pyyaml" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "dspy", specifier = ">=3.4.1" },
|
||||
{ name = "pyyaml", specifier = ">=6.0.3" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "frozenlist"
|
||||
version = "1.8.0"
|
||||
|
||||
Reference in New Issue
Block a user