Tin

Examples · learn/24-models · 269 of 339

claude

run: --replay tests/tapes/agents-05-claude.json

examples/learn/24-models/claude.tintin run examples/learn/24-models/claude.tin
// run: --replay tests/tapes/agents-05-claude.json
/// Add two integers and return the sum.
tool fn add(a: int, b: int): int => a + b

/// Multiply two integers and return the product.
tool fn multiply(a: int, b: int): int => a * b

agent Calculator {
  system: "You are a calculator. Use the tools for all arithmetic. Reply with just the number."
  tools: [add, multiply]
  on toolCall(name, input) => print("  call {name} {input}")
}

type Language = {
  name: string
  /// The year it first appeared
  year: int
  paradigm: Paradigm
  /// One sentence on what it is known for
  knownFor: string
}

type Paradigm = | Functional | ObjectOriented | Procedural | Logic | Multi

agent Historian {
  system: "You are a historian of programming languages. Be accurate and brief."
}

fn main() {
  // tools: the model decides which to call, the loop runs them
  let answer: int = Calculator("What is (17 + 25) * 3?")
  print("(17 + 25) * 3 = {answer}")

  // typed replies: ask for a list of structs, get a list of structs
  let languages: Language[] = Historian("Name three influential programming languages from before 1975.")
  for l in languages.sortBy((a, b) => a.year < b.year) {
    print("{l.year}  {l.name.padRight(8, " ")} {l.paradigm}  — {l.knownFor}")
  }

  // streaming: text handlers fire as the reply arrives
  let poet = agent {
    system: "You write very short poems."
    on text(chunk) => write(chunk)
  }
  poet("Two lines about the metal tin.")
  print()
  print("tokens used: {Calculator.tokens() + Historian.tokens() + poet.tokens()}")
}