Tin

Examples · learn/29-voice · 300 of 339

task-1.solution

examples/learn/29-voice/task-1.solution.tintin run examples/learn/29-voice/task-1.solution.tin
/// Book a table for a number of people.
guarded tool fn book(people: int): string => "booked for {people}"

voice agent Host {
  model: "mock"
  tools: [book]
}

fn main() {
  let s = Host.open()
  s.say("book a table for 4")
  var answered = false
  loop {
    match s.next() {
      ToolReturned { name, output, ok } => print("{name} ok={ok}: {output}")
      Said(text) => {
        answered = true
      }
      TurnDone => if answered { s.stop() }
      HungUp(reason) => break
      _ => {}
    }
  }
}