---
title: "Add Caveman Middleware to your existing agent"
description: "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. TypeScrip"
canonical: https://caveman.ac/guides/agent-sdk-migration
last-updated: 2026-09-19
---

# Add Caveman Middleware to your existing agent

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](https://docs.caveman.so/docs/sdk/middleware). Check the [compatibility guide](https://docs.caveman.so/docs/sdk/middleware/compatibility) 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](https://docs.caveman.so/docs/sdk/middleware/typescript) or [Python quickstart](https://docs.caveman.so/docs/sdk/middleware/python). Installing a language package alone does not start the compression runtime.

For a TypeScript application:

```bash
npm install @caveman-ai/sdk@1.1.0 @caveman-ai/middleware@0.1.0-alpha.2
```

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

```bash
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](/guides/measure-agent-cost) 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.
