@alexkroman1/aai-cli 16.1.0 → 18.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 (220) 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/_console-audio.d.ts +17 -0
  5. package/dist/_console-session.d.ts +70 -0
  6. package/dist/_deno-target.d.ts +15 -14
  7. package/dist/_dev-env.d.ts +19 -13
  8. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-Dtp4aAlo.mjs} +26 -18
  9. package/dist/_dev-server.d.ts +5 -3
  10. package/dist/_init.d.ts +39 -0
  11. package/dist/_modal-target.d.ts +11 -6
  12. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  13. package/dist/_preflight.d.ts +110 -5
  14. package/dist/_target-bundle.d.ts +112 -0
  15. package/dist/_target-entry.d.ts +81 -0
  16. package/dist/_templates-DXadVNsL.mjs +135 -0
  17. package/dist/_templates.d.ts +11 -34
  18. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  19. package/dist/_vitest-runner.d.ts +35 -23
  20. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  21. package/dist/build.d.ts +34 -4
  22. package/dist/cli.mjs +40 -16
  23. package/dist/console-BsyE3DyB.mjs +422 -0
  24. package/dist/console.d.ts +37 -0
  25. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  26. package/dist/deploy.d.ts +9 -0
  27. package/dist/{dev-Du8pCWFq.mjs → dev-BGWU2zPP.mjs} +1 -1
  28. package/dist/dev.d.ts +1 -1
  29. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  30. package/dist/init-CbOhyNYe.mjs +559 -0
  31. package/dist/init.d.ts +43 -3
  32. package/dist/scaffold/CLAUDE.md +161 -166
  33. package/dist/scaffold/package.json +6 -6
  34. package/dist/scaffold/vite.config.ts +29 -1
  35. package/dist/start.d.ts +3 -3
  36. package/dist/{studio-It7SRfUN.mjs → studio-BRJsw7lr.mjs} +19 -9
  37. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  38. package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
  39. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  40. package/dist/templates/applicant-screening-agent/crews.ts +4 -4
  41. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  42. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  43. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  44. package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
  45. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  46. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  47. package/dist/templates/coding-agent/agent.test.ts +109 -0
  48. package/dist/templates/coding-agent/agent.ts +45 -0
  49. package/dist/templates/coding-agent/chat.ts +63 -0
  50. package/dist/templates/coding-agent/shared.ts +46 -0
  51. package/dist/templates/coding-agent/system-prompt.md +32 -0
  52. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  53. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  54. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  55. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  56. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  57. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  58. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  59. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  60. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  61. package/dist/templates/custom-pipeline-agent/agent.ts +3 -2
  62. package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
  63. package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
  64. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  65. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
  66. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  67. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  68. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  69. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  70. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +9 -2
  71. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  72. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  73. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  74. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  75. package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
  76. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  77. package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
  78. package/dist/templates/executive-inbox-agent/meeting.ts +3 -3
  79. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  80. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  81. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  82. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  83. package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
  84. package/dist/templates/front-desk-agent/agent.test.ts +150 -0
  85. package/dist/templates/front-desk-agent/agent.ts +22 -0
  86. package/dist/templates/front-desk-agent/shared.ts +234 -0
  87. package/dist/templates/front-desk-agent/system-prompt.md +13 -0
  88. package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
  89. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  90. package/dist/templates/hotel-reception-agent/agent.test.ts +3 -3
  91. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  92. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  93. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  94. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +3 -3
  95. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  96. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  97. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  98. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  99. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  100. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  101. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  102. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  105. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  106. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  107. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  108. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  109. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  114. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  116. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  117. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  118. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  119. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  120. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  121. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  122. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  123. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  124. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  125. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  126. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  127. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  128. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  129. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  130. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  131. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  132. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  133. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  134. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  135. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  136. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  137. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  138. package/dist/templates/medication-safety-agent/agent.test.ts +57 -4
  139. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  140. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  141. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  142. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
  143. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  144. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  145. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
  146. package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
  147. package/dist/templates/push-to-talk-agent/agent.ts +22 -0
  148. package/dist/templates/push-to-talk-agent/client.tsx +124 -0
  149. package/dist/templates/push-to-talk-agent/shared.ts +34 -0
  150. package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
  151. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
  152. package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
  153. package/dist/templates/quickstart-agent/agent.eval.test.ts +91 -3
  154. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  155. package/dist/templates/quickstart-agent/agent.ts +18 -2
  156. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  157. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  158. package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
  159. package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
  160. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  161. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  162. package/dist/templates/research-planner-agent/agent.test.ts +26 -16
  163. package/dist/templates/research-planner-agent/agent.ts +3 -0
  164. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  165. package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
  166. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  167. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  168. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  169. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +124 -5
  170. package/dist/templates/roadside-assistance-agent/agent.test.ts +39 -7
  171. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  172. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  173. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  174. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  175. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  176. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  177. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  178. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  179. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  180. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  181. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  182. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  183. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  184. package/dist/templates/technical-support-agent/agent.test.ts +29 -23
  185. package/dist/templates/technical-support-agent/agent.ts +5 -1
  186. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  187. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  188. package/dist/templates/technical-support-agent/procedure.ts +7 -6
  189. package/dist/templates/technical-support-agent/shared.ts +10 -146
  190. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  191. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  192. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  193. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  194. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  195. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  196. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  197. package/dist/templates/topic-briefing-agent/agent.test.ts +61 -36
  198. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  199. package/dist/templates/topic-briefing-agent/shared.ts +19 -18
  200. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  201. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  202. package/dist/templates/transcription-workflow/agent.ts +3 -0
  203. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
  204. package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
  205. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  206. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  207. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  208. package/dist/templates/web-research-agent/agent.ts +30 -0
  209. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  210. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  211. package/dist/templates/word-game-agent/agent.test.ts +3 -1
  212. package/dist/templates/word-game-agent/agent.ts +20 -0
  213. package/dist/test-CjKPQ9_B.mjs +102 -0
  214. package/dist/test.d.ts +37 -12
  215. package/package.json +5 -5
  216. package/dist/_init-Bp1CjRrU.mjs +0 -199
  217. package/dist/_preflight-CcAR577V.mjs +0 -46
  218. package/dist/_templates-CuP74F8D.mjs +0 -291
  219. package/dist/init-CY4NAXAA.mjs +0 -183
  220. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -21,6 +21,7 @@ import {
21
21
  } from "@alexkroman1/aai/testing";
22
22
  import { describe, expect, test, vi } from "vitest";
23
23
  import { DISPATCH_EVENTS } from "./events.ts";
24
+ import { claimsUnitsMoving } from "./guardrails.ts";
24
25
  import { callFlow, callSpec, dispatchSlot } from "./shared.ts";
25
26
  import incidentAddNote from "./tools/incident_add_note.ts";
26
27
  import incidentCreate from "./tools/incident_create.ts";
@@ -471,3 +472,105 @@ describe("a dropped 911 call", () => {
471
472
  expect(Object.keys(dispatchSlot.get(ctx).incidents)).toEqual([]);
472
473
  });
473
474
  });
475
+
476
+ describe("the desk's own output guardrail", () => {
477
+ /**
478
+ * The guardrail as the runtime runs it: the list off the DEF, not off the
479
+ * resolved config.
480
+ *
481
+ * `outputGuardrails` is host-only — `toAgentConfig` strips it with `tools`,
482
+ * `events` and `dialogs`, because a function cannot cross the wire — so
483
+ * `expectDeployable` has nothing to say about it and the check that it is
484
+ * wired at all has to be this one. Looked up and CHECKED rather than reached
485
+ * through `?.[0]`, for the reason `hangUpOn` is: a def that lost the field
486
+ * would leave every assertion below passing against nothing.
487
+ */
488
+ function say(ctx: ToolContext, text: string): true | string {
489
+ const [guardrail, ...rest] = dispatchAgent.outputGuardrails ?? [];
490
+ if (guardrail === undefined) throw new Error("the def declares no outputGuardrails");
491
+ // One rule, deliberately: a second one would be judged here and asserted
492
+ // nowhere. Adding one is a real edit and should say so by failing.
493
+ if (rest.length > 0) throw new Error(`the def declares ${rest.length + 1} outputGuardrails`);
494
+ const verdict = guardrail(text, ctx);
495
+ // Synchronous by construction here — it reads the board and a regex. An
496
+ // awaited promise would make the assertions below pass on `{}`.
497
+ if (typeof verdict === "object") throw new Error("this guardrail must not be async");
498
+ return verdict;
499
+ }
500
+
501
+ test("blocks 'units are on the way' while nothing is assigned, naming the tool", async () => {
502
+ const ctx = createToolContext();
503
+ await createIncidentFor(ctx);
504
+
505
+ const verdict = say(ctx, "Copy that. Medic-1 is en route, ETA four minutes.");
506
+
507
+ expect(verdict).not.toBe(true);
508
+ // The verdict is SPOKEN in place of the reply, so it has to be usable to
509
+ // the dispatcher hearing it — which means naming what to do, not what went
510
+ // wrong.
511
+ expect(verdict).toMatch(/resources_dispatch/);
512
+ });
513
+
514
+ test("passes the same sentence once a unit really is assigned", async () => {
515
+ const ctx = createToolContext();
516
+ const incidentId = await createIncidentFor(ctx);
517
+ expectToolOk(await resourcesDispatch.execute({ incidentId, callsigns: ["Medic-1"] }, ctx));
518
+
519
+ // The STATE half is the whole point: the same words are a lie on one board
520
+ // and a report on the other, and only the board can tell them apart.
521
+ expect(say(ctx, "Copy that. Medic-1 is en route, ETA four minutes.")).toBe(true);
522
+ });
523
+
524
+ test("lets the desk SAY that nothing is rolling", async () => {
525
+ const ctx = createToolContext();
526
+ await createIncidentFor(ctx);
527
+
528
+ // The false positive that would matter most: on a shift with nothing
529
+ // assigned, "no units are en route yet" is the truthful sentence and is
530
+ // exactly the one a keyword filter blocks.
531
+ expect(say(ctx, "Negative — no units are en route yet.")).toBe(true);
532
+ expect(say(ctx, "I'll get Engine-7 rolling once you confirm the address.")).toBe(true);
533
+ });
534
+
535
+ test("claimsUnitsMoving is biased toward missing a claim, never toward a false block", () => {
536
+ // The detector alone, away from the board — the half worth pinning, since
537
+ // the guardrail around it is two branches.
538
+ expect(claimsUnitsMoving("Engine-7 is on the way.")).toBe(true);
539
+ expect(claimsUnitsMoving("Units are responding now.")).toBe(true);
540
+
541
+ expect(claimsUnitsMoving("Nothing is rolling yet.")).toBe(false);
542
+ expect(claimsUnitsMoving("Once Medic-2 is en route I'll update you.")).toBe(false);
543
+ expect(
544
+ claimsUnitsMoving("Confirmed, 400 Oak Street. What's the nature of the emergency?"),
545
+ ).toBe(false);
546
+
547
+ // Per SENTENCE, so a hedge in one clause does not excuse the next.
548
+ expect(claimsUnitsMoving("No one is assigned yet. Ladder-2 is inbound.")).toBe(true);
549
+ });
550
+
551
+ test("a NEGATED claim is not a claim — the contraction is the whole hedge", () => {
552
+ // `\bn't\b` cannot match: there is no word boundary between the `n` and the
553
+ // `'` of "isn't", so that alternative was dead and every one of these read
554
+ // as a claim — the guardrail speaking a correction over a dispatcher who
555
+ // said the true thing, which inverts this file's stated bias. Each sentence
556
+ // here carries the contraction and NO other hedge, so a `NOT_A_CLAIM` that
557
+ // cannot see one fails on it.
558
+ expect(claimsUnitsMoving("Medic-1 isn't en route.")).toBe(false);
559
+ expect(claimsUnitsMoving("Engine-7 wasn't rolling.")).toBe(false);
560
+ expect(claimsUnitsMoving("I can't confirm anyone is responding.")).toBe(false);
561
+ expect(claimsUnitsMoving("We don't have anyone inbound.")).toBe(false);
562
+ // The typographic apostrophe a model writes as readily as the straight one.
563
+ expect(claimsUnitsMoving("Medic-1 isn\u2019t en route.")).toBe(false);
564
+ });
565
+
566
+ test("the desk can say a negated one out loud, on a board with nothing assigned", async () => {
567
+ const ctx = createToolContext();
568
+ await createIncidentFor(ctx);
569
+
570
+ // The end-to-end shape of the same bug: a true sentence, spoken over. No
571
+ // other hedge in either — take the contraction out and the desk is
572
+ // corrected for reporting the board accurately.
573
+ expect(say(ctx, "Negative — Medic-1 isn't en route.")).toBe(true);
574
+ expect(say(ctx, "We don't have anyone inbound.")).toBe(true);
575
+ });
576
+ });
@@ -1,9 +1,11 @@
1
1
  import { agent } from "@alexkroman1/aai";
2
2
  import { DISPATCH_EVENTS } from "./events.ts";
3
+ import { DISPATCH_GUARDRAILS } from "./guardrails.ts";
3
4
  import { callFlow, dashboardProjection } from "./shared.ts";
4
5
 
5
6
  export default agent({
6
7
  name: "Dispatch Command Center",
8
+ description: "Runs a 911 dispatch shift: logs incidents, triages them, and assigns units",
7
9
 
8
10
  /**
9
11
  * Declaring the flow is what makes its instructions reach a turn that calls
@@ -42,6 +44,19 @@ export default agent({
42
44
  */
43
45
  events: DISPATCH_EVENTS,
44
46
 
47
+ /**
48
+ * The desk's own last check on itself, and the third of the three things
49
+ * `agent()` can declare about a turn — the gates decide which tools are
50
+ * LEGAL, `events` OBSERVES what happens, and this is the only one that can
51
+ * stop the desk speaking.
52
+ *
53
+ * One rule, and it is the one the tool gates structurally cannot hold: never
54
+ * say help is coming before a unit has been assigned. See `guardrails.ts`,
55
+ * which also carries what the hold costs and why a desk that talks in radio
56
+ * traffic can afford it.
57
+ */
58
+ outputGuardrails: DISPATCH_GUARDRAILS,
59
+
45
60
  // The system prompt instructs the model to use web_search and run_code, so
46
61
  // they must be enabled here — the default builtin set does not include them.
47
62
  builtinTools: ["think", "remember", "recall", "calculate", "web_search", "run_code"],
@@ -0,0 +1,105 @@
1
+ import type { AgentGuardrail } from "@alexkroman1/aai";
2
+ import { callInHand, dispatchSlot } from "./shared.ts";
3
+
4
+ /**
5
+ * The one rule on this desk that the tool gates cannot hold: **never say help
6
+ * is coming before a unit has been assigned.**
7
+ *
8
+ * Everything else here is enforced structurally. Six mutating tools refuse
9
+ * until something has been logged, every one of them is addressed by incident
10
+ * id, and `callFlow`'s `dispatching` state says "never leave a critical
11
+ * incident without at least one" on every turn. None of that reaches the
12
+ * SPEECH: a model that has been told to dispatch and has not can still tell the
13
+ * room that Medic-1 is rolling, and the gates have nothing to say about it,
14
+ * because no tool ran. That is the hole `outputGuardrails` closes — it is the
15
+ * only declaration on an agent that can stop a turn, and `agent({ events })`
16
+ * deliberately cannot (a handler's return value is ignored).
17
+ *
18
+ * **It is pipeline-mode only, and refused at config time in the other two.**
19
+ * S2S synthesizes provider-side, so the words reach this runtime after the
20
+ * caller has heard them; text mode hands its caller the model stream directly
21
+ * and owns no point at which to hold a reply. `agent-guardrails.ts` argues
22
+ * both.
23
+ *
24
+ * ## What it costs, and why this desk can pay it
25
+ *
26
+ * A reply that has to be judged whole cannot be spoken as it arrives, so
27
+ * declaring one trades time-to-first-word for the check — the whole reply is
28
+ * held until the model finishes. That is a real regression on a live call and
29
+ * it is not free here either. What makes it bearable is the shape of this
30
+ * agent's speech: `system-prompt.md` asks for radio traffic ("Medic-1, respond
31
+ * priority one to 400 Oak Street"), so a reply is one or two short lines rather
32
+ * than a paragraph, and the dead-air cover is exempt from the hold and fills
33
+ * the gap exactly as it does during a tool chain.
34
+ *
35
+ * A desk that spoke at length would be the wrong place for this. The test is
36
+ * whether the sentence being checked is worth waiting for the whole of, and on
37
+ * a dispatch floor it is.
38
+ */
39
+ export const DISPATCH_GUARDRAILS: readonly AgentGuardrail[] = [
40
+ (text, ctx) => {
41
+ // The STATE half, and it is what keeps this from being a keyword filter: an
42
+ // `AgentSessionContext` carries `slots`, so the check can ask the board
43
+ // whether the claim is true rather than whether the sentence looks bad.
44
+ // `callInHand` is the same reading of "which incident" that `events.ts`
45
+ // uses for a dropped call — the most recently touched open one.
46
+ const incident = callInHand(dispatchSlot.get(ctx));
47
+ if (incident !== undefined && incident.assignedResources.length > 0) return true;
48
+ if (!claimsUnitsMoving(text)) return true;
49
+ return (
50
+ "Correction — nothing is rolling on that call yet. Assign a unit with " +
51
+ "resources_dispatch, then say so."
52
+ );
53
+ },
54
+ ];
55
+
56
+ /** One sentence at a time, so a hedge in one clause does not excuse the next. */
57
+ const SENTENCES = /[^.!?]+[.!?]?/g;
58
+
59
+ /** The desk asserting that something is already moving. */
60
+ const MOVING = /\b(?:on (?:the|their) way|en ?route|rolling|responding|inbound|underway)\b/i;
61
+
62
+ /**
63
+ * Words that make the same sentence a denial, a condition or a plan rather than
64
+ * a claim — "no units are en route yet", "once Medic-1 is rolling", "I'll get
65
+ * someone responding".
66
+ *
67
+ * **The contractions sit OUTSIDE the leading `\b`, and that is not a style
68
+ * choice.** `\bn't\b` can never match: `\b` is a boundary between a word
69
+ * character and a non-word one, and there is none between the `n` and the `'`
70
+ * of "isn't". The alternative was dead for as long as it was written that way,
71
+ * so "Medic-1 isn't en route" read as a CLAIM and the desk was corrected for
72
+ * saying the true thing — the exact inversion of this file's stated bias. Every
73
+ * other alternative begins and ends with a word character, so the shared `\b`
74
+ * pair is right for them; `n't` and `'ll` carry the boundary they actually
75
+ * have, which is the trailing one. The curly apostrophe is accepted too: a model
76
+ * writes "isn’t" often enough, and a guardrail that misses the typographic form
77
+ * is the same bug in a different font.
78
+ *
79
+ * `n['’]t` also covers "won't", "can't" and "doesn't", none of which any other
80
+ * alternative here reaches.
81
+ */
82
+ const NOT_A_CLAIM =
83
+ /(?:\b(?:no|not|none|nothing|never|nobody|yet|once|when|if|until|before|after|will|going to|need|should|about to)|n['’]t|['’]ll)\b/i;
84
+
85
+ /**
86
+ * Does this reply tell the room that units are already moving?
87
+ *
88
+ * A keyword heuristic, and the bias is deliberate: `NOT_A_CLAIM` is broad, so
89
+ * the check MISSES a claim far more often than it blocks an innocent sentence.
90
+ * That is the right way round for a guardrail whose verdict is spoken over the
91
+ * top of a dispatcher — a missed claim leaves the desk where it was, and a
92
+ * false block interrupts a shift with a correction that is not true.
93
+ *
94
+ * The state gate above is what makes the false-positive rate tolerable at all:
95
+ * this function is only ever consulted on an incident with nothing assigned to
96
+ * it, which on a working shift is a minority of turns.
97
+ *
98
+ * Exported because it is the half worth testing directly — the guardrail around
99
+ * it is two branches over the board.
100
+ */
101
+ export function claimsUnitsMoving(text: string): boolean {
102
+ return (text.match(SENTENCES) ?? []).some(
103
+ (sentence) => MOVING.test(sentence) && !NOT_A_CLAIM.test(sentence),
104
+ );
105
+ }
@@ -32,6 +32,7 @@ Operational rules:
32
32
  - Location is always the first priority in any emergency call
33
33
  - Critical incidents get immediate dispatch, triage can happen simultaneously
34
34
  - Never leave a critical incident without at least one resource dispatched
35
+ - Never say units are moving until resources_dispatch has actually assigned one. The desk checks this before it speaks: a reply that claims help is rolling on an incident with nothing on it is replaced by a correction the room hears instead
35
36
  - Monitor resource utilization. If it exceeds 65 percent, warn about degraded capacity
36
37
  - At red alert level, recommend mutual aid from neighboring jurisdictions
37
38
  - Track time on all incidents. Escalate if critical incidents have no on-scene resources within 8 minutes
@@ -27,11 +27,12 @@
27
27
  * then passes or fails for the wrong reason.
28
28
  */
29
29
  import agentDef from "virtual:aai/agent";
30
- import type { SessionEvent } from "@alexkroman1/aai/protocol";
30
+ import type { SessionEvent } from "@alexkroman1/aai";
31
31
  import {
32
32
  createVmRunCode,
33
33
  customEventsIn,
34
34
  describeTurn,
35
+ expectCalled,
35
36
  lastStateIn,
36
37
  runCodeIn,
37
38
  runCodeOutput,
@@ -133,6 +134,12 @@ describeEval(
133
134
  await session.say("I want something cozy to watch tonight.");
134
135
  const turn = await session.say("Now give me something spooky to read.");
135
136
 
137
+ // `expectCalled` first, because "the host named something out of its own
138
+ // head and ended the turn" is how this case actually fails — the night's
139
+ // log stays empty and `revisit` has nothing to find. It reports the
140
+ // sentence spoken in place of the call, where `expected [] to deeply
141
+ // equal [ 'recommend' ]` reported neither.
142
+ expectCalled(turn, "recommend");
136
143
  expect(toolNames(turn.toolCalls)).toEqual(["recommend"]);
137
144
  expect(turn.toolCalls[0]!.args).toEqual({ category: "book", mood: "spooky" });
138
145
 
@@ -229,7 +236,7 @@ describeEval(
229
236
  // about a companion that talked its way through the sum instead, and it
230
237
  // names a cancelled reply, which is the usual reason a turn reached for
231
238
  // nothing.
232
- expect(toolNames(turn.toolCalls), describeTurn(turn)).toContain("run_code");
239
+ expectCalled(turn, "run_code");
233
240
  // The recipe is the prompt's, and it is two constants: a 90-minute cycle
234
241
  // plus the 15 minutes it takes to fall asleep. Arithmetic done in the
235
242
  // model's head has neither of them anywhere in the code. `runCodeIn`
@@ -3,6 +3,7 @@ import { nightProjection } from "./shared.ts";
3
3
 
4
4
  export default agent({
5
5
  name: "Night Owl",
6
+ description: "Recommends films, music and books for the evening, and works out when to go to bed",
6
7
  // The night's recommendation log, pushed to the client after every tool
7
8
  // call. The page renders `useAgentState(nightProjection)` and keeps no copy
8
9
  // of its own, so a reload resumes with the list intact.
@@ -2,6 +2,12 @@ You are Night Owl, a cozy evening companion. You help people wind down,
2
2
  recommend entertainment, and share interesting facts about the night sky. Keep
3
3
  your tone warm and relaxed. Use short, conversational responses.
4
4
 
5
+ Every recommendation goes through the recommend tool — call it, then say what
6
+ it gave you. Naming something out of your own head instead leaves the night's
7
+ log empty, so the sidebar shows nothing and revisit has nothing to find later.
8
+ Call it before you speak: saying the title first ends your turn and the pick is
9
+ never recorded.
10
+
5
11
  When someone asks about something you already recommended tonight, look it up
6
12
  with revisit and pass along their own words — never recall it from memory.
7
13
 
@@ -43,6 +43,13 @@ export default nightSlot.tool({
43
43
  // Two words the listener can name, scored independently: "the spooky
44
44
  // books" beats a spooky MOVIE and a cozy BOOK, and "the spooky ones"
45
45
  // ties them — which is a refusal that asks, not a coin flip.
46
+ //
47
+ // A hand-written scorer where four sibling templates use `resolveOne`'s
48
+ // built-in `match`, and deliberately: a listener says "books" where the
49
+ // field says `book`, and the built-in matches whole WORDS on both sides
50
+ // with no stemming, so the plural would score nothing and every category
51
+ // would tie. Substring containment against two NAMED fields is the
52
+ // domain fact here, which is exactly what `score` is kept for.
46
53
  score: (rec, text) =>
47
54
  (text.includes(rec.mood) ? 1 : 0) + (text.includes(rec.category) ? 1 : 0),
48
55
  }),
@@ -23,8 +23,10 @@
23
23
  import agentDef from "virtual:aai/agent";
24
24
  import { dialogRefusalPattern } from "@alexkroman1/aai/testing";
25
25
  import {
26
+ describeToolCalls,
26
27
  describeTurn,
27
28
  type EvalSession,
29
+ expectCalled,
28
30
  lastStateIn,
29
31
  statesIn,
30
32
  toolCallsInTurns,
@@ -70,17 +72,37 @@ const DRAFT =
70
72
  describeEval(agentDef, (test) => {
71
73
  test(
72
74
  "the call opens with a triage, and a triage sends nothing",
73
- async ({ session }) => {
75
+ async ({ session, mode }) => {
74
76
  const turn = await session.say("Morning. What came in?");
75
- expect(toolNames(turn.toolCalls), describeTurn(turn)).toContain("triage_inbox");
76
- // Their `route_after_triage`: two `no`s filed on the spot, six queued.
77
+ expectCalled(turn, "triage_inbox");
78
+ // Their `route_after_triage` routed EVERY email: nothing is left
79
+ // `untriaged`. `open` is allowed because a desk that went on to open the
80
+ // first one has still triaged all eight, and whether it opens unprompted
81
+ // is the next case's business rather than this one's.
77
82
  const view = latest(session);
78
- expect(view?.emails.filter((e) => e.status === "closed")).toHaveLength(2);
79
- expect(view?.emails.filter((e) => e.status === "queued")).toHaveLength(6);
80
- // Triage is not a proposal, and nothing was sent by reading the inbox.
81
- expect(view?.proposal).toBeNull();
83
+ expect(view?.emails).toHaveLength(TRIAGE_SCRIPT.length);
84
+ expect(
85
+ view?.emails.every((e) => e.status !== "untriaged"),
86
+ describeTurn(turn),
87
+ ).toBe(true);
88
+ // The exact split is the TRIAGE model's judgment — one verdict per email,
89
+ // eight of them — so it is pinned only where `TRIAGE_SCRIPT` determines
90
+ // it. Live it drifts: a run that filed nothing failed this case on "expected
91
+ // [] to have a length of 2", which reads as broken routing rather than as
92
+ // a model that found every email worth answering.
93
+ if (mode === "stub") {
94
+ expect(view?.emails.filter((e) => e.status === "closed")).toHaveLength(2);
95
+ expect(view?.emails.filter((e) => e.status === "queued")).toHaveLength(6);
96
+ }
97
+ // THE claim, and the one this case is named for: reading the inbox sent
98
+ // nothing. Live, that is all it asserts.
82
99
  expect(view?.sent).toEqual([]);
83
100
  expect(toolNames(turn.toolCalls)).not.toContain("accept");
101
+ // A triage is not a proposal — true of the SCRIPT, which runs `triage_inbox`
102
+ // and stops. A live desk that opened the first email as well has staged a
103
+ // proposal and still sent nothing, so pinning this live measured its
104
+ // helpfulness rather than the gate.
105
+ if (mode === "stub") expect(view?.proposal).toBeNull();
84
106
  },
85
107
  {
86
108
  stubReply: [
@@ -94,18 +116,37 @@ describeEval(agentDef, (test) => {
94
116
  test(
95
117
  "a draft is staged and read back, and nothing is sent before a yes",
96
118
  async ({ session }) => {
97
- const turn = await session.say(
119
+ // Two turns, and the second only repeats the instruction the first
120
+ // carried. The desk opens the email and then usually SPEAKS — one tool
121
+ // per reply is the live model's median — so reading both calls out of a
122
+ // single turn measured that rather than the gate. Nothing below cares
123
+ // which turn the staging landed in: the claim is that staging produced a
124
+ // READ-BACK and not a receipt, and that nothing was sent without a yes.
125
+ //
126
+ // The nudge is worded twice over. "Go ahead and draft that reply" reads as
127
+ // APPROVAL to a live model, which answered it with `accept` — passing the
128
+ // chain and failing the one assertion this case exists for. "Draft it, but
129
+ // do not send anything yet" fixed that and cost the other half: the desk
130
+ // heard the negation and did nothing at all, and a bare "write that reply
131
+ // for me" was no better. What works is an instruction to ACT that names
132
+ // the reply AND its content while saying nothing about sending — there is
133
+ // no yes in it to mishear, and nothing to read as "wait".
134
+ const turns = await session.sayAll([
98
135
  "Open the one from Dana at Northwind and reply that yes, inference stays inside their VPC.",
99
- );
100
- const names = toolNames(turn.toolCalls);
101
- expect(names, describeTurn(turn)).toContain("open_email");
102
- expect(names).toContain("draft_reply");
136
+ "Write the reply now — say yes, it stays inside their VPC.",
137
+ ]);
138
+ const calls = toolCallsInTurns(turns);
139
+ const names = toolNames(calls);
140
+ // Across BOTH turns, and named: "expected [ 'open_email' ] to include
141
+ // 'draft_reply'" said nothing about what the desk did instead.
142
+ expectCalled(turns, "open_email", "draft_reply");
103
143
  // The staging tool answered with the read-back, not a receipt.
104
- const staged = turn.toolCalls.find((call) => call.name === "draft_reply");
144
+ const staged = calls.find((call) => call.name === "draft_reply");
105
145
  expect(staged?.result).toMatch(/awaitingDecision/);
106
146
  expect(staged?.result).toMatch(/Nothing has been sent/);
107
- // The assistant asks; it does not decide. An `accept` in the same turn as
108
- // the staging is the agent confirming on its own initiative.
147
+ // The assistant asks; it does not decide. An `accept` anywhere in here is
148
+ // the agent confirming on its own initiative — neither utterance was a
149
+ // yes to SEND, only an instruction to draft.
109
150
  expect(names).not.toContain("accept");
110
151
  // THE claim: through every frame, nothing went out.
111
152
  for (const view of frames(session)) expect(view.sent).toEqual([]);
@@ -117,6 +158,7 @@ describeEval(agentDef, (test) => {
117
158
  {
118
159
  stubReply: [
119
160
  { tool: "open_email", args: { which: "m2" } },
161
+ "Dana is asking whether inference stays inside their VPC.",
120
162
  { tool: "draft_reply", args: { content: DRAFT } },
121
163
  "Here's the draft: Dana, it stays inside your VPC, models included. Send it?",
122
164
  ],
@@ -145,8 +187,14 @@ describeEval(agentDef, (test) => {
145
187
  test(
146
188
  "the executive's yes is the only thing that sends",
147
189
  async ({ session }) => {
190
+ // Three turns: the request, an instruction to draft, THEN the yes. The
191
+ // middle one exists because the desk reliably opens the email and speaks
192
+ // rather than chaining the staging into the same reply, which left this
193
+ // case failing on a draft that had not happened yet rather than on the
194
+ // gate it is here to measure. The yes is still the only send.
148
195
  const turns = await session.sayAll([
149
196
  "Open Dana's email from Northwind and reply that inference stays inside their VPC.",
197
+ "Write the reply now — say inference stays inside their VPC.",
150
198
  "Yes. Send it.",
151
199
  ]);
152
200
  const calls = toolCallsInTurns(turns);
@@ -154,7 +202,11 @@ describeEval(agentDef, (test) => {
154
202
  // Staged first, sent second, once each — reversed, or a send with nothing
155
203
  // staged, is the regression this template's whole shape exists to prevent.
156
204
  expect(names.indexOf("draft_reply"), describeTurn(turns[0]!)).toBeGreaterThanOrEqual(0);
157
- expect(names.lastIndexOf("accept")).toBeGreaterThan(names.indexOf("draft_reply"));
205
+ // Named across BOTH turns: "expected -1 to be greater than 2" says a send
206
+ // never happened and nothing about what the desk did with the yes instead.
207
+ expect(names.lastIndexOf("accept"), describeToolCalls(calls)).toBeGreaterThan(
208
+ names.indexOf("draft_reply"),
209
+ );
158
210
  const sent = calls.filter(
159
211
  (call) => call.name === "accept" && /"sent"/.test(call.result ?? ""),
160
212
  );
@@ -172,6 +224,7 @@ describeEval(agentDef, (test) => {
172
224
  {
173
225
  stubReply: [
174
226
  { tool: "open_email", args: { which: "m2" } },
227
+ "Dana wants to know whether inference stays inside their VPC.",
175
228
  { tool: "draft_reply", args: { content: DRAFT } },
176
229
  "Here's the draft — it stays inside your VPC. Send it?",
177
230
  { tool: "accept" },
@@ -186,7 +239,7 @@ describeEval(agentDef, (test) => {
186
239
  async ({ session }) => {
187
240
  const turn = await session.say("Open the Docusign one.");
188
241
  const names = toolNames(turn.toolCalls);
189
- expect(names, describeTurn(turn)).toContain("open_email");
242
+ expectCalled(turn, "open_email");
190
243
  // Their `notify` route halts for the human with nothing drafted.
191
244
  expect(names).not.toContain("draft_reply");
192
245
  const view = latest(session);
@@ -207,11 +260,19 @@ describeEval(agentDef, (test) => {
207
260
  "a scheduling request goes through the meeting assistant before any draft",
208
261
  async ({ session }) => {
209
262
  const scheduling = INBOX.find((e) => e.id === "m4");
210
- const turn = await session.say(
263
+ // Two turns, and the second NAMES the action. "Yes, go ahead" left this a
264
+ // coin toss (measured 1/2 over repeats) because it authorises without
265
+ // saying what to do; naming the calendar is what a caller answering
266
+ // "shall I check?" actually says. The judgement being
267
+ // measured is that the CALENDAR is consulted before a time is written
268
+ // down — an ordering claim, and the ordering holds across the pair.
269
+ const turns = await session.sayAll([
211
270
  `Open the one from Sam Reyes, "${scheduling?.subject}", and sort out a time with him.`,
212
- );
213
- const names = toolNames(turn.toolCalls);
214
- expect(names, describeTurn(turn)).toContain("meeting_assistant");
271
+ "Check my calendar and find us a slot.",
272
+ ]);
273
+ const calls = toolCallsInTurns(turns);
274
+ const names = toolNames(calls);
275
+ expectCalled(turns, "meeting_assistant");
215
276
  // The calendar is consulted before a time is ever written down: the brief
216
277
  // says never to guess free time, and a draft or an invite that came first
217
278
  // would have.
@@ -220,8 +281,8 @@ describeEval(agentDef, (test) => {
220
281
  const at = names.indexOf(later);
221
282
  if (at >= 0) expect(at).toBeGreaterThan(checked);
222
283
  }
223
- // And the specialist's report is what came back — not a calendar dump.
224
- const report = turn.toolCalls.find((call) => call.name === "meeting_assistant");
284
+ // And the subagent's report is what came back — not a calendar dump.
285
+ const report = calls.find((call) => call.name === "meeting_assistant");
225
286
  expect(report?.result).toMatch(/availability/);
226
287
  expect(latest(session)?.sent).toEqual([]);
227
288
  },
@@ -75,23 +75,29 @@ function scriptedDesk(
75
75
  ) {
76
76
  return scriptedToolContext({
77
77
  generate: {
78
- [TRIAGE_SYSTEM]: (call) => ({ object: verdictFor(call.prompt) }),
79
- [REWRITE_SYSTEM]: (call) => ({
80
- object: {
81
- toneLogic: "casual and direct",
82
- rewrittenContent: `(in Maya's voice) ${draftIn(call.prompt)}`,
78
+ routes: {
79
+ [TRIAGE_SYSTEM]: (call) => ({ object: verdictFor(call.prompt) }),
80
+ [REWRITE_SYSTEM]: (call) => ({
81
+ object: {
82
+ toneLogic: "casual and direct",
83
+ rewrittenContent: `(in Maya's voice) ${draftIn(call.prompt)}`,
84
+ },
85
+ }),
86
+ [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: opts.chooser ?? [] } },
87
+ [UPDATE_MEMORY_SYSTEM]: {
88
+ object: opts.update ?? { logic: "", updatePrompt: false, newPrompt: "" },
83
89
  },
84
- }),
85
- [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: opts.chooser ?? [] } },
86
- [UPDATE_MEMORY_SYSTEM]: {
87
- object: opts.update ?? { logic: "", updatePrompt: false, newPrompt: "" },
88
90
  },
89
91
  },
90
92
  delegate: {
91
- "meeting-assistant": {
92
- text: "Maya is free Wednesday 1pm-3pm.",
93
- steps: 3,
94
- toolCalls: [{ name: "get_events_for_days", input: { days: ["2026-03-17", "2026-03-18"] } }],
93
+ routes: {
94
+ "meeting-assistant": {
95
+ text: "Maya is free Wednesday 1pm-3pm.",
96
+ steps: 3,
97
+ toolCalls: [
98
+ { name: "get_events_for_days", input: { days: ["2026-03-17", "2026-03-18"] } },
99
+ ],
100
+ },
95
101
  },
96
102
  },
97
103
  });
@@ -594,17 +600,19 @@ describe("reflect (their multi_reflection_graph)", () => {
594
600
  test("rewrites each chosen prompt in parallel and skips a declined one", async () => {
595
601
  let updates = 0;
596
602
  const model = stubGenerate({
597
- [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: ["tone", "calendar"] } },
598
- [UPDATE_MEMORY_SYSTEM]: (call) => {
599
- updates += 1;
600
- const calendar = call.prompt.includes(DEFAULT_MEMORY.schedulePreferences);
601
- return {
602
- object: {
603
- logic: calendar ? "45 minutes" : "",
604
- updatePrompt: calendar,
605
- newPrompt: calendar ? "Meetings are 45 minutes." : "",
606
- },
607
- };
603
+ routes: {
604
+ [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: ["tone", "calendar"] } },
605
+ [UPDATE_MEMORY_SYSTEM]: (call) => {
606
+ updates += 1;
607
+ const calendar = call.prompt.includes(DEFAULT_MEMORY.schedulePreferences);
608
+ return {
609
+ object: {
610
+ logic: calendar ? "45 minutes" : "",
611
+ updatePrompt: calendar,
612
+ newPrompt: calendar ? "Meetings are 45 minutes." : "",
613
+ },
614
+ };
615
+ },
608
616
  },
609
617
  });
610
618
  const out = await reflect(model.generate, { ...input, promptTypes: ["tone", "calendar"] });
@@ -620,7 +628,9 @@ describe("reflect (their multi_reflection_graph)", () => {
620
628
  });
621
629
 
622
630
  test("a chooser that names nothing costs no second call", async () => {
623
- const model = stubGenerate({ [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: [] } } });
631
+ const model = stubGenerate({
632
+ routes: { [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: [] } } },
633
+ });
624
634
  expect(await reflect(model.generate, { ...input, promptTypes: ["tone"] })).toEqual([]);
625
635
  expect(model.calls).toHaveLength(1);
626
636
  });
@@ -35,6 +35,7 @@ import systemPrompt from "./system-prompt.md?raw";
35
35
  */
36
36
  export default agent({
37
37
  name: "Executive Assistant",
38
+ description: "Triages an executive's inbox by phone and drafts the replies for their approval",
38
39
  // The voice rules in the file, plus who the principal is — their
39
40
  // `config.yaml`'s `full_name`, `name`, `background` and `timezone`, rendered
40
41
  // from the one place `inbox.ts` declares them so the prompt cannot name a