awe docs

For developers

Keeping API model requests small and cacheable

API models keep nothing between calls, so awe sends the model what it needs on every turn. Left alone, that request grows with every tool result and every message. The console does four things to keep each request small and to let the model provider reuse (cache) the part that does not change. This page explains them and their settings. It is for developers who run awe on an API model and want to understand cost and context size.

None of this applies when your model is a command-line agent such as the Claude CLI, which manages its own context.

What the console does

1. Keeps the start of the request identical

Providers bill less for the part of a prompt they have seen before, but only if it is byte-for-byte the same. On OpenAI-style providers the console can arrange each request so the front never changes:

  • The system prompt and the tool definitions come first and stay the same from turn to turn.
  • Memories recalled for the current question are placed late in the request, just before your message, instead of inside the system prompt.
  • awe’s operating manual and pinned memory are sent once per conversation, not on every turn.
  • Each request carries the conversation id as a routing hint (the user field and an x-session-affinity header), so a provider with several servers can send the conversation back to the one that has it cached.

Setting: AWE_COMPAT_STABLE_PREFIX. When the line is absent, this is on for awe’s own AI plan and off for a key you bring. 1 or 0 in .env decides it either way.

2. Marks the cacheable part for Anthropic

When you use an Anthropic API key directly, the console marks the system prompt and the last tool definition as cacheable, which is how Anthropic’s prompt caching is switched on.

Setting: AWE_SDK_CACHE_CONTROL. On unless set to 0.

3. Parks large tool results

A tool result longer than the cap is not put into the conversation whole. The model gets the beginning, plus a note with an id. The full result is saved in .awe/tool-results/ in the awe folder and deleted after about a day. Because the full text is not in the conversation, it is not sent again on every later step.

The model reads more with the built-in expand_result tool:

Argument What it does
id The id from the note
offset Where to continue reading. Each answer includes next_offset
query Return only the lines that contain this text

Setting: AWE_TOOL_RESULT_CAP, in characters. Default 16000.

4. Stops a runaway turn

A single turn can call many tools, and each round sends the conversation again. Two settings watch the total input tokens across one turn’s tool rounds on OpenAI-style providers:

  • AWE_TURN_TOKEN_WARN (default 120000): write a warning to the log. Nothing is cut.
  • AWE_TURN_TOKEN_BUDGET (default 0, off): after at least one tool round, stop calling tools once the total passes this number and answer from what has been gathered so far. The log gets a [token-budget] line saying so.

Settings

All in .env in the awe folder. Restart awe after a change.

Setting When the line is absent What it does
AWE_COMPAT_STABLE_PREFIX On for awe’s AI plan, off otherwise Keep the front of the request identical
AWE_SDK_CACHE_CONTROL On Cache marks for a direct Anthropic key
AWE_TOOL_RESULT_CAP 16000 Characters of a tool result kept in the conversation
AWE_TURN_TOKEN_WARN 120000 Log a warning past this many input tokens in one turn
AWE_TURN_TOKEN_BUDGET 0 (off) End the tool loop past this many input tokens in one turn
AWE_TOKEN_DIAG On 0 silences the [cache] and [token-budget] log lines

Check that caching works

With AWE_TOKEN_DIAG on, each streamed reply on an OpenAI-style provider writes one line to the console’s log (MCP-servers/awe-console/logs/gateway-stderr.log):

[cache] conv=<id> prompt=<tokens> cached=<tokens> (<percent>% hit) out=<tokens> model=<name>

Send three or four messages in one conversation and watch cached. The first turns of a conversation show little or no cached input, because the provider has not stored the prefix yet. If cached stays at zero on later turns, the provider is not caching, or AWE_COMPAT_STABLE_PREFIX is off.

For parked results, ask for something that returns a lot of data. The tool result in the conversation ends with a note that names expand_result and an id.

Limits

  • A provider can drop its cache at any time, so some turns will miss even when everything is set up correctly.
  • Keeping the prefix identical helps most on long conversations and turns with many tool calls. On short questions it makes little difference.
  • The token budget cuts a turn short. The answer is built from what the tools had returned up to that point.