Skip to content

Commit f24b1cf

Browse files
committed
fix: add stagnation_detector to loop docstrings, strengthen turn assertion
- Add stagnation_detector to PlanExecuteLoop and ReactLoop Args docstrings - Strengthen STAGNATION turn count assertion: verify both planning and tool-use turns are present (not just >= 1)
1 parent 70d97c4 commit f24b1cf

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/synthorg/engine/plan_execute_loop.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class PlanExecuteLoop:
9191
approval_gate: Optional gate that checks for pending escalations
9292
after tool execution and parks the agent when approval is
9393
required. ``None`` disables approval checks.
94+
stagnation_detector: Optional detector that checks for
95+
repetitive tool-call patterns within each step and
96+
intervenes with corrective prompts or early termination.
97+
``None`` disables stagnation detection.
9498
"""
9599

96100
def __init__(

src/synthorg/engine/react_loop.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ReactLoop:
7171
approval_gate: Optional gate that checks for pending escalations
7272
after tool execution and parks the agent when approval is
7373
required. ``None`` disables approval checks.
74+
stagnation_detector: Optional detector that checks for
75+
repetitive tool-call patterns and intervenes with
76+
corrective prompts or early termination. ``None``
77+
disables stagnation detection.
7478
"""
7579

7680
def __init__(

tests/unit/engine/test_plan_execute_loop.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,11 @@ async def test_stagnation_within_step_triggers_terminate(
923923

924924
assert result.termination_reason == TerminationReason.STAGNATION
925925
assert "stagnation" in result.metadata
926-
# STAGNATION result must include ALL turns, not just step-scoped
927-
assert len(result.turns) >= 1
926+
# STAGNATION result must include ALL turns (planning + tool-use),
927+
# not just step-scoped turns.
928+
assert len(result.turns) == 2
929+
assert result.turns[0].tool_calls_made == () # planning turn
930+
assert result.turns[1].tool_calls_made == ("echo",) # tool turn
928931

929932
async def test_stagnation_correction_in_step(
930933
self,

0 commit comments

Comments
 (0)