Spaces:
Sleeping
Sleeping
| """ | |
| 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 {} | |