<!-- Learn Tin · Tin · https://tin.ad/docs/learn/ · generated from the built page -->

# 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](https://tin.ad/docs/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.](https://tin.ad/docs/learn/hello/)
-  [2Values and types`let`, `var`, numbers, strings and how Tin infers types.](https://tin.ad/docs/learn/values/)
-  [3FunctionsParameters, return types and functions that are one expression.](https://tin.ad/docs/learn/functions/)
-  [4Control flow`if`, loops and ranges. Most things are expressions.](https://tin.ad/docs/learn/control/)
-  [5Structs and methodsGroup values into a type and give it methods.](https://tin.ad/docs/learn/structs/)
-  [6Sum types and matchA value that is one of several shapes, and a `match` that handles every one.](https://tin.ad/docs/learn/enums/)
-  [7Option, Result and ?No null and no exceptions: missing values and failures are ordinary values.](https://tin.ad/docs/learn/errors/)
-  [8Arrays and mapsLists of values, lookups by key, and the methods you use every day.](https://tin.ad/docs/learn/collections/)
-  [9Closures and pipelinesFunctions as values, and `|>` to chain them.](https://tin.ad/docs/learn/closures/)
-  [10GenericsOne function or type for many element types.](https://tin.ad/docs/learn/generics/)
-  [11Values, var and inoutEvery value is a copy. How you change things anyway, and why it helps.](https://tin.ad/docs/learn/values-not-references/)
-  [12Durations and frequenciesUnits are types: `250ms + 3` does not compile.](https://tin.ad/docs/learn/units/)
-  [13ModulesSplit a program across files with `import`.](https://tin.ad/docs/learn/modules/)
-  [14Tests`test` blocks next to the code, run with `tin test`.](https://tin.ad/docs/learn/tests/)

## 2. Agents

Agents, tools and approval as part of the language, checked by the compiler.

-  [15Your first agentAn `agent` block, called like a function.](https://tin.ad/docs/learn/first-agent/)
-  [16ToolsGive an agent functions to call. Their schemas come from your types.](https://tin.ad/docs/learn/tools/)
-  [17Typed repliesAsk for a struct and get a struct back, not text to parse.](https://tin.ad/docs/learn/typed-replies/)
-  [18Guarded tools and approvalA person approves every call to a dangerous tool.](https://tin.ad/docs/learn/approval/)
-  [19CapabilitiesThe compiler proves what each agent can reach.](https://tin.ad/docs/learn/capabilities/)
-  [20Sub-agents and teamsAgents that call agents: planners, workers and critics.](https://tin.ad/docs/learn/teams/)
-  [21spawn, await and withinRun agents at the same time, cancel them, and give them a time budget.](https://tin.ad/docs/learn/concurrency/)
-  [22Code as actionAn agent that answers with a small, checked Tin program.](https://tin.ad/docs/learn/code-as-action/)
-  [23Record and replaySave every model answer to a tape and run it again offline.](https://tin.ad/docs/learn/replay/)
-  [24Real modelsSwap the mock for a real model. Nothing else changes.](https://tin.ad/docs/learn/real-models/)

## 3. Real programs

Calling JavaScript, a fleet of agents, a command-line tool and the browser.

-  [25Calling JavaScript`import js` and `extern fn`, checked at the boundary.](https://tin.ad/docs/learn/js-interop/)
-  [26A fleet of agentsA larger program, read piece by piece.](https://tin.ad/docs/learn/fleet/)
-  [27A command-line tool`tin new`, input, formatting and building a `.wasm`.](https://tin.ad/docs/learn/cli/)
-  [28Tin in the browserWhat runs in the playground and how agents work there.](https://tin.ad/docs/learn/browser/)
-  [29Talking agentsA `voice agent` holds a live conversation: speech in, speech out, tools in between.](https://tin.ad/docs/learn/voice/)
-  [30ServersA `server` where request input is untrusted like a model's reply: injection does not compile, and every agent is an endpoint.](https://tin.ad/docs/learn/server/)
-  [31Seeing what an agent didOpenTelemetry traces of every agent question, model call and tool call, with one environment variable.](https://tin.ad/docs/learn/telemetry/)

## 4. Robots

Declare a robot, drive it with policies, and let an agent move it only through the safety gate.

-  [32Robots`robot Arm = so101`: joints by name, checked at compile time, angles as units.](https://tin.ad/docs/learn/robots/)
-  [33Policies and the control loop`arm.run(policy, 5s, 50Hz)`: holds, sequences, noise, and tapes that replay exactly.](https://tin.ad/docs/learn/policies/)
-  [34Safety and agentsOne gate for every write, and an agent that moves an arm only through it.](https://tin.ad/docs/learn/robot-safety/)
