Learn Tin
From a first program to agents with tools, in short chapters. Each one has programs you can run and tasks you can check.
Read the parts in order. Every program here is a real file in examples/learn/, compiled and run when this page was
built; the output shown is what it printed. Want a quick look first? Read the 15-minute tour.
· · · kept only in this browser
1. The language
Values, functions, types, errors and collections. Everything you need before agents.
- 1Hello, TinWrite a program, run it, and read an error message.
- 2Values and types
let,var, numbers, strings and how Tin infers types. - 3FunctionsParameters, return types and functions that are one expression.
- 4Control flow
if, loops and ranges. Most things are expressions. - 5Structs and methodsGroup values into a type and give it methods.
- 6Sum types and matchA value that is one of several shapes, and a
matchthat handles every one. - 7Option, Result and ?No null and no exceptions: missing values and failures are ordinary values.
- 8Arrays and mapsLists of values, lookups by key, and the methods you use every day.
- 9Closures and pipelinesFunctions as values, and
|>to chain them. - 10GenericsOne function or type for many element types.
- 11Values, var and inoutEvery value is a copy. How you change things anyway, and why it helps.
- 12Durations and frequenciesUnits are types:
250ms + 3does not compile. - 13ModulesSplit a program across files with
import. - 14Tests
testblocks next to the code, run withtin test.
2. Agents
Agents, tools and approval as part of the language, checked by the compiler.
- 15Your first agentAn
agentblock, called like a function. - 16ToolsGive an agent functions to call. Their schemas come from your types.
- 17Typed repliesAsk for a struct and get a struct back, not text to parse.
- 18Guarded tools and approvalA person approves every call to a dangerous tool.
- 19CapabilitiesThe compiler proves what each agent can reach.
- 20Sub-agents and teamsAgents that call agents: planners, workers and critics.
- 21spawn, await and withinRun agents at the same time, cancel them, and give them a time budget.
- 22Code as actionAn agent that answers with a small, checked Tin program.
- 23Record and replaySave every model answer to a tape and run it again offline.
- 24Real modelsSwap the mock for a real model. Nothing else changes.
3. Real programs
Calling JavaScript, a fleet of agents, a command-line tool and the browser.
- 25Calling JavaScript
import jsandextern fn, checked at the boundary. - 26A fleet of agentsA larger program, read piece by piece.
- 27A command-line tool
tin new, input, formatting and building a.wasm. - 28Tin in the browserWhat runs in the playground and how agents work there.
- 29Talking agentsA
voice agentholds a live conversation: speech in, speech out, tools in between. - 30ServersA
serverwhere request input is untrusted like a model's reply: injection does not compile, and every agent is an endpoint. - 31Seeing what an agent didOpenTelemetry traces of every agent question, model call and tool call, with one environment variable.
4. Robots
Declare a robot, drive it with policies, and let an agent move it only through the safety gate.