Getting started

Quickstart

Build a governed LLM agent in a few lines. Pick a model, register tools, set the rules — the runtime enforces them on every step.

A governed agent

agent.py
import asyncio
from antraft import Antraft, ToolRegistry, tool_from_function
from antraft.models import create_model
 
def search_web(query: str) -> str:
"Search the web."
return f"results for {query}"
 
tools = ToolRegistry([tool_from_function(search_web)])
 
runtime = (
Antraft.agent(
create_model("anthropic:claude-opus-4-8"),
tools,
task="Research Antraft and summarize it.",
guardrails=True,
)
.allow(["search_web"]) # default-deny everything else
.budget(max_cost_usd=1.0) # enforce spend as policy
.build()
)
 
asyncio.run(runtime.run())
Note
The parameter schema for search_web is inferred from its type hints, so the model knows how to call it and the gateway validates the arguments before it runs.

Inspect the result

agent.py
ctx = asyncio.run(runtime.run())
 
print(runtime.agent.final_answer) # the model's answer
print(ctx.action_history) # tools that actually ran
print(ctx.tokens_used, ctx.cost_usd)
print(ctx.completed, ctx.killed)

Everything switched on

agent.py
from antraft import Antraft, SemanticMemory
 
runtime = (
Antraft.agent(
model, tools,
task="...",
guardrails=True, # injection / jailbreak / PII / secrets
memory=SemanticMemory(path="mem.jsonl"), # learns across runs
parallel_tools=True, # run independent calls concurrently
)
.budget(max_tokens=200_000, max_cost_usd=5.0)
.resilient(retries=2, timeout=30)
.checkpoint("run.ckpt") # crash-safe + resumable
.observe() # live dashboard at /observability
.build()
)

Govern an agent you already have

Antraft is framework-agnostic. Wrap any agent that proposes actions:

existing.py
await Antraft.guard(my_agent, my_tools).allow(["search"]).deny(["shell"]).run()