Metadata-Version: 2.4
Name: litellm-paritok
Version: 0.1.0
Summary: Paritok context compression as a LiteLLM Proxy callback — tool filter + content/history compression + non-destructive recall + edit recovery, transparently on every request through LiteLLM Proxy.
Project-URL: Homepage, https://paritok.com
Project-URL: Repository, https://github.com/paritok-official/litellm-paritok
Author: Paritok Team
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: coding-agent,compression,context,litellm,paritok,proxy,token
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: litellm>=1.95
Requires-Dist: paritok>=1.3.0
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Description-Content-Type: text/markdown

# litellm-paritok

[Paritok](https://paritok.com) context compression as a **LiteLLM Proxy** callback.

Drop one line in your LiteLLM Proxy config and every request through the proxy is
compressed before it hits the upstream provider — tool-schema filtering, file/tool-output
compression, history compression, non-destructive recall (`read_original` /
`gateway_search_tools`), and Edit-recovery — with **zero changes** to your agent or app.

> **Scope:** this works under **LiteLLM Proxy**. The hooks it uses
> (`async_pre_call_hook` / `async_post_call_success_hook`) are proxy-only, so the bare
> SDK path (`import litellm; litellm.completion(...)`) is not intercepted. See *Limitations*.

## Install

```bash
pip install litellm-paritok        # pulls in `paritok`
```

You also need a Paritok 4B compression backend (either one):

```bash
ollama pull paritok/paritok-4b-v1        # local Ollama, on your own machine
# or point Paritok at a hosted GPU server via an API key
```

## Use

Add one line to your LiteLLM Proxy `config.yaml`:

```yaml
litellm_settings:
  callbacks: ["litellm_paritok.paritok_handler"]
```

Then run the proxy as usual; your app keeps pointing at LiteLLM:

```bash
litellm --config config.yaml
```

> The callback string is a **dotted path** `module.instance`, resolved by LiteLLM's
> `get_instance_fn`. Use `litellm_paritok.paritok_handler` (a ready-made instance this
> package exports) — **not** a bare `"paritok"`, which LiteLLM would try to import as a module.

## How it works

The package is a thin `CustomLogger` over the published `paritok` engine — the same
compression/recall/recovery algorithms that power the Paritok proxy, wired to LiteLLM's
hooks:

- **`async_pre_call_hook`** → `ParitokEngine.process_request(...)`: filters tool schemas,
  compresses file reads / tool outputs / old history, injects the virtual recall tools,
  and returns the modified request for the upstream call.
- **`async_post_call_success_hook`** → recall resolve-loop + Edit recovery: answers any
  `read_original` / `gateway_search_tools` calls itself (re-requesting the model via
  `litellm.acompletion` until a plain turn returns), then rewrites any `Edit` whose
  `old_string` was authored against a lossy summary so it matches the real file byte-for-byte.

## Limitations

- **Proxy-only.** The bare LiteLLM SDK path does not trigger these hooks. SDK coverage
  would need a separate wrapper / custom provider.
- Requires a Paritok 4B backend (Ollama or hosted GPU) — the prerequisite for any Paritok
  deployment, not specific to this integration.

## Development

```bash
pip install -e ".[dev]"
PYTHONPATH=. pytest tests/ -v
```

Licensed under Apache-2.0.
