All posts

Engineering1 min read

Adding AgentCompile in one line

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.

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.

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

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.

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

Then read the trail.

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

Join the beta. 10 spots.

If your company runs an AI agent in production, we'd like to compile its most repeated jobs with you.

Book a call

cal.com/agent-compile/beta

To start, we'll ask to see your agent's logs.