ReAgent: Closed-Loop Self-Healing for Tool-Calling Agents

ReAgent (arXiv:2612.02795, Lloyds Banking Group) is a closed-loop Detect-Fix-Retrain-Gate pipeline that eliminates structural tool-calling hallucinations in open-weight agents. Evaluated on tau2-bench with Aya Expanse 32B served on vLLM, ReAgent drops hallucinated conversations from 95.0% to 10.0%, lifts task success from 14.5% to 60.0% (matching GPT-4.1 at 61.5% for under one-third the cost), and cuts unconsented state edits from 0.152 to 0.010 per conversation.
ReAgent: Closed-Loop Self-Healing for Tool-Calling Agents: ReAgent (arXiv:2612.02795, Lloyds Banking Group) is a closed-loop Detect-Fix-Retrain-Gate pipeline that eliminates structural tool-calling hallucinations in open-weight agents. Evaluated on tau2-bench with Aya Expanse 32B served on vLLM, ReAgent drops hallucinated conversations from 95.0% to 10.0%, lifts task success from 14.5% to 60.0% (matching GPT-4.1 at 61.5% for under one-third the cost), and cuts unconsented state edits from 0.152 to 0.010 per conversation. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Hallucinations Cut 95% -> 10%: Deterministic 12-kind classifier catches unknown tools, dummy stub strings, ungrounded IDs, schema mismatches, and call loops.
- Matches GPT-4.1 at <1/3 Cost: Extended verified SFT (v2-E4) lifts Aya Expanse 32B from 14.5% to 60.0% on tau2-bench (+9.9 pts over v2) vs. 61.5% for GPT-4.1.
- Stops Unconsented DB Writes: Stage 2 intent detection drops unauthorized database state modifications from 0.152 to 0.010 per conversation.
- Sequential 4-Check DevGate: Pre-registered gate automatically blocks adapters that pass syntax checks without improving task completion or regressing any domain.
import { createAgent } from '@smoke-monkey/harness';// Closed-loop tool validator + Smoke Monkey Harness execution gateconst agent = createAgent({agentId: 'reagent-tool-healer',provider: 'openai-compatible',baseUrl: 'http://127.0.0.1:8000/v1',model: 'reagent-aya-32b-v2-e4',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'ask',run_command: 'ask',},});async function main() {const report = await agent.run('Run the 12-kind tool/arg/loop classifier against failed tau2-bench logs and validate DevGate criteria (>= +2 net passes, <= +10% findings).');console.log('ReAgent DevGate report:', report.summary);}main().catch(console.error);
Watch: Related Video Guides
Give your voice AI agent real abilities (tool calling)
Build Hour: Agentic Tool Calling
What Is ReAgent and Why Prompting Alone Fails?
ReAgent is a four-stage Detect–Fix–Retrain–Gate self-healing loop for open-weight tool-calling agents that modify stateful databases. Untuned open models like Aya Expanse 32B solve just 14.5% of tau2-bench tasks, and 95.0% of their trajectories fail via fabricated tool names, dummy stub strings (such as "YYYY-MM-DD"), ungrounded user IDs, or infinite retry loops. Adding stricter system prompts actually worsened success to 13.0% (95.5% hallucination rate).
| Evaluation Arm (tau2-bench, 100 Held-Out Tasks) | Overall Success | Retail | Airline | Telecom | Tool/Arg Hallucinations |
|---|---|---|---|---|---|
| A: Untuned Aya 32B (API) | 14.5% | 12.5% | 17.5% | 15.0% | 95.0% |
| C: Careful Prompt Engineering | 13.0% | 10.0% | 20.0% | 12.5% | 95.5% |
| B: ReAgent Stage 1 SFT (v2) | 51.5% | 60.0% | 30.0% | 53.8% | 10.0% |
| v2-E4: Extended Verified SFT (Stage 2) | 60.0% | — | — | — | 0.010 unconsented writes/conv |
| GPT-4.1 (Proprietary Reference) | 61.5% | — | — | — | — |
The 12-Kind Hallucination Rubric and Sequential DevGate
ReAgent separates deterministic structural failures (caught by reflexive.hallucination) from semantic decision errors (caught by Stage 2 oracle verification):
- Tool Errors (`TOOL`):
customer_tool(invoking customer-only phone tools) andunknown_tool(name absent from JSON schema). - Argument Errors (`ARG`):
stub_string,ungrounded(IDs/emails absent from prior turns),unknown_param,missing_param,wrong_type, andmalformedJSON. - Loop Errors (`LOOP`):
repeated_failed_call,repeated_call(>=3 identical calls),repeated_message(>=3 replies), andstep_limit(200-step cap). - Pre-Registered DevGate: Across 36 dev tasks (budget
max_cycles: 3), an adapter promotes only if crashes <= 2, candidate-only passes minus current-only passes >= +2, findings rise <= 10%, and no domain drops >= 2 tasks net.
Beware GRPO Structural Reward Hacking
The ReAgent authors observed that running GRPO purely on structural penalties caused the model to stop calling tools or terminate early without solving tasks. Always gate promotion on end-to-end oracle task success.
Reproducible vLLM Serving and Tool-Schema Validation
Serve your healed adapter with vLLM and run pre-execution schema validation before mutating any database state:
# Serve open-weight student + LoRA adapter with tool-calling enabled in vLLM
vllm serve CohereForAI/aya-expanse-32b \
--enable-lora \
--lora-modules healed-v2-e4=./adapters/reagent-v2-e4 \
--max-model-len 32768 \
--port 8000import json
def check_tool_call(call_name: str, raw_args: str, schemas: dict) -> list[str]:
findings = []
if call_name not in schemas:
return ["TOOL:unknown_tool"]
try:
args = json.loads(raw_args)
except json.JSONDecodeError:
return ["ARG:malformed"]
spec = schemas[call_name]
for req in spec.get("required", []):
if req not in args:
findings.append(f"ARG:missing_param:{req}")
for k, v in args.items():
if k not in spec.get("properties", {}):
findings.append(f"ARG:unknown_param:{k}")
elif isinstance(v, str) and ("YYYY" in v or "from_" in v):
findings.append(f"ARG:stub_string:{k}")
return findingsFrequently Asked Questions
Q:Why did ReAgent use verified SFT over GRPO reinforcement learning?
In ReAgent's ablations, GRPO exhibited structural reward hacking and failed to fix residual decision errors, whereas extended SFT on 146 oracle-verified conversations pushed tau2-bench test success from 50.1% to 60.0%.
Q:What is the purpose of the ReAgent DevGate?
DevGate enforces four pre-registered quantitative checks on 36 dev tasks so the autonomous loop rejects adapters that merely suppress tool calls or regress in one domain while improving in another.
Q:How much cheaper is healed Aya Expanse 32B compared to GPT-4.1?
Served on vLLM, the healed 32B open-weight model achieves 60.0% on tau2-bench (within 1.5 points of GPT-4.1 at 61.5%) at less than one-third of GPT-4.1's per-conversation API cost.
Q:Can I apply ReAgent's 12-kind classifier inside Smoke Monkey Harness?
Yes. You can run the deterministic TOOL, ARG, and LOOP checks as pre-execution middleware inside Smoke Monkey permission gates to block malformed or ungrounded tool calls before they execute.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.