Agent Routing & Modal Lock Patterns

VerifiedSafe

Reference for WorldArchitect agent routing priority and modal lock patterns, including stale flag guards and cross-modal scoping.

Sby Skills Guide Bot
DevelopmentAdvanced
8/29/2026
Claude Code
#agent-routing#modal-locks#state-management#worldarchitect#python

Recommended for

Automated summary

Documents WorldArchitect's agent routing priority order and modal lock patterns, including guards against stale state flags.

Strengths

  • Presents an explicit ordered routing chain from GodModeAgent down to the StoryModeAgent fallback.
  • Details concrete guards that distinguish None from False to prevent modal reactivation.
  • Explains cross-modal flag isolation between character creation and level-up modals.
  • Covers finish-choice injection and time freezing during modals.

Limitations

  • Highly specific to the WorldArchitect codebase and its agents.py and world_logic.py files.
  • Acts as a compact reference that points to code rather than providing a full implementation.
  • Assumes warnings-only error handling with no assertions, retries, or default content.
When to use it

Use it to diagnose or modify agent routing and modal locks in WorldArchitect.

When not to use it

Do not use it for another project or for generic agent-routing guidance without WorldArchitect context.

Security analysis

Safe
Quality score74/100

This is a pure documentation/reference file. It declares no allowed-tools and contains only prose, a Markdown table, and inert Python code snippets illustrating routing and modal-lock patterns. There are no executable instructions, no shell commands, no network or credential access, and no attempts to disable safety controls, so listing it carries no meaningful execution risk.

No concerns found

How this analysis is made

Examples

Debug reactivating level-up modal
Review why the level-up modal keeps reactivating in WorldArchitect after it was completed, and identify which stale flag guard in agents.py should prevent it.
Add a routing rule
Add a new routing rule between active combat and the semantic intent classifier in get_agent_for_input(), and update the routing priority documentation accordingly.
Explain finish choice injection
Explain how _inject_modal_finish_choice_if_needed avoids race conditions and where the canonical finish choice should be placed in planning_block.choices.

name: agents description: Reference WorldArchitect agent routing priority and modal lock patterns.

Agent Routing & Modal Lock Patterns

COMPACTNESS RULE: Keep this file under 200 lines. Link to code instead of duplicating implementation details.

Error Handling: Warnings only - no assertions, retries, or default content. Log issues explicitly and let validation catch failures rather than silently backfilling missing data.

Agent Routing Priority ($PROJECT_ROOT/agents.py)

Routing order in get_agent_for_input():

  1. GodModeAgent - Manual override (GOD MODE: prefix)
  2. Character Creation Completion Override - Forced exit from modal
  3. MODAL LOCKS - CharacterCreationAgent, LevelUpAgent (highest priority active state)
  4. CampaignUpgradeAgent - State-based (ascension ceremonies)
  5. CharacterCreationAgent - State-based (new character or level-up)
  6. Active Combat - State-based (in_combat=True)
  7. Semantic Intent Classifier - Primary routing brain (FastEmbed)
  8. Explicit Mode Override - API parameter
  9. StoryModeAgent - Default fallback

Modal Lock Enforcement

Critical Pattern: Stale Flag Guards

Problem: Leftover flags (e.g., level_up_pending=True) from previous modal sessions can incorrectly reactivate modals.

Solution: Check for explicit False flags that indicate intentional deactivation:

# In agents.py get_agent_for_input():
level_up_in_progress = custom_state.get("level_up_in_progress")
if level_up_in_progress is False:  # Explicit False = stale guard
    level_up_modal_active = False

level_up_pending_flag = custom_state.get("level_up_pending")
if level_up_pending_flag is False and not bool(level_up_in_progress):
    level_up_modal_active = False

Why: None (unset) vs False (explicit guard) distinction prevents modal reactivation from stale data.

Modal Scoping: Cross-Modal Flag Isolation

Problem: Character creation lock was protecting ALL custom_state flags, including level-up flags.

Solution: Scoped protection per modal type (world_logic.py _should_protect_field()):

  • Character creation modal: Only protects character creation flags
  • Level-up modal: Only protects level-up flags
  • Prevents cross-modal interference (char creation forcing level_up_in_progress=True)

Level-Up Activation Triggers

Modal activates when ANY of these are true:

  1. level_up_in_progress=True (explicit in-progress flag)
  2. level_up_pending=True (pending flag from rewards)
  3. rewards_pending.level_up_available=True (rewards system signal)

Prevented by stale guards: If level_up_in_progress=False or level_up_pending=False explicitly set, modal won't activate.

Finish Choice Injection (world_logic.py)

Modal exit enforcement via server-side choice injection:

# In _inject_modal_finish_choice_if_needed():
# 1. Uses pre-update state (not post-update) to prevent race conditions
# 2. Checks modal is active (no stale guards blocking)
# 3. Adds canonical finish choice as LAST item in planning_block.choices
# 4. Uses structured_fields["planning_block"] not structured_response (preserves injection)

Key fix: Use current_game_state_dict (pre-update) instead of updated_game_state_dict to avoid race condition where LLM sets level_up_in_progress=False in same turn.

Time Freezing During Modals

Level-up and character creation modals freeze game time:

# In world_logic.py should_freeze_time():
is_char_creation = not custom_state.get("character_creation_completed", False)
is_level_up_mode = custom_state.get("level_up_in_progress", False) or \
                   custom_state.get("level_up_pending", False)
return is_char_creation or is_level_up_mode

Common Issues & Fixes

| Issue | Root Cause | Fix Location | Fix | |-------|-----------|--------------|-----| | Modal bypass | level_up_pending=True didn't activate lock | agents.py:2871-2876 | Added pending flag to activation logic | | Routing inconsistency | Injection used different detection logic than routing | agents.py + world_logic.py | Unified stale flag guards | | Cross-modal interference | Char creation protected level-up flags | world_logic.py _should_protect_field() | Scoped protection per modal | | Finish choice position | LLM response overwrote server injection | world_logic.py:5414 | Use structured_fields not structured_response | | Stale reactivation | Old flags reactivated completed modals | agents.py:2864-2876 | Check explicit False flags |

Testing Patterns

Unit Tests ($PROJECT_ROOT/tests/):

  • test_rev_439p_modal_bypass.py - Activation with level_up_pending=True
  • test_rev_0g1y_inconsistent_detection.py - Stale flag guard consistency
  • test_world_logic.py::TestModalLockFlagScoping - Cross-modal isolation

E2E Tests (testing_mcp/creation/):

  • test_level_up_modal_flow_real.py - Full modal lifecycle with real LLM
  • test_character_creation_agent_real_e2e.py - Character creation flows

Quick Reference

Agent matching check order:

  1. State-based: matches_game_state(game_state)
  2. Intent-based: Semantic classifier or matches_input(user_input)
  3. Explicit: Mode parameter override

Modal debugging:

  • Check level_up_in_progress, level_up_pending, rewards_pending.level_up_available
  • Look for stale flags: explicit False values blocking activation
  • Verify character_creation_completed not interfering with level-up

See also:

  • .claude/skills/character-creation-modal-exit.md - Character creation specific patterns
  • $PROJECT_ROOT/agents.py - Full implementation (lines 2739-3200)
  • $PROJECT_ROOT/world_logic.py - Modal injection and protection (lines 1800-1900, 5400-5500)

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/agent-routing-modal-lock-patterns-mte1lk7t/download' --output '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md.part' && mv '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md.part' '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Original excerpt: Quick Reference

Agent matching check order:

  1. State-based: matches_game_state(game_state)
  2. Intent-based: Semantic classifier or matches_input(user_input)
  3. Explicit: Mode parameter override

Modal debugging:

  • Check level_up_in_progress, level_up_pending, rewards_pending.level_up_available
  • Look for stale flags: explicit False values blocking activation
  • Verify character_creation_completed not interfering with level-up

See also:

  • .claude/skills/character-creation-modal-exit.md - Character creation specific patterns
  • $PROJECT_ROOT/agents.py - Full implementation (lines 2739-3200)
  • $PROJECT_ROOT/world_logic.py - Modal injection and protection (lines 1800-1900, 5400-5500)

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md' && test -s '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/agents' && cp -R '.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t' '.claude/skills/agents'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t'

openskills read 'agent-routing-modal-lock-patterns-mte1lk7t'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/agent-routing-modal-lock-patterns-mte1lk7t/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills