Command Palette

Search for a command to run...

Hectal
Phase 8: Tools and Human Approval
AI Frontend · Exercise 5 of 5 Previous
Advanced

A Tool That Runs in the Browser

The route declares showOrder with no execute, so the call comes to the browser. When it arrives, put the order id in #panel as Orders panel: ORD-1042, give the model the result, and make the chat continue.

Use onToolCall and addToolOutput (do not await it there), and sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls. If the id does not look like ORD- and four digits, answer with an output-error and the text Not a valid order id. instead. The model's final sentence appears in #answer.

What Check tests

  1. Before anything, #panel says Orders panel: nothing
  2. After #good, the panel shows the order and the model answers
  3. After #bad, the panel does not change and the model says the id was not valid
  4. The code does not await addToolOutput

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.