Skip to content

Interrupts & Listeners - Human-in-the-Loop ​

examples/07-interrupts-and-listeners.halo policies |! people

Pause for human input with |! yield(...), wait with ~>

Open in the playground →

halo
// ============================================================
// STEP 7: Interrupts & Listeners - Human-in-the-Loop
// Learn: Pause for human input with `|! yield(...)`, wait with `~>`
// ============================================================

policy NoProfanity : Block(Profanity)

tool SlackApprovals : POST("hooks.slack.com/services/hello-approvals")

agent Greeter [gemini-3-1-pro, temp: 0.7]
  requires NoProfanity

pipeline ApprovedHello(name: String) -> Result:
  name
    |> Greeter.prompt("Write a warm, 1-sentence greeting for {{name}}.") as greeting
    // Interrupt: Pause for human approval
    |! yield(context.data.greeting)
    // Listen for approval response (the event is stored at context.data.reaction)
    ~> listen(SlackApprovals.Reaction) as reaction
    // Gate: Only print if approved
    |? (context.data.reaction.approved == true)
    |> System.Print()

curl -fsSL https://halolang.com/install.sh | sh