floop: a run that asked the user ends IN the question (fixed-code clarify)
His 23/10 run review: ROUTE correctly deferred Q2 to the user (the
evidence only flagged ambiguity — layer-3 policy working), the user
expert recorded needs_user_input, the cascade killed the dependents…
and then the ANSWER step ran anyway: the synthesis prompt read
'note=needs_user_input' as plain text and invented 'The provided
evidence does not identify who was the President…' — the machine had
DECIDED to ask, and the final node swallowed the question.
The fix (his call): a run that ASKED ends IN THE QUESTION.
- _finish now checks pending user rows (note=needs_user_input) BEFORE
any synthesis; when present the final answer is composed by FIXED
CODE (_clarify_answer, zero LLM calls): 'I need to ask you: <the
instantiated question> (so far: <what the machine holds>)' — the
dependency's value rendered as context, with the ambiguity note when
the row is ambiguous ('so far: Socialist International — but other
defensible readings exist: Spain').
- Ordering vs the branch answer: branches own the
ambiguity-with-dependents shape (the fork); clarify owns every OTHER
honest defer. A synthesis prompt can no longer re-render a machine
decision as 'evidence is unknown'.
- test_user_expert_fails_question updated: it asserted the OLD
behaviour ('synthesis still happens, honestly') — that assertion
codified exactly the bug he rejected; the run that asks now ends in
the ask.
New test: the defer path ends in the question, no synthesis runs.
Suite 18/18.
This commit is contained in:
+68
-1
@@ -70,7 +70,11 @@ def test_user_expert_fails_question():
|
||||
rep = FloopRun("goal?", budget(), modules=fm).run()
|
||||
assert rep.questions[1][1] == "failed"
|
||||
assert any("needs_user_input" in e for e in rep.evidence_rows)
|
||||
assert rep.final_answer == "ANSWER(goal?)" # synthesis still happens, honestly
|
||||
# the 23/10 law: a run that ASKED ends IN THE QUESTION (fixed code),
|
||||
# never a synthesis prompt swallowing the ask — 'the evidence does
|
||||
# not identify...' is the rejected behaviour
|
||||
assert rep.final_answer.startswith("I need to ask you:"), rep.final_answer
|
||||
assert any("clarification requested" in n for n in rep.notes)
|
||||
|
||||
|
||||
def test_recursion_depth_cap():
|
||||
@@ -290,6 +294,69 @@ def test_seed_warning_is_emitted():
|
||||
print("ok: seed WARNING lands in run.log (auto-answer is loud)")
|
||||
|
||||
|
||||
def test_route_to_user_ends_in_the_question():
|
||||
"""His 23/10 run: ROUTE deferred a subquestion to the user (the
|
||||
evidence only flagged ambiguity) — and the final ANSWER prompt
|
||||
swallowed the ask, inventing 'the evidence does not identify...'.
|
||||
A run that ASKED ends IN THE QUESTION, composed by fixed code: the
|
||||
instantiated question, what the machine holds as context, zero
|
||||
synthesis calls. (The ambiguity+dependent shape now forks branches —
|
||||
tested in branches.py; this covers every OTHER honest defer.)"""
|
||||
import tempfile
|
||||
from floop.stream import RunStreams
|
||||
from floop.state import AnswerType, EvidenceRow
|
||||
streams = RunStreams("clarify test", verbose=False,
|
||||
runs_dir=tempfile.mkdtemp())
|
||||
|
||||
class PlainEngine:
|
||||
def __init__(self, modules, charge, expert_kind):
|
||||
self.charge = charge
|
||||
def run(self, qid, question, parent_question, table, answer_type, streams=None):
|
||||
self.charge()
|
||||
return EvidenceRow(
|
||||
qid=qid, answer_type=AnswerType.OPEN,
|
||||
payload={"value": "Paris", "quote": "q"},
|
||||
engine="knowledge", trace=[], provenance={},
|
||||
verified=False, note="")
|
||||
|
||||
import floop.machine as M
|
||||
real = M.LLMExpertEngine
|
||||
M.LLMExpertEngine = PlainEngine
|
||||
try:
|
||||
# FakeModules.route_question returns (route_fn(question), "fake") —
|
||||
# our route must return the ATTENDANT string alone, not a tuple
|
||||
def route(q):
|
||||
if "district" in q:
|
||||
return "user"
|
||||
return "knowledge"
|
||||
|
||||
fm = FakeModules(
|
||||
init_subs=[
|
||||
{"text": "What is the capital of France?", "deps": [],
|
||||
"answer_type": "OPEN"},
|
||||
{"text": "Which specific district of that capital does the user mean?",
|
||||
"deps": [1], "answer_type": "OPEN"},
|
||||
],
|
||||
route_fn=route)
|
||||
# the generic FakeModules.missing_decompose would inject a fallback
|
||||
# question after the defer, reopening the loop and reaching a plain
|
||||
# synthesis — this test isolates the defer path (missing adds nothing)
|
||||
fm.missing_decompose = lambda goal, evidence: []
|
||||
run = FloopRun("What is the capital of France and which district do you mean?",
|
||||
budget(), modules=fm, streams=streams)
|
||||
rep = run.run()
|
||||
finally:
|
||||
M.LLMExpertEngine = real
|
||||
# the run ends IN THE QUESTION to the user, by fixed code
|
||||
assert rep.final_answer.startswith("I need to ask you:"), rep.final_answer
|
||||
assert "district" in rep.final_answer, rep.final_answer
|
||||
assert "(so far: Paris)" in rep.final_answer, rep.final_answer
|
||||
# the synthesis NEVER ran: the ask is not invented from the table
|
||||
assert "synthesize" not in fm.calls, fm.calls
|
||||
assert any("clarification requested" in n for n in rep.notes), rep.notes
|
||||
print("ok: a run that asks ends in the question (fixed code, no synthesis)")
|
||||
|
||||
|
||||
# keep a handle to restore the real engine after monkeypatching
|
||||
from floop.engine import LLMExpertEngine as _restore_llm_engine
|
||||
|
||||
|
||||
Reference in New Issue
Block a user