openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Text-mode tool calls silently dropped when a small model garbles <tool_call> tags with pipes

Open yh928 opened this issue 4 months ago • 0 comments

Summary

When a small model drives a large Composio toolkit in text mode, it sometimes leaks its native <|…|> sentinel-token pipes into the <tool_call> markers (e.g. <|tool_call>call:{…}<tool_call|>). The garbled tags match no grammar, so the whole tool call is silently dropped as narrative text — the tool never runs, and the model then tends to answer with a hallucinated "no results".

Problem

What happens: In text-mode tool calling (used when a toolkit is too large for the provider's native tool-schema grammar — e.g. integrations_agent with a Composio toolkit filter), a weak model emits tool calls whose delimiter tags are corrupted by its own sentinel tokens:

  • <|tool_call>call:{"name":"GMAIL_FETCH_EMAILS", …}<tool_call|>
  • symmetric variants: <|tool_call|> … <|tool_call|>
  • a leading call: before the JSON body

What's expected: The tool call is parsed and executed.

Actual: parse_tool_calls / parse_tool_calls_with_pformat only recognize the canonical <tool_call>…</tool_call> (and clean tag variants). The pipe-garbled shapes fall through every branch, get treated as plain assistant text, and the tool is never dispatched. The user sees a confident but wrong "no results" / "nothing found" reply instead of the actual tool output.

Impact: Any text-mode agent on a weak/fast model tier can silently fail to act — most visibly the integrations agent (Gmail, calendar, etc.) returning empty answers while claiming it searched. Intermittent and model-dependent, so it reads as a flaky integration rather than a parser gap.

Steps to reproduce (observed):

  1. Run a text-mode agent session with a large Composio toolkit on a small/fast model tier (the burst tier in a sub-agent path forces text mode).
  2. Ask it to perform a toolkit action (e.g. "fetch my latest emails").
  3. Inspect the raw assistant message in the session transcript: the <tool_call> markers carry | pipes (<|tool_call>…<tool_call|>).
  4. Observe the harness produced no tool call and the model answered result: [] / "no results".

Version / platform: dev build, Linux (headless core). Text-mode tool-call path in src/openhuman/agent/harness/parse.rs. Model-dependent (weak/fast tiers under the sub-agent text-mode path).

Solution

Add a format-agnostic normalization pass at the two parse entry points (parse_tool_calls, parse_tool_calls_with_pformat): locate every tool_call-family tag (any pipe/slash/whitespace garble) with one tolerant regex, then pair them positionally — 1st open, 2nd close, … — rewriting each pair to canonical <tool_call>BODY</tool_call> and stripping a leading call:. Positional pairing avoids the unreliable per-tag open/close guess a string-replace map needs. It is a cheap Borrowed no-op unless a piped tag is actually present, so well-formed output and P-Format name[a|b] pipe args are left untouched. <tool_calls> (plural JSON key) and <invoke> are excluded.

Acceptance criteria

  • [ ] Repro gone — pipe-garbled <tool_call> tags in text mode are parsed and the tool executes instead of being dropped as text.
  • [ ] Regression safety — unit coverage for the garbled shapes (JSON body + call: prefix, multiple parallel calls, symmetric pipe tags) plus negatives (clean output and P-Format pipe args left untouched).
  • [ ] Diff coverage ≥ 80% — the fix PR meets the changed-lines coverage gate.

Related

  • Fix PR: #4938
  • Context: text-mode tool calling is forced for integrations_agent when a toolkit filter is present because a large Composio toolkit exceeds the provider's native tool-schema grammar ceiling.

yh928 avatar Jul 16 '26 01:07 yh928