Skip to content

feat(loop): add REASONIX anti-wandering loop guards - #178

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/loop-guards-reasonix
Open

feat(loop): add REASONIX anti-wandering loop guards#178
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:feat/loop-guards-reasonix

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

Adds anti-wandering loop guards to the agent runtime loop: an evidence ledger, a progress guard, a storm breaker, and delegation admission. When the model starts spinning (repeated tool calls producing no new evidence), the guards inject escalating interventions and can force a final answer instead of burning the remaining budget on the same failure pattern.

The engine lives in core/loop/guards.py (stdlib-only, zero internal dependencies) with an optional telemetry seam in core/loop/guard_telemetry.py (enabled via DEEPCODE_GUARD_TELEMETRY=1, zero overhead by default).

Wiring

  • runner.py — blocked short-circuit before tool execution, observe_batch injection after each tool batch, per-tool check_tool governance gate, and success-path observation hooks.
  • session.py — threads a LoopGuards instance through AgentSessionAgentRunSpec.
  • spawn_agent.py — delegation admission gate (REASONIX delegationAdmission adaptation) so a sub-agent that references parent-context without inheriting it (fork_turns='none') is rejected with an actionable error.
  • loop/__init__.py — public exports for the guard API.

Behavior notes

  • Guards are opt-in: guards: LoopGuards | None = None on AgentRunSpec; absent means zero cost.
  • Blocks are errors-as-data (never exceptions): the model reads the block reason as a tool result and wraps up cleanly.
  • guard_event_callback receives structured events (blocked / injection / tool_block) for telemetry without changing default logging behavior.

Testing

  • tests/test_guards.py — evidence ledger scoring, progress-guard escalation (2/4/6), storm-breaker circuit breaking, delegation admission.
  • tests/test_guard_telemetry.py — telemetry wiring and event payloads.
  • 37 new tests, all passing.

Origin

This is a Python port of the applyBatchGuards component family (evidence ledger, progress guard, storm breaker, delegation admission) from DeepSeek-Reasonix (MIT licensed), adapted to DeepCode's run-loop conventions. The implementation is a fresh Python rewrite following the original design semantics — not a code copy. Original project: esengine/DeepSeek-Reasonix (MIT License).

Port the REASONIX anti-wandering guard family (evidence ledger, progress
guard, storm breaker, delegation admission) into the agent runtime loop:

- core/loop/guards.py: guard engine (stdlib-only, no internal deps)
- core/loop/guard_telemetry.py: optional telemetry seam
- runner.py: blocked short-circuit, observe_batch injection, per-tool
  check_tool gate, success-path observation wiring
- session.py: thread LoopGuards instance through AgentSession/AgentRunSpec
- spawn_agent.py: delegation admission gate (REASONIX delegationAdmission)
- loop/__init__.py: public exports

Origin: Python port of the applyBatchGuards component family from
DeepSeek-Reasonix (https://github.com/esengine/DeepSeek-Reasonix, MIT
licensed), adapted to DeepCode's run-loop conventions. Implementation is
a fresh Python rewrite, not a code copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants