File size: 1,429 Bytes
c0e3412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Phase III: Cognitive Descent."""

from __future__ import annotations

import time

from ..core import DescentVector
from ..types import PhaseOutput, RunConfig, SolutionState


def run(state: SolutionState, config: RunConfig) -> tuple[SolutionState, PhaseOutput]:
    t0 = time.perf_counter()
    # cache_mode "offline" means: no network. Use deterministic heuristic
    # refinement so the descent stays reproducible (and tests stay hermetic).
    descent = DescentVector(
        offline=(config.cache_mode == "offline"),
        model=config.model_name,
    )
    initial_context = {
        "problem": state.problem,
        "block_solutions": state.block_solutions,
        "building_height": state.building_height,
        "blocks": state.blocks,
    }
    descent_result = descent.cognitive_descent(state.building_height, initial_context)
    dt = time.perf_counter() - t0
    state.extra["descent_result"] = descent_result
    return (
        state,
        PhaseOutput(
            name="phase3_cognitive_descent",
            input={"building_height": state.building_height},
            output={
                "final_answer": descent_result.get("final_answer", ""),
                "counterfactual_summary": descent_result.get("counterfactual_summary", ""),
                "attribution_explanation": descent_result.get("attribution_explanation", ""),
            },
            duration_sec=dt,
        ),
    )