Skip to content

feat: truncate oversized web tool output - #70

Merged
K-Mistele merged 1 commit into
mainfrom
add-output-truncation-hooks-for-web-tools
Aug 18, 2026
Merged

feat: truncate oversized web tool output#70
K-Mistele merged 1 commit into
mainfrom
add-output-truncation-hooks-for-web-tools

Conversation

@K-Mistele

@K-Mistele K-Mistele commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Why the change

Large successful web fetches and searches now stay within the model-context budget while their complete serialized output remains available through the existing Read tool.

Special things to note

  • The hook matches the dispatched web_fetch and web_search registry keys because their underlying interfaces are named webfetch and websearch.
  • Spilled results use AgentLayer's existing anonymous OS-temp agent-tool-output-* directories rather than session-persistent storage.

Change outline

Business logic

postToolUse(web_fetch | web_search)
  if output is not a string, or is within 2,000 lines and 50 KiB
    keep the serialized result unchanged
  otherwise
    keep a head excerpt at whole-line boundaries
    save the complete serialized result to an OS-temp file
    replace history output with the excerpt, saved path, and Read offset
    first line exceeds byte limit -> instruct Read from offset 1

Files

agentlayer/
├── packages/agentlayer-filesystem/
│   ├── src/hooks/output-truncation.ts  # web-specific spill hook and Read guidance
│   ├── src/coding-agent.ts             # canonical filesystem hook chain
│   └── test/                           # boundaries, spill content, hook composition
├── agents/codelayer/
│   ├── src/agent.ts                    # root and RLM hook composition
│   ├── src/coding-subagent-tool.ts     # specialist composition and library Read access
│   └── test/                           # root and specialist coverage
└── packages/docs/content/packages/filesystem/hooks.md
    # public hook behavior and configuration

Call flow

createCodelayerAgent / createCodingSubagentTool
  createAgentFilesystemHooks
    Read -> Bash -> Glob -> Grep -> List -> Web output -> file state -> caller hooks
  standard root, RLM root, and web-capable children share this one chain

Agent executes web_fetch or web_search
  serialized successful result
    -> web output hook
    -> bounded replacement enters the next model request
    -> full result remains readable at the returned temp-file path

@github-actions

Copy link
Copy Markdown

Docs Agent Review

Agent finished with reason: error


To apply these recommendations, comment: @docs-agent apply

@K-Mistele
K-Mistele merged commit 82815e9 into main Aug 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant