Skip to content

Commit 178603e

Browse files
fluffy314cursoragent
authored andcommitted
fix(autoresearch): scope history to target leaf
Prevent prior unrelated proof branches from being reinjected into each Generator turn while preserving complete current-output review by the Critic. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent cec1b48 commit 178603e

2 files changed

Lines changed: 69 additions & 4 deletions

File tree

scripts/agent_gan_repl.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,17 @@ def build_generator_messages(
636636
previous_generator: str = "",
637637
previous_critic: str = "",
638638
proof_ledger: str = "",
639+
target_obligation_id: str = "",
639640
) -> list[dict[str, str]]:
641+
if target_obligation_id:
642+
previous_generator = extract_obligation_history(
643+
previous_generator,
644+
target_obligation_id,
645+
)
646+
previous_critic = extract_obligation_history(
647+
previous_critic,
648+
target_obligation_id,
649+
)
640650
feedback = ""
641651
if previous_generator or previous_critic:
642652
feedback = (
@@ -674,6 +684,22 @@ def build_generator_messages(
674684
]
675685

676686

687+
_OBLIGATION_HISTORY_SECTION = re.compile(
688+
r"^### (?:ISSUE_RESPONSE|ISSUE_VERDICT)\s+(\S+)\s*$"
689+
r"(?P<body>.*?)(?=^### |\Z)",
690+
re.MULTILINE | re.DOTALL,
691+
)
692+
693+
694+
def extract_obligation_history(text: str, obligation_id: str) -> str:
695+
sections = [
696+
match.group(0).strip()
697+
for match in _OBLIGATION_HISTORY_SECTION.finditer(text)
698+
if match.group(1) == obligation_id
699+
]
700+
return "\n\n".join(sections)
701+
702+
677703
def build_critic_messages(
678704
goal: str,
679705
generator_response: str,
@@ -1157,12 +1183,19 @@ def get_stats():
11571183
try:
11581184
generator_messages = build_generator_messages(
11591185
research_goal,
1160-
steering=generator_steering,
1186+
steering="\n\n".join(filter(None, (
1187+
generator_steering,
1188+
critic_issue_injection,
1189+
))),
11611190
previous_generator=previous_generator,
1162-
previous_critic=(
1163-
previous_critic + critic_issue_injection
1164-
),
1191+
previous_critic=previous_critic,
11651192
proof_ledger=proof_ledger_text,
1193+
target_obligation_id=(
1194+
turn_obligations[0].obligation_id
1195+
if research_candidate is not None
1196+
and len(turn_obligations) == 1
1197+
else ""
1198+
),
11661199
)
11671200
generator_ids = tokenizer.apply_chat_template(
11681201
generator_messages,

tests/inference_engine/bridge/test_agent_gan_repl.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
_telemetry_request,
2020
build_critic_messages,
2121
build_generator_messages,
22+
extract_obligation_history,
2223
install_signal_protection,
2324
is_runtime_artifact_prompt,
2425
consume_critic_issue_batch,
@@ -292,6 +293,37 @@ def test_interactive_prompts_are_deterministic_for_kv_reuse():
292293
assert "sample, summarize, simplify" in combined
293294

294295

296+
def test_generator_history_is_scoped_to_target_leaf():
297+
history = """
298+
### ISSUE_RESPONSE RH-C1
299+
Correction: unrelated operator branch.
300+
301+
### ISSUE_VERDICT RH-C1
302+
Status: UNRESOLVED
303+
Missing lemma: unrelated operator lemma.
304+
305+
### ISSUE_RESPONSE RH-C2-child
306+
Correction: target convergence branch.
307+
308+
### ISSUE_VERDICT RH-C2-child
309+
Status: UNRESOLVED
310+
Missing lemma: target compact convergence lemma.
311+
"""
312+
scoped = extract_obligation_history(history, "RH-C2-child")
313+
assert "target convergence branch" in scoped
314+
assert "target compact convergence lemma" in scoped
315+
assert "RH-C1" not in scoped
316+
messages = build_generator_messages(
317+
"prove RH",
318+
previous_generator=history,
319+
previous_critic=history,
320+
target_obligation_id="RH-C2-child",
321+
)
322+
prompt = messages[-1]["content"]
323+
assert "target convergence branch" in prompt
324+
assert "unrelated operator branch" not in prompt
325+
326+
295327
def test_runtime_output_cannot_replace_research_goal():
296328
for text in (
297329
"critic> ### Central Claim",

0 commit comments

Comments
 (0)