mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 19:04:50 +07:00
[PR #640] serve: the loop guard across turns - an agent's tool call made again and again with the same result gets a message to try something else #644
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#644
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/640
Author: @merbanan
Created: 10/28/2026
Status: 🔄 Open
Base:
main← Head:pr/loop-guard-tools📝 Commits (1)
fc5db3eserve: the loop guard across turns - an agent's tool call made again and again with the same arguments and result gets a message after its 3rd result: nothing new, try a different approach or answer (GLM-5.3 over opencode ran two commands in turn 25 times, every answer short and fine; loop_guard.tool_repeat, maya:loop_guard_tool_repeats_total)📊 Changes
5 files changed (+160 additions, -11 deletions)
View changed files
📝
docs/SETTINGS.md(+8 -1)📝
serve/loop_guard.py(+56 -0)📝
serve/server.py(+29 -7)📝
serve/test_loop_guard.py(+63 -1)📝
serve/web/monitor.js(+4 -2)📄 Description
What
The loop guard catches a loop inside one answer: a block of tokens repeated back to back. An agent can also loop across turns, where every answer is short and fine on its own:
The guard never sees this, because each answer is a new request.
Seen on the live service. GLM-5.3-Flash (EXL3 2.05bpw) was working over opencode in a 65K conversation.
nmcli … | grep pmfand agrep … src/uplink.cpp.The change
When a request ends with tool results, the server looks at the tool calls since the user's last message (
loop_guard.tool_repeat).When it counts as a loop: the last call's name, arguments and result are all the same as at least 2 others among the last 12 calls. That makes this call the 3rd of its kind.
What happens then: a short user message follows that result, marked as the server's:
What doesn't count:
make testwith another result each time).Reporting:
[maya] loop guard:bash3 times with the same arguments and result: a note after it./metricsloop_guard.tool_repeatsandmaya:loop_guard_tool_repeats_totalcount these notes, and the Monitor's totals line includes them.Settings: the same as the loop guard's (on by default;
MAYA_LOOP_GUARD=0,"loop_guard": falsein the config or in a request). It covers Chat Completions, Anthropic Messages, Responses and the web app's MCP rounds.docs/SETTINGS.mdhas a bullet under "The loop guard".Why a message and not text in the tool's result. I tried both on the live model with the same conversation: three identical
nmclirounds, temperature 0."loop_guard": false)nmclicommand a 4th timenmclicommand a 4th timeTests
serve/test_loop_guard.py::ToolRepeat(2 tests). They cover:"loop_guard": false, which turns it off;/metricsand Prometheus.All 24
serve/test_*.pysuites pass on v1.1.36. The change has been running on the live V100 GLM service.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.