Repository navigation
Description
Agent loop allows simulated tool calls instead of enforcing real tool invocation
Summary
During testing of web_fetch in OpenClaw v2026.3.12, the agent frequently simulates tool usage in text instead of generating a real tool call.
Example output from the model:
To retrieve the content from the provided URL, I will use the web_fetch tool.
{
"tool": "web_fetch",
"args": {
"url": "https://nos.nl"
}
}
This is not a valid OpenAI-style tool call (tool_calls), but plain text generated by the model.
The agent loop currently accepts this output instead of enforcing a proper tool invocation.
Environment
OpenClaw:
v2026.3.12
Stack:
OpenClaw
LiteLLM
vLLM
local model (vllm_long)
Tools enabled:
web_fetch
web_search (Brave)
LiteLLM endpoint:
Reproduction
Agent prompt
Use web_fetch on https://nos.nl and return only the page title.
Result
The model outputs a textual explanation of how the tool works instead of triggering the tool.
Isolating the problem
To determine whether the issue is in the model stack or OpenClaw, tool calling was tested directly against LiteLLM.
Direct API test
Without forced tool choice:
POST /v1/chat/completions
The model does not produce tool_calls.
With forced tool choice:
"tool_choice": {
"type": "function",
"function": { "name": "web_fetch" }
}
Result:
finish_reason: tool_calls
The tool call is generated correctly.
Key finding
The model can produce valid tool calls, but does not reliably choose them autonomously.
This means the problem is not:
LiteLLM
vLLM
tool schema
web_fetch configuration
The issue lies in how OpenClaw handles tool invocation inside the agent loop.
Likely agent loop behavior
Based on observed behavior, the loop appears to do something similar to:
LLM → generate message
if tool_calls present:
execute tool
else:
send response
However, when the model outputs simulated tool usage in text, the agent loop treats this as a normal response instead of retrying or forcing a tool invocation.
Missing safeguards
The current agent loop appears to lack mechanisms to detect or correct simulated tool behavior.
Examples of missing safeguards:
- Tool simulation detection
Patterns such as:
{ "tool": "web_fetch" }
or
"I will use the web_fetch tool"
could trigger a retry with forced tool_choice.
- Deterministic tool routing
Certain cases are easily detectable:
URL present → web_fetch
search request → web_search
Allowing deterministic routing would significantly increase reliability.
- Tool call enforcement
If a tool is available and clearly required, the agent loop could retry with:
tool_choice = required
instead of allowing the model to continue.
Why this matters
Local model deployments are becoming common:
LiteLLM
vLLM
self-hosted models
Many of these models:
support tool calling
but are weaker at autonomous tool selection
Without stronger tool enforcement, OpenClaw agents become unreliable in these setups.
Suggested improvements
Possible improvements to the agent loop:
- tool simulation detection
Detect when the model describes tool usage instead of calling it.
- retry with forced tool_choice
If a tool is clearly required but not called, retry the turn with forced tool invocation.
- rule-based routing layer
Allow simple rules such as:
if url_detected → web_fetch
before sending the prompt to the model.
Conclusion
The infrastructure works correctly:
LiteLLM routing works
vLLM works
tool schema works
tool calls work when forced
The current limitation lies in how the OpenClaw agent loop handles tool invocation.
Without stronger enforcement, agents can simulate tool behavior instead of actually using tools.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
mindburnlabs commentedon Mar 21, 2026
This is an important security issue beyond just a model quality problem. The root cause is that the agent loop parses model output as tool invocations rather than requiring the model to emit valid
tool_callsobjects in the OpenAI format. When the model produces a JSON code block in text, the agent loop treats it as equivalent to a real tool call — but it's not. Real tool calls pass through the tool call pipeline; simulated text blocks don't.This has a direct security implication: all pre-execution hooks (
before_tool_call, policy checks, provenance tracking) are bypassed when the model routes around the tool call protocol with plain text. An adversary who can influence the model's output — via prompt injection in web_fetch output, for example — could cause the agent to produce a simulated tool call that the loop accepts, then escalate to a real tool call in a subsequent step after context has been poisoned. The simulated call is the taint injection vector.The fix isn't just stricter JSON parsing — it's enforcing at the agent loop level that tool invocations only happen via the
tool_callsprotocol field, and that any model output which appears to simulate a tool call in text is treated as a text response (no tool execution). The enforcement has to be structural: reject the pattern at the parsing layer, not by instructing the model not to do it.This is the same architectural principle as the CaMeL enforcement discussions in #48503 — enforcement primitives have to intercept at the protocol boundary, not rely on the model's compliance with instructions. The
before_tool_callhook only fires if the invocation reaches the tool pipeline through the proper path. Simulated calls are an entirely different code path that currently skips enforcement entirely.Adding a strict mode that rejects non-
tool_callstool invocations would also make HELM OSS-style execution enforcement more complete: the execution kernel can only audit and sign calls that actually pass through it.apoorv12 commentedon Apr 17, 2026
Adding a related-but-distinct failure mode on OpenClaw 2026.4.14,
pi-embeddedruntime,openrouter/openai/gpt-5.4-mini.This issue focuses on the model emitting a JSON tool-call shape in text, bypassing the OpenAI
tool_callsprotocol. We see a structurally worse variant: the model outputs a plain natural-language success claim with no tool-call shape at all — not a realtool_callsobject, not a simulated JSON-in-text. Just text like"Done. Note posted."or"PDF saved to <path>.", with zero corresponding exec/tool invocations in the turn's ledger.Two incidents (full detail in a comment on #49876):
approve(turn 2), emits "Done. Note posted" with zero tool calls. Ground-truth API query confirms zero writes.typst compile" → agent fetches real data via a Python wrapper (real exec) → emitsDRAFTblock citing a PDF path →typst compilenever fires → PDF doesn't exist on disk.The structural point @mindburnlabs raises — "all pre-execution hooks (
before_tool_call, policy checks, provenance tracking) are bypassed when the model routes around the tool call protocol" — applies here too, but via a different route. In #45049's case the simulated JSON can at least be syntactically detected. In our case there's no detectable simulation pattern; the model simply asserts completion in prose.The fix in this issue (strict
tool_callsprotocol at parsing layer) is necessary but not sufficient. An additional layer is needed: cross-reference success-claim verbs in outbound text against the turn's actual tool-call ledger, block delivery if claims aren't backed. Companion feature request filed as #68051 with a concrete config surface for this.Related: #49876 (same pattern in cron sessions), #44472 (
pi-embeddedruntime patches for the "premature success" bug), #51073 (critical fabrication tracking issue).openclaw-barnacle commentedon Apr 28, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
clawsweeper commentedon Apr 29, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 30, 2026, 11:30 PM ET / July 31, 2026, 03:30 UTC.
Summary
Keep open for maintainer review: the report has concrete multi-version evidence of agents returning text that claims a tool action without a corresponding structured call, while the merged Gateway HTTP work covers only caller-supplied OpenAI
tool_choicecontracts. The remaining agent-runtime enforcement policy is security- and compatibility-sensitive, and the currentsecuritylabel prevents automated cleanup.Likely related people: steipete (medium confidence, recent Gateway and agent-runtime area contributor); vincentkoc (medium confidence, Gateway compatibility contributor); Lellansin (medium confidence, authored the related Gateway contract work).
Reproducibility: no. high-confidence current-main live reproduction was established in this read-only review. The issue contains concrete provider runs and the prior source review identified the relevant text-versus-structured-call path, but the required enforcement policy has not been selected or tested on the current head.
Ways to help us reproduce this
Maintainer decision needed
Why: The reports establish a real integrity problem, but deciding which requests mandate a tool and whether to retry, fail, or deliver explanatory text changes agent behavior, provider compatibility, and operator expectations.
Next step
A maintainer must choose the scope and default behavior of the required-tool gate before a safe implementation can be designed; the protected security signal also excludes autonomous repair dispatch.
Security
Needs attention: The report raises a real action-integrity concern, but text-only output does not itself execute a tool or bypass the structured tool pipeline; the security-sensitive decision is how to enforce and report unmet required-tool policies.
Review details
Best possible solution:
Define one explicit, operator-visible required-tool or pre-response gate at the agent-runtime boundary: accept only ledger-backed structured calls for that policy, record a clear unmet-policy outcome, and return a visible retry/failure rather than treating fabricated success text as completion.
Do we have a high-confidence way to reproduce the issue?
No high-confidence current-main live reproduction was established in this read-only review. The issue contains concrete provider runs and the prior source review identified the relevant text-versus-structured-call path, but the required enforcement policy has not been selected or tested on the current head.
Is this the best way to solve the issue?
Unclear. The Gateway
tool_choicefix is a useful explicit-contract pattern, but broad text-pattern retries or URL routing are not the best general fix; a narrowly defined ledger-backed enforcement gate needs maintainer direction first.AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against 5337e85f111a.
Label changes
Label changes:
issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.clawsweeper:needs-live-repro: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.clawsweeper:source-repro: Current issue advisory state no longer selects this label.issue-rating: 🦞 diamond lobster: Current issue advisory state no longer selects this label.Label justifications:
P1: Users can receive a convincing completion reply while the requested tool action never occurs, breaking real agent workflows.impact:security: The report concerns enforcing that actions and policy checks are represented by real protocol-level tool events rather than unverified assistant claims.impact:session-state: Reported session ledgers can contain no tool-call or tool-result entries even when the final text claims an operation ran.impact:message-loss: A channel can receive a final-looking response in place of the expected externally grounded action or result.Evidence reviewed
Security concerns:
A model can present a plausible tool result in final text without a matching structured invocation or ledger entry, so workflows that require an action need a policy boundary that records and surfaces the unmet requirement rather than trusting prose.
Confidence: 0.84
What I checked:
src/gateway/openai-http.ts, f87c4c6f2e3f)src/agents/agent-loop.ts)VISION.md:19, 5337e85f111a)src/gateway/openai-http.ts, f87c4c6f2e3f)Likely related people:
tool_choiceenforcement work and is identified in that PR’s history as a recent contributor to the affected Gateway compatibility path. (role: recent area contributor and merger; confidence: medium; commits: 242eab9d20f7, fde9fb05dfcf, aabdc63d20cb; files:src/gateway/openai-http.ts,src/gateway/openresponses-http.ts)src/gateway/openai-http.ts,src/gateway/openresponses-http.ts,src/gateway/openai-http.test.ts)src/gateway/openai-http.ts,src/gateway/openresponses-http.ts,src/gateway/openai-http.test.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.camerono commentedon May 1, 2026
Adding fresh evidence on OpenClaw 2026.4.9 (gateway in local mode,
openclaw agent --jsoninvocation path, not the TUI). The simulated-tool-call pattern this issue describes still fires, and in a worse-than-text-only shape: with the model's chat-template special tokens leaked into the assistant text along with a fabricatedtoolResult.Stack
127.0.0.1:18789).vllm/vllm-openai:lateston127.0.0.1:8002with--enable-auto-tool-choice --tool-call-parser hermes --gpu-memory-utilization 0.20 --max-model-len 32768.NousResearch/Hermes-3-Llama-3.1-8B, served-namehermes-3-llama-3.1-8b.bootstrapMaxChars=1500,bootstrapTotalMaxChars=12000,skipBootstrap=true. AGENTS.md rewritten with tool-rules at top.agents.defaults.params.temperature=0,seed=42. Behavior reproduces at default temperature too — but is now deterministic.Repro (from a real test harness run)
The user prompt explicitly directed the model toward
exec:The session jsonl at
~/.openclaw/agents/main/sessions/c75ad1a9-7acb-4802-92b5-cbc2b7bdd3be.jsonlshows:toolCallcontent-items inside anymessage.content[].role: "toolResult".textcontent-item containing this body verbatim:The model fabricated the entire exec invocation including a structurally-correct toolResult with the specific expected stderr — without invoking any tool. The fabricated stderr is exactly what
catwould say in this case (directionally accurate confabulation), which makes it worse — if the file had existed, the agent would have confidently said it didn't.Two intersecting bugs
This run actually reproduces two of the issue classes the thread has discussed:
://exec: exec(...) -> {...}block was treated as a plain assistant reply rather than rejected or retried withtool_choice: required.clawsweeper's 2026-04-29 review correctly notes that current main hasdetectToolCallShapedTextfor diagnostic logging but no enforcement; this evidence shows that's still where the bug lives in 2026.4.9.stripModelSpecialTokensnot applied to the main output path. The leaked<|end_of_text|>and<|begin_of_text|>tokens are exactly what the existingMODEL_SPECIAL_TOKEN_REregex would match. They reach the user-facing reply because the sanitizer isn't called from theopenclaw agent --jsonpath.A protocol-boundary fix (this issue) plus turning the existing sanitizer on in the main path (#44179) would close both. Either alone leaves the other.
On
apoorv12's comment about claim-vs-ledger cross-referencingThe
apoorv122026-04-17 comment is right that strict-tool_callsenforcement isn't sufficient for all the fabrication shapes we're seeing. We have a separate row from the same test session (T2.C2.2.b) where the model dispatchedweb_fetchcorrectly, then dispatchedexec date -u(which failed at the gateway because the model self-imposedsecurity: "allowlist"), and then fabricateddate=2023-05-01from training data — claiming a date in the assistant text that contradicted the real toolResult ("exec denied: allowlist miss"). Strict-protocol enforcement would have prevented the fake-tool-call shape we're showing here, but a separate claim-vs-ledger check would be needed for the date-fabrication shape.In our local extension-candidates ledger (
nemoclaw/docs/extension-candidates.mdin our project) we've sketched this as a stochastic-sampling middleware (EC-1) that does both checks: (a) any tool-result-shape claim must trace back to a realtoolCall+toolResultpair in the session jsonl; (b) any text claim that contradicts a real toolResult body must be flagged. We'd be happy to align with whatever maintainer-approved strict-protocol policy this issue lands on so the two checks compose cleanly.Reproducibility note
We ran this with
agents.defaults.params.temperature=0+seed=42, applied viaopenclaw config set agents.defaults.params.temperature 0 --strict-jsonand asystemctl --user restart openclaw-gateway.service. The<|end_of_text|>-leak shape didn't reproduce on the same prompt at temp=0 in the round 3 run (the model preempted with bareNO_REPLYinstead — no leak, but also no dispatch and no useful output). At default temperature in our round 2 run it did reproduce. So the fabricated-tool-call-as-text path appears to be reachable both deterministically and stochastically, depending on prompt shape and sampling.Happy to provide the full session jsonl, harness output, and run config if useful.
17 remaining items
wzg0911 commentedon Jul 26, 2026
Root Cause Analysis
I've analyzed this issue extensively. The problem you've identified is correct: the agent loop accepts simulated tool invocations as plain text instead of enforcing real tool calls. This is particularly critical for security-sensitive operations where agents must be prevented from "pretending" to execute tools.
From the ClawSweeper review on 2026-04-29, current main has
detectToolCallShapedTextfor diagnostic logging but lacks enforcement. This confirms the core issue: detection exists, but enforcement is missing.Technical Context
The agent loop flow in
src/agents/agent-loop.tscurrently:tool_callsin the responseThe missing safeguard: retry with
tool_choice: requiredwhen simulation is detected.Workaround for Current Version (2026.3.12 - 2026.4.9)
You can force tool execution at the session level:
```bash
Force a specific tool for the session
openclaw config set session.toolChoice required
Or for a specific tool
openclaw config set session.toolChoice '{"type": "function", "function": {"name": "web_fetch"}}'
```
For vLLM/LiteLLM setups, also consider:
```bash
Add a deterministic routing layer before the model
This example uses a simple script to detect URLs and pre-route to web_fetch
openclaw skill create url-router --description "Detect URLs and force web_fetch routing"
```
Recommended Fix Path
The proper fix requires changes to the agent loop:
detectToolCallShapedText)```typescript
if (detectToolCallShapedText(message.content)) {
// Retry the turn with tool_choice: required
return retryWithForcedToolCall();
}
```
Related Issues
This connects to broader session-state integrity concerns tracked in #61238 - agents should never be able to "fake" tool execution when security-sensitive operations are involved.
For local model deployments (vLLM, LiteLLM), stronger tool enforcement is critical for reliability. The infrastructure works; the limitation is in the agent loop's enforcement logic.
Cross-posted from ARK project.
openclaw-barnacle commentedon Aug 14, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
openclaw-barnacle commentedon Aug 22, 2026
Closing due to inactivity.
If this is still an issue, please retry on the latest OpenClaw release and share updated details.
If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.