Agent frameworks

Add Caveman Middleware to your existing agent

Set up local tool-result compression and original recovery in a TypeScript or Python application without replacing its framework.

By CavemanReviewed 2 min readRead Markdown ↗
Where Caveman fits
  1. 01Choose an adapter
  2. 02Start the local runtime
  3. 03Attach middleware
  4. 04Check complete tasks

Caveman Middleware is the current integration for developers who want smaller tool results in an existing application. Keep your framework, provider client, tools, and original conversation. TypeScript and Python packages are available in alpha.

Choose the integration your application uses

Start with the middleware overview. Check the compatibility guide for your framework and installed version. The integration belongs at a supported tool-result boundary, before the next model call.

Start the local runtime

Follow the runtime setup in the TypeScript quickstart or Python quickstart. Installing a language package alone does not start the compression runtime.

For a TypeScript application:

terminal
npm install @caveman-ai/[email protected] @caveman-ai/[email protected]

For the Python LangChain integration, on Python 3.13 or newer:

terminal
pip install "caveman-sdk==1.1.0" "caveman-middleware[langchain]==0.1.0a1"

Preserve the original conversation

The middleware changes eligible content in an outgoing copy. Keep your application's original history. Use the documented runtime and conversation scope, and retain the adapter's recovery tools and callbacks so the agent can request omitted detail.

Measure a completed task

Save a direct baseline. Run the same task with middleware, using the same model, tools, inputs, and grader. Count recovery calls, retries, input tokens, output tokens, and time across the whole task. A smaller first request is not sufficient evidence.

Use the cost measurement guide to compare outcomes. The published 33.2% input-token result measured Claude Code with wrap plus skill; it is not a middleware benchmark.

Roll back the integration

Remove the middleware wrapper and restore the original model call. Keep any originals that active conversations still need to retrieve. Confirm that your original tool and streaming behavior still passes the saved checks.

Try it on work you know

Keep your stack. Add the adapter.

Wrap the client or framework you already call, run one agent task you can check, and compare the tokens sent.

Open the middleware docs Explore comparisons ↗