multi_session
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.
Classes¶
LoopResult
dataclass
¶
LoopResult(sessions: list[LearningSession] = list(), stop_reason: str = 'stagnation', total_cost_usd: float = 0.0, best_overall_score: float = 0.0)
Final state of a multi-session run.
stop_reason is one of:
"stagnation"— gate score did not improve forstagnation_kconsecutive sessions."budget"— cumulative teacher cost reachedmax_total_cost_usd."failed"— a session returnedSessionStatus.FAILED; the loop exits rather than burning more budget on a broken state.
SpecSearchLoop
¶
SpecSearchLoop(orchestrator: Any, *, stagnation_k: int = 5, stagnation_eps: float = 0.001, max_total_cost_usd: float = 50.0)
Paper Algorithm 1: greedy gated edits across primitives, multi-session.
Args:
orchestrator: a constructed SpecSearchOrchestrator. Each tick
of the loop calls orchestrator.run(trigger).
stagnation_k: stop after this many consecutive sessions with no
gate-score improvement (paper default: 5).
stagnation_eps: gate-score delta below this counts as "no
improvement" — guards against floating-point noise.
max_total_cost_usd: cumulative teacher-cost budget across all
sessions. The loop stops as soon as this is exceeded.
Source code in src/openjarvis/learning/spec_search/multi_session.py
Functions¶
run
¶
run(trigger: Any | None = None) -> LoopResult
Run sessions until stagnation, budget, or failure.