mandatory_tool_rulesο
Mandatory tool injection rules β Autonomic Reflex Vβ¨-666. # πͺβ§οΈπ
Evaluates contextual conditions and returns forced tool execution
directives. When a rule fires, the transport layer sets tool_choice
in the API payload so the model cannot skip tool execution.
- Rules:
needle_judo_stall: Escalation Rule 5 β needle judo stalled for 3 turns β forcesneedle_view_plan(route-planner injection rides in viacontext_injections). Priority 4 (highest).parallax_or_needle_escalation: Escalation Rules 1 & 6 β forcesparallax_reasoningon ANY friction across all 13 guard buckets (5 original + 5 expansion + distress/sexual-spiral/rigidity), and for the 3-turn re-evaluation cycle during needle judo. Priority 5.needle_judo_escalation: Escalation Rules 3-5 β understanding gate failed β forces the needle belt (co-regulation or Solo Mode). Priority 6.parallax_cold_channel: Forcesparallax_reasoning(analyze) when the active channel has zero established axioms in DB12.needle_active_plan: Forces needle tools when a plan is active.hex_chess_active: Forcesactivate_hexwhile Loopmother Chess locks the channel.snes_game_session: Forces game choice tools during S.N.E.S.babystar_playpen: Forces spell tools in playpen channels.gock_hypervisor: Keeps market-aware GOCK rooms wired to embodied, Timebender, Parallax, and Needle tooling.
The full escalation ladder (5 trigger categories, co-regulation vs Solo
Mode, understanding gate, stall detection, de-escalation) lives in
escalation_state.py.
- Architecture:
Rules are Python-native (fast, version-controlled).
Each rule is an async condition that receives message context.
First matching rule wins for
tool_choicemode.All matching rulesβ tools are merged into the available set.
The forced choice decays after
max_rounds(default 1).
- class mandatory_tool_rules.MandatoryToolRule(name='', description='', condition=None, tools=<factory>, tool_choice_mode='required', priority=50, max_rounds=1, cooldown_seconds=0.0)ο
Bases:
objectOne mandatory injection rule. # π
The fields have these semantics:
nameβ Machine-readable rule identifier for logs and telemetry.descriptionβ Human-readable label.conditionβ Async callable acceptingmsg,redis, androom_context.toolsβ Tool names to force-inject into the available set.tool_choice_modeβ"required"(any tool),"specific"(the first exact name intools), or"available"(inject only).priorityβ Lower values wintool_choice; all matching rules still merge their tools.max_roundsβ Number of tool rounds for which the forced choice persists.cooldown_secondsβ Minimum seconds between firings per channel.
Ordinary prose is intentional here. A Napoleon
Attributessection would index these dataclass fields once, and autodoc:members:would index them again, making the strict Sphinx-Wbuild fail on duplicate object descriptions.- Parameters:
- class mandatory_tool_rules.MandatoryInjectionResult(rule_name='', tools=<factory>, tool_choice_payload=None, max_rounds=1)ο
Bases:
objectWhat the evaluator returns when at least one rule fires. # π₯
- Parameters:
- async mandatory_tool_rules.evaluate_mandatory_rules(msg, redis, room_context, tool_names, registry)ο
Evaluate all mandatory injection rules and return the first match.
- Parameters:
msg (
IncomingMessage) β The incoming user message.redis (
Any) β Async Redis client (main DB, not DB12).room_context (
dict[str,Any] |None) β The room context dict (may be None).tool_names (
list[str]) β Currently resolved tool names (for dedup).registry (
Any) β The ToolRegistry (to verify tool names exist).
- Return type:
- Returns:
A
MandatoryInjectionResultif any rule fired, elseNone.