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
- Install the SDK: pip install agentcompile, or npm install agentcompile.
- Wrap the client your agent already uses.
- Give each conversation its id.
- Start with mode set to shadow and read the trail.
- 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