Tin

Examples · learn/29-voice · 298 of 339

session

examples/learn/29-voice/session.tintin run examples/learn/29-voice/session.tin
/// The weather in a city.
tool fn weather(city: string): string => "18C and clear in {city}"

voice agent Concierge {
  model: "mock"
  system: "You are a hotel concierge. One short sentence."
  tools: [weather]
}

fn main() {
  let s = Concierge.open()
  s.say("weather in 'Oslo'")
  var answered = false
  loop {
    match s.next() {
      CallingTool { name, input } => print("calling {name} {input}")
      ToolReturned { name, output, ok } => print("{name} gave: {output}")
      Said(text) => {
        print("said: {text}")
        answered = true
      }
      TurnDone => if answered { s.stop() }
      HungUp(reason) => {
        print("hung up: {reason}")
        break
      }
      _ => {}
    }
  }
}