Tin

Examples · learn/27-cli · 289 of 339

new-project

hello: a Tin program with one agent.

examples/learn/27-cli/new-project.tintin run examples/learn/27-cli/new-project.tin
// hello: a Tin program with one agent.
//
//   tin run main.tin            run it (offline: the model is "mock")
//   tin test main.tin           run the test blocks at the bottom
//   tin tools main.tin          the JSON Schemas the model sees
//   tin caps main.tin           what the agent can reach, and what needs approval
//
// To talk to Claude, change `model: "mock"` to `model: "claude-opus-5-5"` and set
// ANTHROPIC_API_KEY.

type Mood = | Calm | Busy | Stuck

type Status = {
  /// How the project feels right now
  mood: Mood
  /// One sentence on what to do next
  next: string
}

/// List the open tasks.
tool fn tasks(): string[] => ["write the README", "add a second agent"]

/// Close a task for good. A person approves every call.
guarded tool fn close(task: string): string => "closed '{task}'"

agent Helper {
  model: "mock"
  system: "You help a developer keep track of a small project."
  tools: [tasks, close]
  on toolCall(name, input) => print("  -> {name} {input}")
}

fn main() {
  print(Helper("what is in tasks?"))

  // ask for a type and you get a real value back
  let s: Status = Helper("one line of status, please: 'start with the README'")
  print("mood: {s.mood}, next: {s.next}")

  // run with --yes to approve, or answer the prompt
  print(Helper("close 'write the README'"))
}

test "a tool fn is still a function" {
  assertEq(tasks().len, 2)
}

test "the agent uses its tools" {
  // the mock model calls the tool a prompt names, so this runs offline
  assert(Helper("what is in tasks?").contains("README"), "Helper should list the tasks")
}