Skip to content

(bug) Cap oversized gateway tool outputs before they reach the model #5341

Description

@mmabrouk

When a long-running agent conversation calls a tool that returns a large result, the raw, unbounded result is inserted directly into the model context with no cap.

Reproduction

Observed live during v0.105.0 release-night QA (2026-07-14): a Composio get_pull_request call returned an entire PR patch, producing a single turn of ~241,000 tokens. Every subsequent model call in the conversation re-sends the full context, including that oversized turn, so the harness quickly hit provider rate/context limits.

From the outside this looks like the agent hanging:

  • The UI shows repeated Retrying (attempt 1/3, waiting 2s)... messages — this is pi-acp translating Pi's auto_retry events for failed provider calls.
  • The conversation appears stuck.
  • On pre-fix builds, the eventual failure surfaced to the user as "The agent produced no output," with no indication of the real cause.

This is believed to be the main driver behind the general "long conversations get weird" symptom seen across agent-workflows QA.

Steps to reproduce

  1. Start an agent conversation with a tool that can return large payloads (e.g. Composio get_pull_request against a PR with a sizeable diff).
  2. Let the agent call the tool and receive the full raw result into context.
  3. Continue the conversation for a few more turns.
  4. Watch provider calls fail/rate-limit and the harness loop on retry messages, eventually surfacing as a stuck or empty-output turn.

Related existing behavior

Transcript rebuilds already cap tool results at 4000 chars (TOOL_RESULT_RENDER_MAX_CHARS in services/runner/src/engines/sandbox_agent/transcript.ts), but this only applies when a transcript is rebuilt — LIVE turns have no cap, so the raw oversized result still enters context in real time.

Proposed direction

  • Cap or summarize oversized tool results at the tool/gateway layer, before they enter model context.
  • Steer tool schemas to request narrower results (e.g. file lists or specific files) instead of whole patches.

Evidence

docs/design/agent-workflows/projects/qa/STATUS.md on branch qa-prerelease-agent-runtime (v0.105.0 release-night QA, 2026-07-14).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions