Repository navigation
Releases
v0.2.4
Pagination fields now survive reduction (#9, reported in the feedback thread).
- When a result is over budget, the reducer rebuilds it and used to keep only the source's total. Cursors and next-page links were lost, so the model could not ask for more.
- The source's pagination fields are now found by name anywhere in the response around the items:
next_cursor,response_metadata.next_cursor,paging.next.after,pageInfo.endCursor,nextRecordsUrl,has_more,links.nextand similar. - Your code always gets them on
ReducedResult.paging. - The model gets them in
_meta.source_pagingonly when every item of the page is included. A cursor jumps past the whole page, so following it from a partial page would skip the items left out; in that case the existing warning asks for a narrower call instead. - New
Messages.pagingtext, configurable like the others.
Tested with Claude Opus 5.5 on a three-page source: it followed the cursor through every page and listed all 30 items, including when the first page arrived partial and it had to narrow the call first. Without source_paging it stopped at 10.
v0.2.3
Documentation only; no code change.
- The README's links to the examples now work on PyPI. They were relative paths, which PyPI resolved to its own site, giving a "not found" page.
- The README links the feedback thread for design questions.
v0.2.2
Added
-
Examples for real agent loops, each a one-line change where the tool result enters the conversation:
openai_tool_loop.py: OpenAI Responses APIanthropic_tool_loop.py: Anthropic Messages APIlangchain_tool.py: inside a LangChain@tool
All three were run against live models (gpt-6-luna and claude-opus-5-5). In each, the model received all 30 of 30 items and listed every one correctly.
-
_meta.total_note: when the source reports more items than the response holds (a page of 30 out of 412), the model is told thatcompletecovers this response only and that it should not present the items as the full set. Its wording is the newMessages.more_at_sourcetemplate.
Changed
summary()now gives item counts and the selected fields when aselectfits, instead of only the character count.
Upgrade note
Results from paginated sources carry the extra note, about 230 characters, within the same budget.
pip install -U agent-tool-result-reducer
v0.2.1
v0.2.0
New: max_overshoot
The budget is strict by default: when a result lands over it, a whole item is dropped to bring it back. The overrun is usually a few dozen characters, because the size of the _meta block is estimated while filling, so that can cost a large item for the sake of a few characters.
max_overshoot=200 accepts a result up to 200 characters over the budget and keeps the item. Use it when the budget is a cost target; keep the default, 0, when it is a hard limit.
reduce_tool_result(payload, "crm.search", budget=12_000, max_overshoot=200)Fixed: items dropped for nothing
If the first item plus the _meta block is already over the budget, dropping the other items cannot bring the result under it. v0.1.0 dropped them anyway; they are now kept.
Behaviour with default arguments is otherwise unchanged.
pip install git+https://github.com/AryabhattaLabs/agent-tool-result-reducer@v0.2.0v0.1.0
First public release.
agent-tool-result-reducer fits a large JSON tool result into a size budget before it goes into an LLM agent's context, without silently losing data.
- Whole items, valid JSON. It never cuts a record in half.
- Fields before items. When a result is too large, it drops the widest fields first so every item survives.
- The model is told. A
_metablock states how many items were included, how many exist, and which fields were dropped. select. Keep only the fields the task needs, as dot-paths (id,summary.name).- No dependencies. Python 3.10 to 3.15.
It was extracted from a production agent runtime, where it handles every tool result.
pip install git+https://github.com/AryabhattaLabs/agent-tool-result-reducer@v0.1.0Not yet on PyPI. See the README for a quick start.