Skip to main content

Shorten long tool results

An agent sends every earlier tool result again on each step of its tool loop. A long log or test report makes each later step larger, although the agent needs only a small part of it. Proxium can shorten such a result before the call goes to the vendor.

Keep has five modes. The mode off keeps every result. The other four modes shorten the middle of a long result:

ModeWhat replaces the middle
cutNothing. Proxium keeps the head and the tail, and a one-line notice gives the number of removed characters.
extractThe lines of the middle that matter for the step, copied word for word by a small model.
summariseAt most three short sentences from a small model: the outcome, the one error or number that matters, and the next step.
factsThe facts that the next step needs, one on each line as key: value, with each value copied exactly from the middle.

The modes extract, summarise and facts call a helper model. The modes cut and off call no model.

Keep is off for every app until you set a limit or a mode.

How it works​

  1. Proxium reads the mode of the call, in the order of the next section.
  2. Proxium checks each tool result in the history of the call. A result is eligible when its tool is in the list of the rule and its text is longer than the limit.
  3. Proxium keeps the first characters and the last characters of an eligible result. It puts the replacement of the mode in the middle, between two notices.
  4. Proxium sends the shortened history to the vendor.

The cut is a fixed function of the result text. The same result gives the same shortened text on every call, so the cache of the vendor still holds the prefix. A call with nothing to cut goes to the vendor with no change.

A tool that is not in the list stays whole. The list of a new rule is bash, shell and execute. bash is the shell tool of OpenCode. Name the shell tool of your own agent in keep_tools. Keep read out of the list: an agent that edits a file needs the exact text.

Choose the mode​

Three sources can name the mode of a call. The most specific one that names a mode wins:

  1. The request header x-proxium-keep. A caller that sends it decides for its own call.
  2. The classification document. A rule action keep names the mode for the calls that the rule matches. See automatic routing.
  3. The app setting. The row of the app in axon_source_limits holds keep_mode and keep_model.

When none of them names a mode, the app inherits the mode of the project default, the row of the source *. When that row names no mode either, the mode follows the limit. An app with a limit gets cut, and an app with no limit gets off. A header or a setting value of off switches keep off for that call or that app.

The header takes the mode, and the parameter model names the helper model:

curl "$PROXIUM_URL/v1/chat/completions" \
-H "authorization: Bearer $PROXIUM_KEY" \
-H "x-proxium-source: my-agent" \
-H "x-proxium-keep: summarise; model=acme/tiny" \
-d '{"model": "chat", "messages": [{"role": "user", "content": "fix the failing test"}]}'

Proxium refuses a header that names no mode of the five, or a parameter that is not model. The call then fails with 400 invalid_keep_mode, and the message names the mode or the parameter that is not valid.

Set the limit​

Keep is off for an app until you set a limit or a mode for it. There are three ways to set it:

  1. On Overview in the console.
  2. With the MCP tool proxium_set_app_limit.
  3. With a request to the source limits of your team.

In each way, a field that you leave out keeps its stored value. A change of keep keeps the ceilings of the app.

FieldMeaningDefault
keep_modeHow the middle is shortened: off, cut, extract, summarise or facts, or inherit for the project default.inherit
keep_modelThe helper model of the modes extract, summarise and facts: a tier of the routing or a provider/model. Empty means the helper tiers of the project.empty
keep_limit_charsThe length above which a result is shortened. 0 switches the shortening off and keeps the mode.0
keep_head_charsThe characters that stay at the start.3000
keep_tail_charsThe characters that stay at the end.3000
keep_toolsThe tool names that keep applies to.bash, shell, execute

A limit of 0 with a mode of extract, summarise or facts turns the limit on at 8000. A helper mode costs a model call, so it needs a result to work on.

The limit must be larger than the head, plus the tail, plus 200 characters. Proxium refuses a rule that breaks this, because such a rule could never shorten a result.

curl -X PUT "$PROXIUM_URL/api/teams/$TEAM/source-limits" \
-H "authorization: Bearer $PROXIUM_TOKEN" \
-H "content-type: application/json" \
-d '{"source": "my-agent", "keep_limit_chars": 8000, "keep_mode": "summarise", "keep_model": "trivial"}'

To switch keep off, send "keep_mode": "off". To switch the limit off and keep the mode, send "keep_limit_chars": 0.

The row of the source * is the default of the project. It holds a mode and a helper model, and it holds no limit, because a limit names one app.

The helper model​

The modes extract, summarise and facts read the middle with a small model. The model is a decision call of the gateway, not a call of your agent.

keep_model names the model. Proxium does not ask the vendor for that name. The call goes through the routing of the project instead. An empty keep_model asks the cheapest tier of the project (trivial, then memory-extract). A tier keeps the routing of the project in charge of the vendor, its price and its failover.

The helper call goes under the source keep and the route proxium-keep:<mode>. It is a call of the project and it goes into the usage of the project. The report of keep gives its calls, its tokens and its cost.

The answer is stored per result for seven days, under the project, the mode, the model and the hash of the middle. The step of the conversation goes into the question of the one call that first reads a result. Every later call reuses the stored answer, whatever its own step. So the same history costs one small call, and every later step sends the same bytes.

An answer that holds nothing of the middle is dropped, and the result is cut with the plain note. A model that writes instead of copying therefore cannot change the text that the vendor reads.

AXON_KEEP_EXTRACT_TIMEOUT_MS (8000 by default) bounds the small call. When it fails or finds no model, the result is cut with the plain note, and the agent's call goes ahead.

Read the full result again​

The agent can read the full text of a result that Proxium shortened. This costs no new vendor call. Proxium stores the full text once for each app and each result, and the notice names the hash of the text.

The notice in a shortened result looks like this:

[proxium: read the full result with proxium_read_full_result, hash 3f...]

Pass that hash to the MCP tool proxium_read_full_result. The tool returns the full text of the result. The same hash always returns the same text, and a hash from another project returns not found. The main model of the call can always read the full result again, so a short mode never loses a fact (#513).

The route GET /api/teams/{team}/keep/results/{hash} returns the same text as JSON. It accepts a member's token or a virtual key of the project.

The gateway stores the text in the S3 body bucket. It writes no Postgres row for each call. A Redis marker stops a second store of the same result. The marker lives for 30 days; the object stays until an erasure or a lifecycle rule removes it.

An app can switch the store off with keep_full in axon_source_limits. The default is on. When the store is off, the notice names no tool.

What keep did​

The route GET /api/teams/{team}/keep/report?days=7 answers what keep did in the project. For each mode and each helper model it gives the calls and the tokens that its shortening removed. It gives the tokens of the vendor too, with the share that it read from its cache. It also gives each helper job with its calls, its cost and the same two token sums. The days are 1 to 90, and the default is 7.

The console shows the same table on Overview, under the app limits. The MCP tool proxium_read_keep_report gives it to an agent.

The report measures the question of the issue: keep must save more tokens than its helper costs. A cut always wins, because it calls no model. A helper mode wins when its saved tokens are more than the tokens of its helper calls.

What to switch on​

Start with cut for the app that sends long shell results. The cut needs no model and no configuration beyond the limit.

Switch an app to summarise or facts when its agent loses a fact in the middle of a result. Read the report after a day: the saved tokens of the mode must be more than the cost of the helper. extract keeps the exact lines, and it is the safest helper mode for a step that needs the text.

Test a new mode on your own tasks before you set it for an app that does real work.