From 34d347ffb9ced22f6004af320958f9d1a0ae22d2 Mon Sep 17 00:00:00 2001 From: t Date: Thu, 3 Dec 2026 18:03:21 -0700 Subject: Page oversized MCP tool results to stay under agy's cap agy truncates any MCP tool result above about 10 KB before the model sees it, and splitting the text into several blocks does not avoid the cap. Results over 10,000 bytes now go out as parts of at most 9,600 bytes; the first part carries a notice and the model fetches the rest through a relay-only result_part tool. Panto still runs the tool once. Removes BUGS.md; the evidence moves to docs/findings.md. --- catalog.lua | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'catalog.lua') diff --git a/catalog.lua b/catalog.lua index 31297d0..d4b0c80 100644 --- a/catalog.lua +++ b/catalog.lua @@ -1,5 +1,38 @@ local json = require('panto').ext.json local M = {} +-- agy 1.5.23 cuts the middle out of any MCP tool result it would store above +-- 10,240 bytes (its built-in tool-output-max-bytes flag). Content blocks are +-- joined first and its own ~80-byte timestamp header counts. The model is +-- pointed at a spill file it has no tool to read, and no block type or setting +-- avoids the cut, so the relay sends larger text in parts: the first with the +-- result, the rest on request through this relay-only tool. docs/findings.md. +M.result_bytes = 10000 +M.part_tool = {name='result_part', + description='Return one later part of a tool result that was too large for a single reply. Use it only when a result says it has more parts.', + inputSchema={type='object',properties={result={type='integer'},part={type='integer',minimum=1}},required={'result','part'}}, + _meta={['antigravity/alwaysLoad']=true}} +-- Consecutive pieces of at most result_bytes-400 bytes (room for the notice), +-- ending on a newline when the piece's second half has one and never inside a +-- UTF-8 character. table.concat(pages) == text. +function M.pages(text) + local size, out, at = M.result_bytes - 400, {}, 1 + while #text - at + 1 > size do + local stop = at + size - 1 + local nl = text:sub(at, stop):match('^.*()\n') + if nl and nl > size // 2 then stop = at + nl - 1 + else for _ = 1, 3 do if (text:byte(stop + 1) or 0) & 0xC0 ~= 0x80 then break end; stop = stop - 1 end end + out[#out + 1] = text:sub(at, stop); at = stop + 1 + end + out[#out + 1] = text:sub(at); return out +end +-- What the model receives for part i of result n. The wording was checked +-- against live Hydrogen: it fetched every remaining part in one response. +function M.part(pages, n, i) + if i > 1 then return ('[pantograph: part %d of %d of result %d]\n'):format(i, #pages, n) .. pages[i] end + local bytes = 0; for _, p in ipairs(pages) do bytes = bytes + #p end + return pages[1] .. ('\n\n[pantograph: this is part 1 of %d of result %d (%d bytes in all); the tool ran once and nothing was lost. Call result_part with result=%d and part=2%s for the rest, requesting every part you need in a single response.]') + :format(#pages, n, bytes, n, #pages > 2 and ' through ' .. #pages or '') +end function M.catalog(req, names) local all, by, list = {}, {}, json.array({}) for _,t in ipairs(req.tools) do all[t.name]=t end @@ -9,7 +42,7 @@ function M.catalog(req, names) for i,name in ipairs(names) do local t=assert(all[name], 'Tool not in active rig: '..name); local s=json.decode(t.input_schema_json) assert(s.type=='object','Expected MCP object input schema for '..name) - local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire], 'Invalid or colliding MCP tool name: '..name) + local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire] and wire~=M.part_tool.name, 'Invalid or colliding MCP tool name: '..name) by[wire]={name=name,schema=s}; list[i]={name=wire,description=t.description,inputSchema=s,_meta={['antigravity/alwaysLoad']=true}} end return by,list -- cgit v1.3