Playground
More
The real compiler, running in this tab: your code becomes WebAssembly here and nothing is sent anywhere.
Agents use model: "mock", an offline stand-in that calls the tools a prompt names, unless you add a key below.
Examples marked “recorded with Claude” or “scripted tape” replay a session from a tape while their code is unchanged.
Use a real model (off: agents use the offline mock)
Your key stays in this tab and is sent only to that provider (or the base URL you set), straight from your browser;
never in a link, a tape or this site's code. Agents with model: "mock" stay offline either way.
optional: a proxy, or your own server
replaces model: "mock" with model: "claude-opus-5-5".
Some providers refuse calls from web pages (CORS); the run then says it could not reach the API. Local servers
must allow this origin (OLLAMA_ORIGINS for Ollama). The tin CLI works when a browser can't.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
// Tools and agents are part of the language.
//
// `tool fn` is an ordinary function the compiler also describes to the model:
// its name, the `///` comments, and a JSON Schema derived from the parameter
// types. See what it generates with: tin tools examples/agents/01-tools.tin
//
// This file uses `model: "mock"`, a built-in offline stand-in that calls the
// tools a prompt names. Swap in a real model to talk to Claude:
// model: "claude-opus-5-5"
/// Add two integers.
tool fn add(
/// The first number
a: int,
/// The second number
b: int,
): int => a + b
/// Divide one integer by another.
tool fn divide(a: int, b: int): Result<int, string> {
// An Err is not a crash: it goes back to the model as a failed tool call,
// and the model gets to try something else.
if b == 0 { return Err("cannot divide by zero") }
Ok(a / b)
}
agent Calculator {
model: "mock"
system: "You are a calculator. Use the tools for every calculation."
tools: [add, divide]
// the agent loop is observable: handlers run as it goes
on toolCall(name, input) => print(" call {name} {input}")
on toolResult(name, output, ok) => print(" {if ok { "result" } else { "failed" }} {name}: {output}")
}
fn main() {
// An agent is called like a function. The loop runs until the model answers:
// model -> tools -> model -> ... -> text
print(Calculator("please add 19 and 23"))
print(Calculator("now divide 10 by 0"))
// agents remember the conversation; reset() starts a new one (turns() counts every model call the agent has made)
print("turns so far: {Calculator.turns()}")
Calculator.reset()
}
Tab indents · Esc then Tab leaves the editor · ⌘/Ctrl+Enter runs
Press Run. Run a program with a tool fn to see the JSON Schema the compiler generates for the model. Run a program with agents to see what each one can reach. Each step of the agent loop appears here.