@alexkroman1/aai-cli 16.1.0 → 17.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +2 -1
  2. package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
  3. package/dist/_build-target.d.ts +98 -19
  4. package/dist/_deno-target.d.ts +15 -14
  5. package/dist/_dev-env.d.ts +19 -13
  6. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-CLU9xjH5.mjs} +25 -17
  7. package/dist/_dev-server.d.ts +4 -3
  8. package/dist/_init.d.ts +39 -0
  9. package/dist/_modal-target.d.ts +11 -6
  10. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  11. package/dist/_preflight.d.ts +110 -5
  12. package/dist/_target-bundle.d.ts +112 -0
  13. package/dist/_target-entry.d.ts +81 -0
  14. package/dist/{_templates-CuP74F8D.mjs → _templates-IMeKMVIj.mjs} +1 -1
  15. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  16. package/dist/_vitest-runner.d.ts +35 -23
  17. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  18. package/dist/build.d.ts +34 -4
  19. package/dist/cli.mjs +20 -16
  20. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  21. package/dist/deploy.d.ts +9 -0
  22. package/dist/{dev-Du8pCWFq.mjs → dev-ChsrNHpK.mjs} +1 -1
  23. package/dist/dev.d.ts +1 -1
  24. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  25. package/dist/init-W-4k-lCF.mjs +559 -0
  26. package/dist/init.d.ts +43 -3
  27. package/dist/scaffold/CLAUDE.md +51 -64
  28. package/dist/scaffold/package.json +6 -6
  29. package/dist/scaffold/vite.config.ts +29 -1
  30. package/dist/{studio-It7SRfUN.mjs → studio-DEAJGBXa.mjs} +19 -9
  31. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  32. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  33. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  34. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  35. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  36. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  37. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  38. package/dist/templates/coding-agent/agent.test.ts +109 -0
  39. package/dist/templates/coding-agent/agent.ts +45 -0
  40. package/dist/templates/coding-agent/chat.ts +63 -0
  41. package/dist/templates/coding-agent/shared.ts +46 -0
  42. package/dist/templates/coding-agent/system-prompt.md +32 -0
  43. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  44. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  45. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  46. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  47. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  48. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  49. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  50. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  51. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  52. package/dist/templates/custom-pipeline-agent/agent.ts +1 -0
  53. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  54. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  55. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  56. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  57. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  58. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +8 -1
  59. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  60. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  61. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  62. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  63. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  64. package/dist/templates/executive-inbox-agent/meeting.ts +1 -1
  65. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  66. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  67. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  68. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  69. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  70. package/dist/templates/hotel-reception-agent/agent.test.ts +2 -1
  71. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  72. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  73. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  74. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +2 -1
  75. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  76. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  77. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  78. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  79. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  80. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  81. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  82. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  83. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  84. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  85. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  86. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  87. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  88. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  89. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  90. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  91. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  92. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  93. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  94. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  95. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  96. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  97. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  98. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  99. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  100. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  101. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  102. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  105. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  106. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  107. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  108. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  109. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  114. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  116. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  117. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  118. package/dist/templates/medication-safety-agent/agent.test.ts +54 -0
  119. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  120. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  121. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  122. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  123. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  124. package/dist/templates/quickstart-agent/agent.eval.test.ts +39 -3
  125. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  126. package/dist/templates/quickstart-agent/agent.ts +18 -2
  127. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  128. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  129. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  130. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  131. package/dist/templates/research-planner-agent/agent.ts +3 -0
  132. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  133. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  134. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  135. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  136. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +37 -5
  137. package/dist/templates/roadside-assistance-agent/agent.test.ts +38 -6
  138. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  139. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  140. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  141. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  142. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  143. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  144. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  145. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  146. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  147. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  148. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  149. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  150. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  151. package/dist/templates/technical-support-agent/agent.test.ts +3 -3
  152. package/dist/templates/technical-support-agent/agent.ts +5 -1
  153. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  154. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  155. package/dist/templates/technical-support-agent/procedure.ts +4 -3
  156. package/dist/templates/technical-support-agent/shared.ts +10 -146
  157. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  158. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  159. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  160. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  161. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  162. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  163. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  164. package/dist/templates/topic-briefing-agent/agent.test.ts +23 -11
  165. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  166. package/dist/templates/topic-briefing-agent/shared.ts +10 -10
  167. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  168. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  169. package/dist/templates/transcription-workflow/agent.ts +3 -0
  170. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  171. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  172. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  173. package/dist/templates/web-research-agent/agent.ts +30 -0
  174. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  175. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  176. package/dist/templates/word-game-agent/agent.ts +20 -0
  177. package/dist/test-CjKPQ9_B.mjs +102 -0
  178. package/dist/test.d.ts +37 -12
  179. package/package.json +5 -5
  180. package/dist/_init-Bp1CjRrU.mjs +0 -199
  181. package/dist/_preflight-CcAR577V.mjs +0 -46
  182. package/dist/init-CY4NAXAA.mjs +0 -183
  183. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -0,0 +1,154 @@
1
+ /**
2
+ * What this store's callers say that a general recognizer has no reason to
3
+ * expect — the `keyterms_prompt` this agent opens its STT stream with.
4
+ *
5
+ * A mis-heard entity is this template's worst failure and the one hardest to
6
+ * see: "wireless earbuds" heard as "wireless ear buds" resolves to nothing,
7
+ * "Bluetooth speaker" heard as "blue tooth speaker" resolves to nothing, and
8
+ * the model then tells a caller their own order does not contain an item they
9
+ * are holding. Nothing in the transcript looks wrong.
10
+ *
11
+ * ## Why the list is SHORT, and stays short
12
+ *
13
+ * AssemblyAI's guidance and Vapi's published keyword advice agree on three
14
+ * rules, and all three point the same way:
15
+ *
16
+ * - **Uncommon words and proper nouns only.** "Laptop", "notebook", "grill"
17
+ * and "return" are all in this domain and none of them is here: a general
18
+ * model already recognizes them, and boosting a common word buys false
19
+ * positives on everything that sounds like it.
20
+ * - **The exact spelling and casing you want in the transcript.** These are
21
+ * the strings the model is being asked to produce, so `"USB-C"` and
22
+ * `"usb c"` are different requests — and `resolve.ts`, which matches a
23
+ * spoken item against the account, is matching against whatever comes out.
24
+ * - **Start small.** Over-boosting makes the model hear terms nobody said,
25
+ * which is the same failure pointed the other way. The cap is 100 terms;
26
+ * this is well under it deliberately, and the way to extend it is one term
27
+ * at a time against a transcript that got that term wrong.
28
+ *
29
+ * There are no ORDER IDS here, and there cannot be: they are per account
30
+ * (`#W2378156`), they arrive one call at a time, and a hundred slots would
31
+ * cover a rounding error's worth of them. The mechanisms that carry those are
32
+ * the other two — `agent_context`, refreshed with the agent's own last reply
33
+ * so the recognizer knows an order number was just asked for, and
34
+ * `resolve.ts`'s spoken-identifier matching on the way back.
35
+ */
36
+
37
+ /**
38
+ * Multi-word product names whose halves are ordinary words.
39
+ *
40
+ * This is the shape of term keyterms are actually for: every word in
41
+ * "electric kettle" is common, and the PAIR is what the recognizer splits,
42
+ * mangles, or resolves to a near neighbour.
43
+ */
44
+ const PRODUCTS = [
45
+ "wireless earbuds",
46
+ "mechanical keyboard",
47
+ "espresso machine",
48
+ "electric kettle",
49
+ "smart thermostat",
50
+ "air purifier",
51
+ "portable charger",
52
+ "indoor security camera",
53
+ "vacuum cleaner",
54
+ "patio umbrella",
55
+ "hiking boots",
56
+ "jigsaw puzzle",
57
+ "luggage set",
58
+ "dumbbell set",
59
+ "yoga mat",
60
+ "e-reader",
61
+ "action camera",
62
+ "Bluetooth speaker",
63
+ ] as const;
64
+
65
+ /**
66
+ * The option vocabulary a caller uses to pick a VARIANT.
67
+ *
68
+ * A variant is what an exchange turns on, so mis-hearing one is a wrong
69
+ * `item_id` rather than a wrong word — the same class of failure as a mis-read
70
+ * order number, arriving through the part of the sentence nobody watches.
71
+ */
72
+ const OPTIONS = [
73
+ "stainless steel",
74
+ "matte black",
75
+ "USB-C",
76
+ "OLED",
77
+ "1080p",
78
+ "4K",
79
+ "noise cancelling",
80
+ "tactile switch",
81
+ "linear switch",
82
+ ] as const;
83
+
84
+ /**
85
+ * The words this domain's PROCEDURE is conducted in.
86
+ *
87
+ * Every one of them decides which tool the model reaches for, so a swap
88
+ * between two of them is a wrong action rather than a wrong noun: "exchange"
89
+ * heard as "change" is a different tool, and "gift card" heard as "gift
90
+ * certificate" sends a refund somewhere the account cannot receive it.
91
+ */
92
+ const PROCEDURE = [
93
+ "order number",
94
+ "item number",
95
+ "tracking number",
96
+ "payment method",
97
+ "original payment method",
98
+ "gift card",
99
+ "store credit",
100
+ "PayPal",
101
+ "exchange",
102
+ "modify",
103
+ ] as const;
104
+
105
+ /**
106
+ * The list this agent's `assemblyAIStt({ keyterms })` sends.
107
+ *
108
+ * Assembled from the three groups above rather than written flat, because the
109
+ * REASON a term is here is the only thing that makes the next edit a judgement
110
+ * instead of a guess — a term nobody can place in one of these groups probably
111
+ * should not be added.
112
+ */
113
+ export const RETAIL_KEYTERMS: readonly string[] = [...PRODUCTS, ...OPTIONS, ...PROCEDURE];
114
+
115
+ /**
116
+ * The names on this store's accounts — boosted ONLY while the call is
117
+ * identifying its caller.
118
+ *
119
+ * Per state rather than per session, and the reason is the whole point of a
120
+ * per-phase keyterm list: a personal name is the hardest thing on this call to
121
+ * recognize and the least useful thing to boost afterwards. "Aarav" competes
122
+ * with nothing once the caller is authenticated, and a permanently boosted
123
+ * name list is a permanent source of false positives on every later turn — the
124
+ * over-boosting AssemblyAI's own guidance warns about.
125
+ *
126
+ * Only the UNCOMMON ones are here. "Smith", "Brown" and "Anderson" are in this
127
+ * store's seed too and are deliberately absent: a general model already
128
+ * recognizes them, so a slot spent on one is a slot and a false positive.
129
+ *
130
+ * **A real deployment's list is longer than 100 and cannot be written here.**
131
+ * The cap is 100 terms, so an account base of any size does not fit, and the
132
+ * mechanism for it is not this one: an application that knows WHO is calling
133
+ * (a CRM lookup on the inbound number) puts that in
134
+ * `assemblyAIStt({ agentContext })`, which is free text — AssemblyAI's own
135
+ * published benchmark reports −49% entity error on NAMES for a detailed
136
+ * context, which is a vendor claim rather than anything measured here. What a
137
+ * keyterm list is for is the closed vocabulary a store has regardless of who
138
+ * calls.
139
+ */
140
+ export const IDENTIFYING_KEYTERMS: readonly string[] = [
141
+ // First names from `seed.json`, minus the ones a general model gets right.
142
+ "Aarav",
143
+ "Anya",
144
+ "Harper",
145
+ "Olivia",
146
+ // Surnames, same rule.
147
+ "Ito",
148
+ "Garcia",
149
+ "Gonzalez",
150
+ // What the caller is being ASKED for in this phase, which is as much a part
151
+ // of the phase's vocabulary as the answers are.
152
+ "zip code",
153
+ "email address",
154
+ ];
@@ -93,7 +93,22 @@ export const resolveOrder = failable((state: RetailState, spoken: string): Order
93
93
  };
94
94
  }
95
95
 
96
- // A position, then exactly-one, then an ambiguity that lists them — and never
97
- // a guess, because the consequence here is cancelling the wrong order.
98
- return resolveOne(candidates, spoken, { label: "order", describe: describeOrder });
96
+ // A code, then a position, then exactly-one, then an ambiguity that lists
97
+ // them — and never a guess, because the consequence here is cancelling the
98
+ // wrong order.
99
+ //
100
+ // `code` is the id match this module used to own outright, moved inside the
101
+ // primitive: it compares through `spokenAlphanumeric` exactly as
102
+ // `normalizeOrderId` does, so an id the caller read aloud in a shape
103
+ // `LOOKS_LIKE_ORDER_ID` does not recognise still resolves. The branch above
104
+ // stays, because what it answers is not a match at all: an id-shaped
105
+ // utterance that names no order of THEIRS is a closed question ("not on this
106
+ // account"), which needs this store's `#W` prefix rule and this customer's
107
+ // list — neither of which `resolveOne` can know, and a fall-through to "the
108
+ // only order" would be the wrong order.
109
+ return resolveOne(candidates, spoken, {
110
+ label: "order",
111
+ describe: describeOrder,
112
+ code: (order) => order.order_id,
113
+ });
99
114
  });
@@ -15,7 +15,13 @@ import agentDef from "virtual:aai/agent";
15
15
  // a script names — so a stub run proves the wiring and proves nothing about
16
16
  // what the agent chose.
17
17
  import { dialogResultSchema } from "@alexkroman1/aai/testing";
18
- import { toolNames, toolResultIn } from "@alexkroman1/aai-runtime/eval";
18
+ import {
19
+ describeToolCalls,
20
+ lastToolResultIn,
21
+ toolCallsInTurns,
22
+ toolNames,
23
+ toolResultIn,
24
+ } from "@alexkroman1/aai-runtime/eval";
19
25
  import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
20
26
  import { expect } from "vitest";
21
27
  import { z } from "zod";
@@ -115,17 +121,42 @@ describeEval(agentDef, (test) => {
115
121
  test(
116
122
  "reads the disclosure the plan it actually found priced",
117
123
  async ({ session }) => {
118
- await session.say(
124
+ // Three turns, and the third asks for the TRUCK. Two other wordings failed
125
+ // for opposite reasons: a neutral "okay, go on" was heard as the
126
+ // acknowledgement, so the desk called `acknowledge_disclosure` for a
127
+ // disclosure it had never read; and "what is the fee?" invited it to
128
+ // answer out of the figures `lookup_coverage` hands back, which is the
129
+ // summarising the brief forbids. Asking for the truck cannot be either —
130
+ // `dispatch_truck` is gated on `onCall.dispatching` and the only way there
131
+ // is through the disclosure, so the DIALOG enforces the order rather than
132
+ // this case hoping for it. The lookup moves the
133
+ // call to `onCall.disclosure` and that step's instruction rides back in
134
+ // the tool result, so the desk is holding its next move — but a live model
135
+ // usually SPEAKS after one tool rather than chaining, so demanding the
136
+ // disclosure land in the same reply as the lookup measured its verbosity.
137
+ // What this case is for is that the words are the TOOL's and priced for
138
+ // the plan the lookup actually found, which no turn boundary affects.
139
+ const turns = await session.sayAll([
119
140
  "My car won't start — route nine past Millfield, silver Corolla, I'm off the road.",
141
+ "The number on the card is R S four four one seven.",
142
+ "Alright, send the truck.",
143
+ ]);
144
+ const calls = toolCallsInTurns(turns);
145
+ // Still in order: the coverage is looked up before anything is priced.
146
+ const names = toolNames(calls);
147
+ expect(names.indexOf("lookup_coverage"), describeToolCalls(calls)).toBeLessThan(
148
+ names.indexOf("service_disclosure"),
120
149
  );
121
- const turn = await session.say("The number on the card is R S four four one seven.");
122
150
 
123
151
  // The disclosure is not a sentence the model composes: it comes back from
124
152
  // the tool, and it must be the one this plan priced. Computed here from
125
153
  // the template's own function rather than pasted, so a change to the
126
154
  // wording moves both together and a change to the PLAN does not.
127
- const handed = toolResultIn(
128
- turn.toolCalls,
155
+ // The disclosure as finally handed over: read across the turns, and the
156
+ // LAST one, because a desk that re-read it after an interruption has
157
+ // called this twice and the words the caller heard last are the words.
158
+ const handed = lastToolResultIn(
159
+ calls,
129
160
  "service_disclosure",
130
161
  dialogResultSchema(z.object({ readThisVerbatim: z.string() })),
131
162
  );
@@ -156,6 +187,7 @@ describeEval(agentDef, (test) => {
156
187
  },
157
188
  "Thanks. What's the policy number?",
158
189
  { tool: "lookup_coverage", args: { policyNumber: "RS-4417" } },
190
+ "Got it — you're on the Plus plan.",
159
191
  { tool: "service_disclosure" },
160
192
  "Before I send anyone, I have to read you this.",
161
193
  ],
@@ -148,9 +148,14 @@ async function verify(ctx: ToolContext, policyNumber?: string): Promise<void> {
148
148
  );
149
149
  }
150
150
 
151
- /** And on to `onCall.dispatching`, with the fee accepted. */
151
+ /** And on to `onCall.dispatching`, with the fee READ and then accepted. */
152
152
  async function accept(ctx: ToolContext, policyNumber?: string): Promise<void> {
153
153
  await verify(ctx, policyNumber);
154
+ // The read is not optional and this helper used to skip it, which is exactly
155
+ // the shortcut a live desk was measured taking — `acknowledge_disclosure`
156
+ // refuses without it now, so every spike through this helper goes the way a
157
+ // real call has to.
158
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
154
159
  expectDialogOk(await acknowledgeDisclosure.execute({ accepted: true }, ctx));
155
160
  }
156
161
 
@@ -266,6 +271,9 @@ describe("the roadside call", () => {
266
271
  const ctx = createToolContext();
267
272
  await verify(ctx, "RS-4417");
268
273
  expect(at(ctx).state).toBe("onCall.disclosure");
274
+ // Read it first: the answer to a disclosure nobody handed over is refused,
275
+ // which the case below this one pins on its own.
276
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
269
277
 
270
278
  // `sendFrom` returning `undefined` is "that worked and it moved nothing" —
271
279
  // not a failure, because declining a fee is not an error.
@@ -280,6 +288,28 @@ describe("the roadside call", () => {
280
288
  expect(agreed.state).toBe("onCall.dispatching");
281
289
  });
282
290
 
291
+ test("a yes to a disclosure nobody read is REFUSED, and records nothing", async () => {
292
+ // The hole this closes: "after you have read it to them in full" lived in
293
+ // `acknowledge_disclosure`'s description and in nothing else, so a desk
294
+ // could take the caller's yes and dispatch on a fee never spoken. Measured
295
+ // on a live run — `lookup_coverage`, `acknowledge_disclosure`,
296
+ // `dispatch_truck`, no `service_disclosure` anywhere.
297
+ const ctx = createToolContext();
298
+ await verify(ctx, "RS-4417");
299
+
300
+ const refused = await acknowledgeDisclosure.execute({ accepted: true }, ctx);
301
+ expect(isToolFailure(refused) && refused.error).toMatch(/service_disclosure/);
302
+ // Refused means NOTHING moved: not the acceptance, not the call's phase.
303
+ expect(roadsideSlot.get(ctx).disclosureAcceptedAt).toBeNull();
304
+ expect(at(ctx).state).toBe("onCall.disclosure");
305
+
306
+ // And it is the READ that unblocks it, not the passage of time.
307
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
308
+ expect(roadsideSlot.get(ctx).disclosureReadAt).not.toBeNull();
309
+ const agreed = expectDialogOk(await acknowledgeDisclosure.execute({ accepted: true }, ctx));
310
+ expect(agreed.state).toBe("onCall.dispatching");
311
+ });
312
+
283
313
  test("the disclosure is handed over verbatim and priced by the plan", async () => {
284
314
  const ctx = createToolContext();
285
315
  await verify(ctx, "RS-8802");
@@ -335,6 +365,7 @@ describe("the roadside call", () => {
335
365
  await reportLocation.execute({ ...A_LOCATION, safeToWait: false, situation: "battery" }, ctx),
336
366
  );
337
367
  expectDialogOk(await lookupCoverage.execute({}, ctx));
368
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
338
369
  expectDialogOk(await acknowledgeDisclosure.execute({ accepted: true }, ctx));
339
370
  const job = await sendTruck(ctx, "roadside", 0);
340
371
  expect(job.result.etaMinutes).toBe(10);
@@ -440,6 +471,11 @@ describe("the per-phase voice knobs", () => {
440
471
  await verify(ctx, "RS-4417");
441
472
  expect(bargeInAt(ctx)).toBe("off");
442
473
 
474
+ // Reading the disclosure does not move the call, so the knob is unchanged
475
+ // across it — which is the property this case is about.
476
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
477
+ expect(bargeInAt(ctx)).toBe("off");
478
+
443
479
  expectDialogOk(await acknowledgeDisclosure.execute({ accepted: true }, ctx));
444
480
  expect(bargeInAt(ctx)).toBeUndefined();
445
481
  });
@@ -467,11 +503,7 @@ describe("the per-phase voice knobs", () => {
467
503
  // the one a sixth phase would be added beside.
468
504
  const audited = eachState(CALL_SPEC.states);
469
505
  for (const [path, spec] of audited) {
470
- expect({ at: path, voice: spec.voice, keyterms: spec.keyterms }).toEqual({
471
- at: path,
472
- voice: undefined,
473
- keyterms: undefined,
474
- });
506
+ expect({ at: path, voice: spec.voice }).toEqual({ at: path, voice: undefined });
475
507
  }
476
508
 
477
509
  // Non-vacuity, and the reason the walk is structural: every state in the
@@ -40,6 +40,10 @@ const PHONE_LINE: TelephonyAccess = ["twilio", "telnyx"];
40
40
  */
41
41
  export default agent({
42
42
  name: "Roadside Assist",
43
+ // What this line does, for whoever is picking an agent out of a list. Written
44
+ // in the order the call goes in, because that order is the template — see
45
+ // `call.ts`.
46
+ description: "Verifies roadside coverage, reads the service fee and dispatches a tow truck",
43
47
 
44
48
  // No provider spread: pipeline mode is the default and every stage is filled
45
49
  // from the all-AssemblyAI pipeline at parse time.
@@ -268,6 +268,17 @@ export interface RoadsideState {
268
268
  situation: Situation | null;
269
269
  /** The plan the lookup found. `null` means unverified, which is a PRICE. */
270
270
  coverage: Coverage | null;
271
+ /**
272
+ * When `service_disclosure` HANDED the words over, epoch ms.
273
+ *
274
+ * The disclosure used to be a pure read, so nothing recorded that it had
275
+ * happened and `acknowledge_disclosure` had no way to tell a caller who had
276
+ * heard the fee from one who had not. Measured: a live desk called
277
+ * `lookup_coverage`, `acknowledge_disclosure` and `dispatch_truck` and never
278
+ * called this one at all — so the truck moved on a fee nobody read, which is
279
+ * the single thing this call exists to prevent.
280
+ */
281
+ disclosureReadAt: number | null;
271
282
  /** When the caller said they understood the disclosure, epoch ms. */
272
283
  disclosureAcceptedAt: number | null;
273
284
  /** The one truck this call ever assigns. See `dispatch_truck`. */
@@ -281,6 +292,7 @@ export function emptyRoadsideState(): RoadsideState {
281
292
  where: null,
282
293
  situation: null,
283
294
  coverage: null,
295
+ disclosureReadAt: null,
284
296
  disclosureAcceptedAt: null,
285
297
  job: null,
286
298
  log: [],
@@ -1,3 +1,4 @@
1
+ import { toolFailure } from "@alexkroman1/aai";
1
2
  import { z } from "zod";
2
3
  import { roadsideCall } from "../call.ts";
3
4
  import { roadsideSlot } from "../shared.ts";
@@ -35,6 +36,19 @@ export default roadsideCall.tool({
35
36
  }),
36
37
  execute: (args, ctx) =>
37
38
  roadsideSlot.update(ctx, (state) => {
39
+ // The disclosure has to have been HANDED OVER first, and this is the only
40
+ // thing that checks it. "after you have read it to them in full" was a
41
+ // sentence in the description above and nothing else: a live desk was
42
+ // measured calling `lookup_coverage`, this tool and `dispatch_truck`
43
+ // while never calling `service_disclosure`, so a truck went out on a fee
44
+ // the caller had never been read. A refusal rather than a silent
45
+ // recording, because a yes to something nobody said is not a yes.
46
+ if (state.disclosureReadAt === null) {
47
+ return toolFailure(
48
+ "The caller has not heard the fee disclosure yet. Call service_disclosure, read back " +
49
+ "exactly what it returns, and only then record their answer.",
50
+ );
51
+ }
38
52
  state.disclosureAcceptedAt = args.accepted ? Date.now() : null;
39
53
  state.log.push(args.accepted ? "Fee disclosure accepted" : "Fee disclosure declined");
40
54
  return {
@@ -67,6 +67,17 @@ export default roadsideCall.tool({
67
67
  freeTowMiles: rate.freeTowMiles,
68
68
  perMile: rate.perMile,
69
69
  ifNoTowNeeded: quoteFee(rate, 0).total,
70
+ // The figures above price the job; they are NOT a script. Handing the
71
+ // model every number and then telling it elsewhere not to summarise
72
+ // them is an invitation, and a live desk took it — it answered the
73
+ // policy number with a sentence about the fee and never called
74
+ // `service_disclosure`, so the caller was quoted terms nobody read them.
75
+ // The dialog's step instruction already says this; naming the next call
76
+ // in the RESULT puts it where the model is actually looking.
77
+ next:
78
+ "Call service_disclosure now, in this same turn, and read back exactly what it " +
79
+ "returns. Do not say any of these numbers in your own words — the disclosure is " +
80
+ "the only wording the caller may hear the fee in.",
70
81
  };
71
82
  }),
72
83
  });
@@ -31,15 +31,21 @@ export default roadsideCall.tool({
31
31
  "word — do not shorten it, paraphrase it, or fold it into another sentence.",
32
32
  when: "onCall.disclosure",
33
33
  inputSchema: z.object({}),
34
- execute: (_args, ctx) => {
35
- const state = roadsideSlot.get(ctx);
36
- const words = disclosureFor(state.coverage);
37
- return {
38
- readThisVerbatim: words,
39
- // The count is here so a spec can assert that what was spoken is the
40
- // whole thing rather than the first clause of it. It is the caller's only
41
- // protection against a "summary" of a disclosure.
42
- wordCount: countWords(words),
43
- };
44
- },
34
+ execute: (_args, ctx) =>
35
+ // A WRITE now, and only a timestamp: `acknowledge_disclosure` refuses
36
+ // without it, so this is what makes "read it before you take their yes" a
37
+ // mechanism rather than a sentence in a description. It still sends no
38
+ // event, so the split this module's doc argues — advancing is
39
+ // `acknowledge_disclosure`'s job, a turn later — is untouched.
40
+ roadsideSlot.update(ctx, (state) => {
41
+ const words = disclosureFor(state.coverage);
42
+ state.disclosureReadAt = Date.now();
43
+ return {
44
+ readThisVerbatim: words,
45
+ // The count is here so a spec can assert that what was spoken is the
46
+ // whole thing rather than the first clause of it. It is the caller's only
47
+ // protection against a "summary" of a disclosure.
48
+ wordCount: countWords(words),
49
+ };
50
+ }),
45
51
  });
@@ -7,6 +7,7 @@ import acknowledgeDisclosure from "./tools/acknowledge_disclosure.ts";
7
7
  import dispatchTruck from "./tools/dispatch_truck.ts";
8
8
  import lookupCoverage from "./tools/lookup_coverage.ts";
9
9
  import reportLocation from "./tools/report_location.ts";
10
+ import serviceDisclosure from "./tools/service_disclosure.ts";
10
11
  import { HOLD_MINUTES, reserveTruck, resetYard, yardLock } from "./yard.ts";
11
12
 
12
13
  /**
@@ -40,6 +41,9 @@ const A_LOCATION = {
40
41
  async function toDispatching(ctx: ToolContext): Promise<void> {
41
42
  expectDialogOk(await reportLocation.execute(A_LOCATION, ctx));
42
43
  expectDialogOk(await lookupCoverage.execute({ policyNumber: "RS-4417" }, ctx));
44
+ // The fee has to be READ before the yes counts — see the gate in
45
+ // `acknowledge_disclosure`, which refuses without it.
46
+ expectDialogOk(await serviceDisclosure.execute({}, ctx));
43
47
  expectDialogOk(await acknowledgeDisclosure.execute({ accepted: true }, ctx));
44
48
  }
45
49
 
@@ -151,6 +151,10 @@ export const spokenSummary: WorkflowDef<typeof spokenSummaryInput, SpokenSummary
151
151
 
152
152
  export default workflowApp({
153
153
  name: "Spoken Summary",
154
+ // The listing line — a registry row, the studio's picker, `aai list`; never
155
+ // the model, which a workflow app does not have. It names what comes OUT,
156
+ // which is what tells this desk apart from every other one that takes audio.
157
+ description: "Turns a recording into a written summary and an audio one you can play back",
154
158
  workflows: { spokenSummary },
155
159
  // Checked at deploy time, so a missing key is a warning naming it rather than
156
160
  // a run that fails on its second step. A workflow app declares no providers,
@@ -32,6 +32,12 @@ import agentDef from "virtual:aai/agent";
32
32
  * thing that tells a live model to set the whole game up in ONE call, and an
33
33
  * eval run against the framework default prompt would measure an agent nobody
34
34
  * deployed.
35
+ *
36
+ * It is also a RESOLVER (see `agent.ts`), so a live run is given the rules file
37
+ * plus the campaign sheet as it stands on that turn. Every `check_state` below
38
+ * is asked for by name ("Check the state…") for that reason: the tracks reach
39
+ * the narrator without one now, so a case that relied on a question forcing the
40
+ * call would be measuring the old prompt.
35
41
  */
36
42
  import type { InferToolInput } from "@alexkroman1/aai";
37
43
  import { dialogResultSchema } from "@alexkroman1/aai/testing";
@@ -1,6 +1,11 @@
1
1
  /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
2
2
  import agentDef from "virtual:aai/agent";
3
- import type { InferToolInput, RandomSource, SlotHolder } from "@alexkroman1/aai";
3
+ import type {
4
+ AgentSessionContext,
5
+ InferToolInput,
6
+ RandomSource,
7
+ SlotHolder,
8
+ } from "@alexkroman1/aai";
4
9
  import { createSeededRandom, isToolFailure } from "@alexkroman1/aai";
5
10
  import {
6
11
  createToolContext,
@@ -20,6 +25,7 @@ import {
20
25
  gameView,
21
26
  inCrisis,
22
27
  isGameOver,
28
+ liveSheet,
23
29
  MAX_LOG_ENTRIES,
24
30
  MAX_NPCS,
25
31
  MIN_MOMENTUM,
@@ -894,3 +900,121 @@ describe("the story flow", () => {
894
900
  // restored rather than recomputed) has no path left to exercise it: a session
895
901
  // is the whole life of a game now.
896
902
  });
903
+
904
+ // ── The prompt carries the sheet ─────────────────────────────────────────────
905
+ //
906
+ // `systemPrompt` is a RESOLVER here: `system-prompt.md` supplies the rules and
907
+ // `liveSheet` appends the campaign as it stands before every model request.
908
+ // What that replaced was FLOW rule 1 — "call check_state as your FIRST tool
909
+ // call every turn" — a model round trip in front of every turn of a live voice
910
+ // game, enforced by nothing.
911
+
912
+ describe("the campaign sheet the narrator is given", () => {
913
+ /** The def's resolver, which is what a request assembles the instructions from. */
914
+ const resolve = (ctx: AgentSessionContext): string => {
915
+ const prompt = agentDef.systemPrompt;
916
+ if (typeof prompt !== "function") throw new Error("systemPrompt is not a resolver");
917
+ return prompt(ctx);
918
+ };
919
+
920
+ test("it is a resolver, and the rules file survives into it", () => {
921
+ // The build discovers `system-prompt.md` and hands it to `withSystemPrompt`,
922
+ // which leaves a resolver alone — so the file reaches the model through the
923
+ // resolver's own import, and this is what proves it does.
924
+ expect(typeof agentDef.systemPrompt).toBe("function");
925
+ expect(resolve(createToolContext())).toContain("CORE MECHANIC - ACTION ROLL");
926
+ });
927
+
928
+ test("before setup it says so, rather than printing an empty sheet", () => {
929
+ const ctx = createToolContext();
930
+ const sheet = liveSheet(gameSlot.get(ctx));
931
+ expect(sheet).toContain("no character yet");
932
+ expect(sheet).toContain("setup_character");
933
+ // The tracks of a campaign that does not exist would read as a live sheet.
934
+ // (Asserted on the sheet, not the whole prompt: the rules file has its own
935
+ // MOMENTUM section and always will.)
936
+ expect(sheet).not.toContain("Momentum");
937
+ expect(resolve(ctx).endsWith(sheet)).toBe(true);
938
+ });
939
+
940
+ test("a roll's consequences are in the NEXT request's prompt, with no tool call in between", async () => {
941
+ const ctx = createToolContext();
942
+ seedPlaying(ctx);
943
+ // A MISS: the tracks and the momentum move, and the chaos factor with them.
944
+ const before = resolve(ctx);
945
+ expect(before).toContain(`Momentum ${DEFAULT_STATE.momentum}`);
946
+
947
+ expectToolOk(
948
+ await run(
949
+ "action_roll",
950
+ { move: "face_danger", stat: "iron", position: "desperate", effect: "standard" },
951
+ createToolContext({ ...ctx, random: dice(1, 1, 10, 10) }),
952
+ ),
953
+ );
954
+
955
+ const after = resolve(ctx);
956
+ const game = gameSlot.get(ctx);
957
+ expect(after).toContain(`Momentum ${game.momentum}`);
958
+ expect(after).toContain(`chaos factor ${game.chaosFactor}`);
959
+ expect(after).toContain(`Health ${game.health}/`);
960
+ // And the burn window, which is the one thing the narrator most often lost
961
+ // track of between turns.
962
+ expect(after).toContain("burn_momentum can still upgrade it");
963
+ });
964
+
965
+ test("the cast, the clocks and the act are all on it", () => {
966
+ const ctx = createToolContext();
967
+ const state = playingState();
968
+ state.playerName = "Kael";
969
+ state.currentLocation = "Ashfall Keep";
970
+ state.clocks[0]!.filled = 2;
971
+ state.storyBlueprint = {
972
+ structureType: "3act",
973
+ centralConflict: "c",
974
+ antagonistForce: "a",
975
+ thematicThread: "t",
976
+ currentAct: 2,
977
+ storyComplete: false,
978
+ acts: [
979
+ { phase: "setup", title: "One", goal: "g1", mood: "m1", transitionTrigger: "t1" },
980
+ { phase: "turn", title: "Two", goal: "g2", mood: "m2", transitionTrigger: "t2" },
981
+ ],
982
+ };
983
+ seedPlaying(ctx, state);
984
+
985
+ const sheet = resolve(ctx);
986
+ expect(sheet).toContain("Kael");
987
+ expect(sheet).toContain("Doom 2/4 (threat)");
988
+ expect(sheet).toContain("Mira (neutral, bond 0)");
989
+ expect(sheet).toContain("Act 2 of 2 (turn)");
990
+ });
991
+
992
+ test("crisis and game over are DERIVED, so an emptied track cannot read as survivable", () => {
993
+ const ctx = createToolContext();
994
+ const hurt = playingState();
995
+ hurt.spirit = 0;
996
+ seedPlaying(ctx, hurt);
997
+ expect(liveSheet(gameSlot.get(ctx))).toContain("CRISIS");
998
+ expect(inCrisis(gameSlot.get(ctx))).toBe(true);
999
+
1000
+ const dead = playingState();
1001
+ dead.health = 0;
1002
+ dead.spirit = 0;
1003
+ seedPlaying(ctx, dead);
1004
+ expect(liveSheet(gameSlot.get(ctx))).toContain("GAME OVER");
1005
+ expect(isGameOver(gameSlot.get(ctx))).toBe(true);
1006
+ });
1007
+
1008
+ test("each session is told its OWN campaign", () => {
1009
+ // The resolver reads through `ctx.slots`, so it is per session for the same
1010
+ // reason every tool is.
1011
+ const one = createToolContext();
1012
+ const two = createToolContext();
1013
+ const named = playingState();
1014
+ named.playerName = "Kael";
1015
+ seedPlaying(one, named);
1016
+
1017
+ expect(resolve(one)).toContain("Kael");
1018
+ expect(resolve(two)).toContain("no character yet");
1019
+ });
1020
+ });