Skip to content

multi_session

diapason.learning.spec_search.multi_session

Multi-session loop for LLM-guided spec search (paper Algorithm 1).

The single-session SpecSearchOrchestrator.run(trigger) does one diagnose / plan / execute / record pass. Algorithm 1 in the paper specifies a multi-session loop that repeats this pass until either gate-score stagnation (default k = 5 sessions with no improvement) or budget exhaustion.

SpecSearchLoop wraps an existing SpecSearchOrchestrator and implements that stopping logic without modifying the orchestrator itself, so existing single-session callers and tests are unaffected.

LoopResult dataclass

Final state of a multi-session run.

stop_reason is one of:

  • "stagnation" — gate score did not improve for stagnation_k consecutive sessions.
  • "budget" — cumulative teacher cost reached max_total_cost_usd.
  • "failed" — a session returned SessionStatus.FAILED; the loop exits rather than burning more budget on a broken state.

SpecSearchLoop

Paper Algorithm 1: greedy gated edits across primitives, multi-session.

Parameters:

Name Type Description Default
orchestrator Any

a constructed SpecSearchOrchestrator. Each tick of the loop calls orchestrator.run(trigger).

required
stagnation_k int

stop after this many consecutive sessions with no gate-score improvement (paper default: 5).

5
stagnation_eps float

gate-score delta below this counts as "no improvement" — guards against floating-point noise.

0.001
max_total_cost_usd float

cumulative teacher-cost budget across all sessions. The loop stops as soon as this is exceeded.

50.0

run(trigger=None)

Run sessions until stagnation, budget, or failure.