Blog

# Adding AgentCompile in one line

Engineering / August 14, 2026 / Krishna Bhatnagar

Install the SDK, wrap the client your agent already uses, and give each conversation its id.

AgentCompile ships as an SDK for Python and TypeScript. It wraps the OpenAI or Anthropic client your agent already uses, and returns a client you use exactly as before.

```python
from openai import OpenAI
import agentcompile

client = agentcompile.wrap(OpenAI())  # reads AGENTCOMPILE_KEY

def handle(ticket):
    with agentcompile.conversation(ticket.id):
        return run_agent(client, ticket)  # your loop, unchanged
```

In TypeScript it is the same shape.

```ts
import OpenAI from "openai";
import { wrap, conversation } from "agentcompile";

const client = wrap(new OpenAI()); // reads AGENTCOMPILE_KEY

export async function handle(ticket: { id: string }) {
  return conversation(ticket.id, () => runAgent(client, ticket)); // your loop, unchanged
}
```

## What happens on each call

- compiled: A known job: AgentCompile answers, in your provider's own response shape. Your model isn't called.
- forwarded: Anything else: your model is called, unchanged, with your own key.
- fail-open: AgentCompile is slow, unreachable or answering nonsense: your model is called.
- shadow: With mode set to shadow: AgentCompile decides, and your model answers.
- no-conversation: No conversation id: your model is called.

## If something goes wrong

It fails open. If AgentCompile is slow, unreachable or answering nonsense, the call goes straight to your model. Your provider key never reaches AgentCompile.

## Anthropic, the same way

```python
from anthropic import Anthropic
import agentcompile

client = agentcompile.wrap(Anthropic())
```

## Start by watching

Before anything runs compiled, set mode to shadow. AgentCompile decides what it would do, your model keeps answering everything, and every call is logged on your machine.

```python
client = agentcompile.wrap(OpenAI(), mode="shadow")
```

Then read the trail.

```bash
agentcompile trail -f
```

## Checklist

1. Install the SDK: pip install agentcompile, or npm install agentcompile.
2. Wrap the client your agent already uses.
3. Give each conversation its id.
4. Start with mode set to shadow and read the trail.
5. When you've seen how each job did on your history, switch to live.

Every example, in Python and TypeScript, is in the Cookbook. [Open the Cookbook](/cookbook)
