File size: 1,566 Bytes
e266561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
"""
gate_node.py β€” Safety gate that controls access to the full solution.

Gate logic (priority order):
  1. If turn_count < 2 AND gap_magnitude <= 7  β†’ force hint (too early)
  2. If gap_magnitude > 7                       β†’ allow solution (completely lost)
  3. Otherwise                                  β†’ force hint (encourage effort)

This prevents immediate solution bypass while still being helpful for users
who are genuinely stuck and unable to make progress.
"""

from agent.models import AgentState


def gate_solution(state: AgentState) -> dict:
    """
    Evaluates whether to allow solution reveal or force a hint.
    Updates request_mode to 'solution' or 'hint_forced' accordingly.
    Does NOT call the LLM β€” purely deterministic routing.
    """
    turn_count = state.get("turn_count", 0)
    gap = state.get("gap_magnitude", 5)

    # Already in solution mode β€” apply gate logic
    if state.get("request_mode") == "solution":
        if gap > 7:
            # User is completely stuck β€” allow solution compassionately
            return {"request_mode": "solution"}
        elif turn_count < 2:
            # Too early β€” redirect to hint flow
            return {
                "request_mode": "hint_forced",
                "final_response": None,  # Clear any stale response
            }
        else:
            # Enough turns done and not completely lost β€” still redirect
            return {"request_mode": "hint_forced", "final_response": None}

    # Not a solution request β€” pass through unchanged
    return {}