Tin

Examples · learn/16-tools · 216 of 339

failing-tool

examples/learn/16-tools/failing-tool.tintin run examples/learn/16-tools/failing-tool.tin
/// Divide one integer by another.
tool fn divide(a: int, b: int): Result<int, string> {
  if b == 0 { return Err("cannot divide by zero") }
  Ok(a / b)
}

agent Calculator {
  model: "mock"
  tools: [divide]
  on toolResult(name, output, ok) => print("  {if ok { "ok" } else { "failed" }} {name}: {output}")
}

fn main() {
  print(Calculator("divide 10 by 2"))
  print(Calculator("divide 10 by 0"))      // an Err goes back to the model; the program keeps going
}