feat(loop): add REASONIX anti-wandering loop guards - #178
Open
raymondginger2018-sudo wants to merge 1 commit into
Open
feat(loop): add REASONIX anti-wandering loop guards#178raymondginger2018-sudo wants to merge 1 commit into
raymondginger2018-sudo wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 incore/loop/guard_telemetry.py(enabled viaDEEPCODE_GUARD_TELEMETRY=1, zero overhead by default).Wiring
runner.py— blocked short-circuit before tool execution,observe_batchinjection after each tool batch, per-toolcheck_toolgovernance gate, and success-path observation hooks.session.py— threads aLoopGuardsinstance throughAgentSession→AgentRunSpec.spawn_agent.py— delegation admission gate (REASONIXdelegationAdmissionadaptation) 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: LoopGuards | None = NoneonAgentRunSpec; absent means zero cost.guard_event_callbackreceives 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.Origin
This is a Python port of the
applyBatchGuardscomponent 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).