MCP Loop Cycling and Gating
The agent loop system
Neurova's agent loops are managed through a Loop registry. Each loop implements the interaction logic for a class of models and is selected automatically by model match via @register_loop:
- OpenAILoop (priority=10) — matches OpenAI-compatible models such as
gpt-,openai/,qwen.anddeepseek- - AnthropicLoop (priority=20) — matches
claude-andanthropic/models
Priority rule: the loop with the stronger model match wins (AnthropicLoop 20 > OpenAILoop 10).
Loop gates
The gate system checks whether to continue after each iteration of the agent loop, returning one of three decisions:
| Decision | Behaviour | When it applies |
|---|---|---|
| BYPASS | Continue, with no intervention | Normal execution |
| INTERRUPT_AND_CONTINUE | Inject a prompt and continue (soft intervention) | The gate's opinion is passed to the LLM so it can correct itself |
| TERMINATE | End the loop (hard stop) | The loop stops immediately — for example when DoomLoop detects a cycle |
Properties of the three-state gate
- Fault isolation: if a gate itself throws, it degrades to BYPASS plus a warning rather than blocking the main flow
- TERMINATE takes precedence: a hard stop outranks every soft intervention
- Kinds of gate: DoomLoopGate (sliding-window similarity detection for runaway loops), plus token, iteration and timeout budget gates
Design rationale
Adopting three-state stop-gate semantics (BYPASS / INTERRUPT_AND_CONTINUE / TERMINATE), Neurova gives the agent loop both an intelligent soft correction and an emergency hard brake — so an agent cannot spin uselessly in a runaway loop burning resources.
Key files
neurova/agent/gates.py # three-state StopAction gating (BYPASS / INTERRUPT / TERMINATE)
```