From 78881dd324f88e4f7729acea7dfa2d6056102df8 Mon Sep 17 00:00:00 2001 From: ray-suton Date: Sat, 25 Jul 2026 20:32:31 +0400 Subject: [PATCH] Preserve branch boundaries in aggregation prompts Branch summaries were joined by bare newlines because operator precedence applied the divider only once. A small helper makes the intended boundary explicit and gives the behavior a focused regression test. Constraint: Keep aggregation search semantics and prompt content unchanged Rejected: Parenthesize the inline expression only | leaves the boundary rule implicit and untested Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep separator formatting covered when aggregation prompt structure changes Tested: python3 -m unittest discover -s tests -v; python3 -m compileall -q agents tests; git diff --check Not-tested: Full live MLEvolve search run --- agents/aggregation_agent.py | 7 ++++++- tests/test_aggregation_agent.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/test_aggregation_agent.py diff --git a/agents/aggregation_agent.py b/agents/aggregation_agent.py index 5d40724..22836be 100644 --- a/agents/aggregation_agent.py +++ b/agents/aggregation_agent.py @@ -13,6 +13,11 @@ logger = logging.getLogger("MLEvolve") +def _join_branch_summaries(summaries: List[str]) -> str: + separator = "\n" + "-" * 80 + "\n" + return separator.join(summaries) + + def _collect_branch_representatives(agent) -> List[SearchNode]: representatives = [] @@ -111,7 +116,7 @@ def run( ) reference_summaries.append(branch_info) - reference_experiences = "\n" + "-" * 80 + "\n".join(reference_summaries) + reference_experiences = _join_branch_summaries(reference_summaries) prompt: Any = { "Introduction": introduction, diff --git a/tests/test_aggregation_agent.py b/tests/test_aggregation_agent.py new file mode 100644 index 0000000..72b4bcf --- /dev/null +++ b/tests/test_aggregation_agent.py @@ -0,0 +1,22 @@ +import unittest + +from agents.aggregation_agent import _join_branch_summaries + + +class JoinBranchSummariesTest(unittest.TestCase): + def test_places_separator_between_branch_summaries(self): + separator = "\n" + "-" * 80 + "\n" + + result = _join_branch_summaries(["branch one", "branch two", "branch three"]) + + self.assertEqual( + result, + f"branch one{separator}branch two{separator}branch three", + ) + + def test_preserves_a_single_branch_summary(self): + self.assertEqual(_join_branch_summaries(["branch one"]), "branch one") + + +if __name__ == "__main__": + unittest.main()