Tin

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.

1. The language

Values, functions, types, errors and collections. Everything you need before agents.

  1. 1Hello, TinWrite a program, run it, and read an error message.
  2. 2Values and typeslet, var, numbers, strings and how Tin infers types.
  3. 3FunctionsParameters, return types and functions that are one expression.
  4. 4Control flowif, loops and ranges. Most things are expressions.
  5. 5Structs and methodsGroup values into a type and give it methods.
  6. 6Sum types and matchA value that is one of several shapes, and a match that handles every one.
  7. 7Option, Result and ?No null and no exceptions: missing values and failures are ordinary values.
  8. 8Arrays and mapsLists of values, lookups by key, and the methods you use every day.
  9. 9Closures and pipelinesFunctions as values, and |> to chain them.
  10. 10GenericsOne function or type for many element types.
  11. 11Values, var and inoutEvery value is a copy. How you change things anyway, and why it helps.
  12. 12Durations and frequenciesUnits are types: 250ms + 3 does not compile.
  13. 13ModulesSplit a program across files with import.
  14. 14Teststest blocks next to the code, run with tin test.

2. Agents

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

  1. 15Your first agentAn agent block, called like a function.
  2. 16ToolsGive an agent functions to call. Their schemas come from your types.
  3. 17Typed repliesAsk for a struct and get a struct back, not text to parse.
  4. 18Guarded tools and approvalA person approves every call to a dangerous tool.
  5. 19CapabilitiesThe compiler proves what each agent can reach.
  6. 20Sub-agents and teamsAgents that call agents: planners, workers and critics.
  7. 21spawn, await and withinRun agents at the same time, cancel them, and give them a time budget.
  8. 22Code as actionAn agent that answers with a small, checked Tin program.
  9. 23Record and replaySave every model answer to a tape and run it again offline.
  10. 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.

  1. 25Calling JavaScriptimport js and extern fn, checked at the boundary.
  2. 26A fleet of agentsA larger program, read piece by piece.
  3. 27A command-line tooltin new, input, formatting and building a .wasm.
  4. 28Tin in the browserWhat runs in the playground and how agents work there.
  5. 29Talking agentsA voice agent holds a live conversation: speech in, speech out, tools in between.
  6. 30ServersA server where request input is untrusted like a model's reply: injection does not compile, and every agent is an endpoint.
  7. 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.

  1. 32Robotsrobot Arm = so101: joints by name, checked at compile time, angles as units.
  2. 33Policies and the control looparm.run(policy, 5s, 50Hz): holds, sequences, noise, and tapes that replay exactly.
  3. 34Safety and agentsOne gate for every write, and an agent that moves an arm only through it.