@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
@@ -1,3 +1,14 @@
1
+ /**
2
+ * The def a DEPLOYED agent runs: authored, plus what `tools/` and
3
+ * `system-prompt.md` declare.
4
+ *
5
+ * `./agent.ts` would be the wrong import even for a template this small.
6
+ * Discovery happens where the bundle is assembled, so the authored export has
7
+ * NO tools and the framework-default prompt — an eval driving it measures a
8
+ * different agent than the one that deploys, and the tool-choice claim below
9
+ * would pass or fail for the wrong reason.
10
+ */
11
+ import agentDef from "virtual:aai/agent";
1
12
  // An EVAL: does the agent actually behave? Run it with `aai eval`.
2
13
  //
3
14
  // A test asserts about the config (see agent.test.ts — it never calls a model).
@@ -17,10 +28,10 @@
17
28
  // What no eval here can see: anything below the audio boundary — where the
18
29
  // agent decides you stopped talking, how it handles being interrupted, whether
19
30
  // two sentences merged into one turn. Those need real paced audio.
20
- import { errorsIn } from "@alexkroman1/aai-runtime/eval";
31
+ import { errorsIn, toolNames } from "@alexkroman1/aai-runtime/eval";
32
+ import { evalSimulation } from "@alexkroman1/aai-runtime/eval/simulate";
21
33
  import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
22
34
  import { expect } from "vitest";
23
- import agentDef from "./agent.ts";
24
35
 
25
36
  describeEval(agentDef, (test) => {
26
37
  test(
@@ -33,12 +44,38 @@ describeEval(agentDef, (test) => {
33
44
 
34
45
  expect(turn.completed).toBe(true);
35
46
  expect(turn.text).toMatch(/paris/i);
36
- // This agent has no tools, so reaching for one would be a real finding.
47
+ // The agent's one tool looks up WEATHER, so reaching for it here would
48
+ // be a real finding — not "this agent has no tools", which is what this
49
+ // line used to say and stopped being true the day it got one.
37
50
  expect(turn.toolCalls).toEqual([]);
38
51
  },
39
52
  { stubReply: "Paris is the capital of France." },
40
53
  );
41
54
 
55
+ test(
56
+ "reaches for the tool that is only a FILE",
57
+ async ({ session }) => {
58
+ const turn = await session.say("What's the weather in Denver?");
59
+
60
+ // The claim the quickstart makes about this project: `get_weather` is a
61
+ // file in `tools/` that nothing imports and nothing registers, and this
62
+ // is the case that would notice if the directory went missing — a
63
+ // scripted run still boots the agent and still executes the tool a
64
+ // script names, so it checks the wiring even with no key set.
65
+ expect(toolNames(turn.toolCalls)).toEqual(["get_weather"]);
66
+ expect(turn.text).toMatch(/denver/i);
67
+ },
68
+ // The tool really runs, and really calls wttr.in. Nothing here asserts on
69
+ // what it answered: a service that is down returns the `{ error }` the
70
+ // tool is written to hand back, and the claim is about the CHOICE.
71
+ {
72
+ stubReply: [
73
+ { tool: "get_weather", args: { city: "Denver" } },
74
+ "It's 54 degrees and clear in Denver.",
75
+ ],
76
+ },
77
+ );
78
+
42
79
  test(
43
80
  "keeps the thread across two turns",
44
81
  async ({ session }) => {
@@ -54,4 +91,55 @@ describeEval(agentDef, (test) => {
54
91
  // answered the first would fail the case it is supposed to let run.
55
92
  { stubReply: ["Nice to meet you, Sam.", "You said your name was Sam."] },
56
93
  );
94
+
95
+ test(
96
+ "a simulated caller gets a forecast, and a judge grades the call",
97
+ async ({ session, mode }) => {
98
+ // The caller and the judge come from `/eval/simulate`, built over this
99
+ // case's own session and mode. In a keyless run all three models are
100
+ // scripted: the agent's replies (`stubReply` below), the caller's lines
101
+ // (ending on `end_call`) and the judge's rulings. That checks the loop
102
+ // is wired; it grades nothing, and the verdict says so.
103
+ const { simulate, judge } = evalSimulation({
104
+ agent: agentDef,
105
+ mode,
106
+ target: session,
107
+ stubCaller: [
108
+ "Hi, do I need an umbrella in Seattle today?",
109
+ { tool: "end_call", args: { reason: "got the forecast" } },
110
+ ],
111
+ });
112
+
113
+ // A SECOND model plays the caller: it is told who it is and what it
114
+ // wants, reads each reply, answers it, and hangs up with `end_call` once
115
+ // it has what it came for. Nobody scripted these lines — which is the
116
+ // point: the caller that gives its city only when asked is the one a
117
+ // scripted case never writes.
118
+ const call = await simulate({
119
+ persona: "a friendly commuter on a phone, who answers in short sentences",
120
+ goal: "find out whether to bring an umbrella in Seattle today",
121
+ });
122
+
123
+ // The call ending on the caller's terms is the first thing to know: a
124
+ // call that ran out of turns usually means the goal was never met.
125
+ expect(call.endedBy, call.transcript()).toBe("caller");
126
+ expect(call.metrics.toolCallCounts.get_weather ?? 0).toBeGreaterThan(0);
127
+
128
+ // What deterministic readers cannot see — whether the answer MEANT
129
+ // anything — goes to a model-graded judge, one ruling per criterion.
130
+ // A judge is a noisy instrument: run it under AAI_EVAL_REPEAT and read
131
+ // the spread before trusting one verdict.
132
+ const verdict = await judge(call, [
133
+ "The agent looked up the weather before answering.",
134
+ "The agent's answer says whether an umbrella is needed.",
135
+ ]);
136
+ expect(verdict.pass, verdict.explain()).toBe(true);
137
+ },
138
+ {
139
+ stubReply: [
140
+ { tool: "get_weather", args: { city: "Seattle" } },
141
+ "It's raining in Seattle, so bring an umbrella.",
142
+ ],
143
+ },
144
+ );
57
145
  });
@@ -1,3 +1,5 @@
1
+ /** The def a DEPLOYED agent runs: authored, plus `tools/` and `system-prompt.md`. */
2
+ import deployedDef from "virtual:aai/agent";
1
3
  import { agent, assemblyAIPipeline, DEFAULT_SYSTEM_PROMPT } from "@alexkroman1/aai";
2
4
  import { expectDeployable } from "@alexkroman1/aai/testing";
3
5
  import { describe, expect, test } from "vitest";
@@ -54,6 +56,26 @@ describe("quickstart-agent template", () => {
54
56
  }
55
57
  });
56
58
 
59
+ test("the two DISCOVERED halves are really discovered", () => {
60
+ // The template's central claim, and until it shipped these files there was
61
+ // nothing here to make it. `virtual:aai/agent` is the lowering a DEPLOYED
62
+ // agent gets — the authored def plus what `tools/` and `system-prompt.md`
63
+ // declare — so this asserts the thing the quickstart tells a reader to
64
+ // trust: the tool is registered by being a file, and the prompt is applied
65
+ // by sitting beside `agent.ts`.
66
+ //
67
+ // `deployedDef` rather than `agentDef` above: the raw export has no tools
68
+ // and the framework-default prompt, which is exactly what makes an
69
+ // assertion against it unable to see either half go missing.
70
+ expect(Object.keys(deployedDef.tools ?? {})).toEqual(["get_weather"]);
71
+ // Not "some prompt" but NOT the framework's — `system-prompt.md` is the
72
+ // one file an author edits first, and a prompt silently ignored produces
73
+ // an agent that behaves plausibly and wrongly rather than one that
74
+ // visibly cannot do something.
75
+ expect(deployedDef.systemPrompt).not.toBe(DEFAULT_SYSTEM_PROMPT);
76
+ expect(deployedDef.systemPrompt).toContain("get_weather");
77
+ });
78
+
57
79
  test("write no prompt and you already have one: the SDK's voice core", () => {
58
80
  // The other half of "declares nothing and still runs", and the one an
59
81
  // author meets first. Built here rather than read off `agentDef`, so
@@ -1,8 +1,24 @@
1
1
  import { agent } from "@alexkroman1/aai";
2
2
 
3
+ // The whole agent. Three files make it up and none of them imports another:
4
+ // this one, `system-prompt.md` beside it, and `tools/get_weather.ts` — each
5
+ // found by WHERE IT SITS. That is the idea the rest of the framework is built
6
+ // on, so it is worth seeing here before anywhere else.
7
+ //
3
8
  // No providers declared: the agent runs the default all-AssemblyAI cascaded
4
- // pipeline, billed to ASSEMBLYAI_API_KEY. (Add `voice: "..."` to pick its
5
- // TTS voice, or declare any of stt/llm/tts to swap a single stage.)
9
+ // pipeline, billed to ASSEMBLYAI_API_KEY. Declare any of stt/llm/tts to swap a
10
+ // single stage.
6
11
  export default agent({
7
12
  name: "Quickstart Assistant",
13
+ // One line for whoever is reading a LIST of agents — `aai list`, a registry
14
+ // page, the studio's picker. Never the model: what the model is told is
15
+ // `system-prompt.md`, beside this file.
16
+ description: "Looks up the current weather for any city",
17
+ // The first thing a caller hears. Without one the agent waits for them to
18
+ // speak, which on a phone call reads as a dead line.
19
+ greeting: "Hi — I can look up the weather anywhere. Which city?",
20
+ // Any name from `ASSEMBLYAI_TTS_VOICES`. It is sugar for a `tts` descriptor,
21
+ // so declaring `tts: assemblyAITts({ voice })` yourself is the same thing
22
+ // spelled out — and either one replaces only the speaking stage.
23
+ voice: "jane",
8
24
  });
@@ -0,0 +1,8 @@
1
+ You are a friendly assistant on a voice call. Keep replies to one or two
2
+ sentences — a caller is listening, not reading.
3
+
4
+ Use the get_weather tool whenever someone asks what it is like somewhere, and
5
+ answer from what it returns rather than from memory. Round temperatures to
6
+ whole degrees and say the city back, so a mishearing is obvious.
7
+
8
+ If a lookup fails, say so plainly and offer to try another city.
@@ -0,0 +1,59 @@
1
+ import { tool } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+
4
+ /**
5
+ * The two fields this tool reads out of wttr.in's JSON.
6
+ *
7
+ * Narrowed by hand rather than typed as the whole response: a tool's result is
8
+ * recorded in the conversation and sent to the model, so returning everything
9
+ * a third-party API happens to include spends context on fields nobody reads.
10
+ */
11
+ type Wttr = {
12
+ current_condition?: [{ temp_F?: string; weatherDesc?: [{ value?: string }] }];
13
+ };
14
+
15
+ // This file IS the tool. It sits in `tools/`, so the model calls it
16
+ // `get_weather` — the filename and nothing else names it, and neither
17
+ // `agent.ts` nor any list mentions it. Adding an ability is adding a file
18
+ // here.
19
+ export default tool({
20
+ description: "Get the current weather for a city.",
21
+ inputSchema: z.object({ city: z.string().describe("City name, e.g. Denver") }),
22
+ // What the caller HEARS while this runs. A third-party lookup on a live call
23
+ // is the case the field exists for: without it the agent goes silent for as
24
+ // long as wttr.in takes, which sounds like a dropped call rather than like
25
+ // someone checking.
26
+ //
27
+ // Several entries at one moment are VARIANTS — one is drawn per call, so an
28
+ // agent asked about three cities does not say the same sentence three times.
29
+ // Different `afterMs` values are STAGES: the second line below is the one a
30
+ // caller hears only when the first was not enough.
31
+ //
32
+ // None of this is recorded. A hold line is heard, never written into the
33
+ // conversation, and never counts as the agent having spoken — so a caller
34
+ // who talks over one is not interrupting the reply being fetched behind it.
35
+ messages: {
36
+ start: ["Let me check that.", "One moment, checking the forecast."],
37
+ delayed: [{ afterMs: 4000, content: "Still waiting on the weather service." }],
38
+ // `role: "system"` hands the model a hint instead of a sentence: the
39
+ // failure is worth apologizing for in the agent's own voice, and only the
40
+ // model knows what the caller asked.
41
+ failed: [
42
+ { role: "system", content: "The weather lookup failed. Apologize and offer to retry." },
43
+ ],
44
+ },
45
+ execute: async ({ city }, ctx) => {
46
+ // `ctx.signal` is the tool call's own deadline. Passing it means a slow
47
+ // service ends the FETCH rather than being waited out and then discarded,
48
+ // which on a live call is the difference between a short apology and a
49
+ // silence the caller hangs up on.
50
+ const res = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=j1`, {
51
+ signal: ctx.signal,
52
+ });
53
+ // Returned, not thrown: a tool failure the model can read is one it can
54
+ // apologize for out loud, which on a call beats silence.
55
+ if (!res.ok) return { error: `The weather service answered ${res.status}.` };
56
+ const now = ((await res.json()) as Wttr).current_condition?.[0];
57
+ return { city, tempF: now?.temp_F, conditions: now?.weatherDesc?.[0]?.value };
58
+ },
59
+ });
@@ -142,7 +142,7 @@ function scriptSteps(options: { hold?: boolean } = {}): ScriptedSteps {
142
142
  // resolves a provider client, so the seam a step reaches it through is the
143
143
  // delegate slot. Unstubbed it THROWS, which is why a converted template's eval
144
144
  // cannot silently keep passing over research that never ran.
145
- installStubStepDelegate({ researcher: RESEARCH_FINDINGS });
145
+ installStubStepDelegate({ routes: { researcher: RESEARCH_FINDINGS } });
146
146
  return { calls: stub.calls, release: () => gate.resolve() };
147
147
  }
148
148
 
@@ -451,7 +451,9 @@ describe("the steps that research", () => {
451
451
  });
452
452
 
453
453
  test("investigate hands the angle to a subagent, with the brief as its context", async () => {
454
- const desk = installStubStepDelegate({ researcher: "Sea otters crack shellfish [1]." });
454
+ const desk = installStubStepDelegate({
455
+ routes: { researcher: "Sea otters crack shellfish [1]." },
456
+ });
455
457
 
456
458
  const note = await investigate(brief, "Tool use");
457
459
 
@@ -467,7 +469,7 @@ describe("the steps that research", () => {
467
469
  test("the researcher is given the web builtins, the budget, and what to answer with", async () => {
468
470
  // What this template still OWNS, now that the loop is the runtime's: which
469
471
  // capabilities the angle is worth, and what a finding has to be.
470
- const desk = installStubStepDelegate({ researcher: "found things" });
472
+ const desk = installStubStepDelegate({ routes: { researcher: "found things" } });
471
473
  await investigate(brief, "Tool use");
472
474
 
473
475
  const researcher = desk.calls[0]?.subagent;
@@ -479,15 +481,17 @@ describe("the steps that research", () => {
479
481
 
480
482
  test("sources are what the researcher CITED", async () => {
481
483
  const desk = installStubStepDelegate({
482
- // The runtime runs a subagent's tools; the stub does not, so the route
483
- // calls `cite` the way a real run would. It is an ordinary `ToolDef`, which
484
- // is what makes that possible at all.
485
- researcher: (call: StubDelegateCall) => {
486
- void call.subagent.tools?.cite?.execute(
487
- { title: "Otters", url: "https://otters.example/tools" },
488
- createToolContext(),
489
- );
490
- return "Sea otters crack shellfish [1].";
484
+ routes: {
485
+ // The runtime runs a subagent's tools; the stub does not, so the route
486
+ // calls `cite` the way a real run would. It is an ordinary `ToolDef`, which
487
+ // is what makes that possible at all.
488
+ researcher: (call: StubDelegateCall) => {
489
+ void call.subagent.tools?.cite?.execute(
490
+ { title: "Otters", url: "https://otters.example/tools" },
491
+ createToolContext(),
492
+ );
493
+ return "Sea otters crack shellfish [1].";
494
+ },
491
495
  },
492
496
  });
493
497
 
@@ -501,13 +505,15 @@ describe("the steps that research", () => {
501
505
  // The worse of the two failures is a note full of findings reporting no
502
506
  // sources at all — the report stage cites from this list.
503
507
  installStubStepDelegate({
504
- researcher: {
505
- text: "Sea otters crack shellfish.",
506
- toolCalls: [
507
- { name: "web_search", input: { query: "otter tool use" } },
508
- { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
509
- { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
510
- ],
508
+ routes: {
509
+ researcher: {
510
+ text: "Sea otters crack shellfish.",
511
+ toolCalls: [
512
+ { name: "web_search", input: { query: "otter tool use" } },
513
+ { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
514
+ { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
515
+ ],
516
+ },
511
517
  },
512
518
  });
513
519
 
@@ -521,13 +527,15 @@ describe("the steps that research", () => {
521
527
  test("investigate reports what the angle cost, since the searches are not visible here", async () => {
522
528
  const reported = installStubReporter();
523
529
  installStubStepDelegate({
524
- researcher: {
525
- text: "found things",
526
- toolCalls: [
527
- { name: "web_search", input: { query: "a" } },
528
- { name: "web_search", input: { query: "b" } },
529
- { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
530
- ],
530
+ routes: {
531
+ researcher: {
532
+ text: "found things",
533
+ toolCalls: [
534
+ { name: "web_search", input: { query: "a" } },
535
+ { name: "web_search", input: { query: "b" } },
536
+ { name: "visit_webpage", input: { url: "https://otters.example/tools" } },
537
+ ],
538
+ },
531
539
  },
532
540
  });
533
541
 
@@ -846,7 +854,7 @@ describe("the run is DURABLE", () => {
846
854
  vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
847
855
  // No `RESEARCH_SLACK_WEBHOOK_URL`, so the filing step posts nothing — which
848
856
  // is why the gateway counts below are the run's model calls and only those.
849
- installStubStepDelegate({ researcher: "Nothing was found on this angle." });
857
+ installStubStepDelegate({ routes: { researcher: "Nothing was found on this angle." } });
850
858
  });
851
859
 
852
860
  /** The step keys a run journaled — the same shape three cases assert on. */
@@ -98,6 +98,10 @@ import { research } from "./shared.ts";
98
98
 
99
99
  export default agent({
100
100
  name: "Research Desk",
101
+ // For a reader of a LIST of agents, never for the model. It names the
102
+ // HANDOFF, because that is what a caller actually gets from this line: an
103
+ // answer later, not an answer now.
104
+ description: "Takes research requests over the phone and reports back when the run lands",
101
105
  greeting: "Research desk. What would you like me to look into?",
102
106
  systemPrompt: [
103
107
  "You take research requests over the phone and read back results.",
@@ -69,6 +69,9 @@ const planState = (session: EvalSession) => lastStateIn(session.events(), Projec
69
69
  * dialog envelope — it reads the position itself. */
70
70
  const IdleStatus = z.object({ stage: z.string(), reads: z.string(), next: z.string() });
71
71
 
72
+ /** How many steps the plan has actually recorded as worked, so far this session. */
73
+ const workedSteps = (session: EvalSession): number => planState(session)?.done.length ?? 0;
74
+
72
75
  describeEval(agentDef, (test) => {
73
76
  test(
74
77
  "the stage the desk reports is the flow's, not a guess at the plan",
@@ -133,6 +136,14 @@ describeEval(agentDef, (test) => {
133
136
  await session.say(
134
137
  "I want to work out whether it is cheaper to take the train or fly from London to Edinburgh next month.",
135
138
  );
139
+ // One more utterance when the desk asked something instead of planning.
140
+ // Its brief allows a single clarifying question, so spending it is legal
141
+ // and the caller answering is what a real call does — without this the
142
+ // case failed on "called no tools" for a desk that was following its own
143
+ // instructions.
144
+ if (session.toolCalls().every((call) => call.name !== "start_plan")) {
145
+ await session.say("Just those two options, next month, cheapest total. Go ahead and plan.");
146
+ }
136
147
  const started = session.toolCalls().find((call) => call.name === "start_plan");
137
148
  // The whole SESSION's calls, not one turn's: the plan may be started on
138
149
  // either utterance, and "expected undefined to be defined" says nothing
@@ -145,13 +156,24 @@ describeEval(agentDef, (test) => {
145
156
  expect(planned?.objective, `start_plan answered: ${started?.result}`).toBeTruthy();
146
157
  expect(planned?.plan.length ?? 0).toBeGreaterThan(0);
147
158
 
148
- const worked = await session.say("Yes, go ahead and start on it.");
159
+ let worked = await session.say("Yes — work the first step now and tell me what it found.");
160
+ // ONE more turn when nothing landed, keyed on the OUTCOME rather than on
161
+ // the tool's message. A step whose `executeStep` throws is put back at the
162
+ // head of the plan by the tool itself, "where a retry will find it" — so a
163
+ // transient delegate failure is a designed-for outcome with a designed-for
164
+ // recovery, and on a real call the caller asking again IS the retry. Read
165
+ // off `done` because the two ways to get here need the same nudge: the
166
+ // step threw, or the desk never called it. Without this a gateway hiccup
167
+ // failed the case on "expected 0 to be greater than 0", naming neither.
168
+ if (workedSteps(session) === 0) worked = await session.say("Give that step another try.");
149
169
  const calls = toolNames(worked.toolCalls).filter((name) => name === "work_next_step").length;
150
170
  expect(calls, describeTurn(worked)).toBeGreaterThan(0);
151
171
 
152
172
  const after = planState(session);
153
173
  const done = after?.done ?? [];
154
- expect(done.length).toBeGreaterThan(0);
174
+ // Named, because "expected 0 to be greater than 0" says nothing about WHY
175
+ // nothing landed — a step that threw answers here with its own sentence.
176
+ expect(done.length, describeToolCalls(session.toolCalls())).toBeGreaterThan(0);
155
177
  // ONE STEP PER CALL: `work_next_step` is one execute-then-replan turn, not
156
178
  // a loop. More steps recorded than calls made would mean the tool had run
157
179
  // the plan to completion, leaving the caller on a silent line with no gap
@@ -92,11 +92,13 @@ function scriptedDesk(script: Script = {}): ScriptedToolContext {
92
92
 
93
93
  return scriptedToolContext({
94
94
  generate: {
95
- [PLANNER_SYSTEM]: { object: { steps: script.steps ?? ["Only step"] } },
96
- [REPLANNER_SYSTEM]: act,
97
- [REVISE_SYSTEM]: act,
95
+ routes: {
96
+ [PLANNER_SYSTEM]: { object: { steps: script.steps ?? ["Only step"] } },
97
+ [REPLANNER_SYSTEM]: act,
98
+ [REVISE_SYSTEM]: act,
99
+ },
98
100
  },
99
- delegate: { executor: worksTheStep },
101
+ delegate: { routes: { executor: worksTheStep } },
100
102
  });
101
103
  }
102
104
 
@@ -125,7 +127,9 @@ describe("planNode", () => {
125
127
 
126
128
  describe("executeStep", () => {
127
129
  test("hands the step to the executor, with the objective and the history as context", async () => {
128
- const desk = stubDelegate({ executor: stepReply("Flights are around 180 return.") });
130
+ const desk = stubDelegate({
131
+ routes: { executor: stepReply("Flights are around 180 return.") },
132
+ });
129
133
 
130
134
  const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", [
131
135
  { step: "Pick dates", result: "Mid-May", settled: true, searches: [] },
@@ -147,12 +151,14 @@ describe("executeStep", () => {
147
151
  // delegation — so the calls are the only honest source for the desk's
148
152
  // "what the wait bought" line.
149
153
  const desk = stubDelegate({
150
- executor: {
151
- text: stepReply("Flights are around 180 return."),
152
- toolCalls: [
153
- { name: "search", input: { query: "lisbon flights may" } },
154
- { name: "search", input: { query: "lisbon flights june" } },
155
- ],
154
+ routes: {
155
+ executor: {
156
+ text: stepReply("Flights are around 180 return."),
157
+ toolCalls: [
158
+ { name: "search", input: { query: "lisbon flights may" } },
159
+ { name: "search", input: { query: "lisbon flights june" } },
160
+ ],
161
+ },
156
162
  },
157
163
  });
158
164
 
@@ -164,7 +170,7 @@ describe("executeStep", () => {
164
170
  test("the executor is given its two tools and a bounded budget", async () => {
165
171
  // What this template still OWNS now that the loop is the runtime's: which
166
172
  // capabilities the step is worth, and how long it may spend.
167
- const desk = stubDelegate({ executor: stepReply("done") });
173
+ const desk = stubDelegate({ routes: { executor: stepReply("done") } });
168
174
  await executeStep(desk.delegate, "objective", "step", []);
169
175
 
170
176
  const executor = desk.calls[0]?.subagent;
@@ -181,7 +187,9 @@ describe("executeStep", () => {
181
187
  // read one string, so a step that found nothing and a step that answered
182
188
  // arrived in the same shape.
183
189
  const desk = stubDelegate({
184
- executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
190
+ routes: {
191
+ executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
192
+ },
185
193
  });
186
194
 
187
195
  const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
@@ -195,9 +203,11 @@ describe("executeStep", () => {
195
203
  // so `accepted` is false — and a `settled: true` from an answer the runtime
196
204
  // refused is exactly the claim not to take at face value.
197
205
  const desk = stubDelegate({
198
- executor: {
199
- text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
200
- complaint: "You reported the step as unsettled without searching for anything.",
206
+ routes: {
207
+ executor: {
208
+ text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
209
+ complaint: "You reported the step as unsettled without searching for anything.",
210
+ },
201
211
  },
202
212
  });
203
213
 
@@ -15,6 +15,9 @@ import { planProjection } from "./shared.ts";
15
15
  */
16
16
  export default agent({
17
17
  name: "Planning Desk",
18
+ // For a reader of a list of agents. It says the LOOP rather than "research",
19
+ // because a caller who wants an answer in one turn is on the wrong line.
20
+ description: "Turns an objective into a plan and works it one step at a time with the caller",
18
21
  // The plan exists before the first tool call, so a resumed connection has
19
22
  // something to project.
20
23
  // The plan, its progress and its revision trail, pushed after every tool call.
@@ -2,7 +2,7 @@ You are the planning desk. Someone calls with something they want to get done, a
2
2
 
3
3
  How a call goes:
4
4
 
5
- - Find out what they actually want first. One clarifying question is usually enough — you are planning, not interviewing.
5
+ - Find out what they actually want first, but only when you actually need to: if what they opened with is already clear enough to plan, call `start_plan` on it straight away. One clarifying question is the most you ever need — you are planning, not interviewing, and a question you did not have to ask costs the caller a whole turn before anything starts.
6
6
  - Call `start_plan` with the objective, then read the steps back in one breath: "I'd do three things — check X, compare Y, then book Z. Want me to start?"
7
7
  - Call `work_next_step` once per step, never in a loop. It does the step, searches the web where it needs to, and updates the plan from what it found.
8
8
  - After each step, say what it found in a sentence and ask whether to carry on. That pause is the point: it is where the caller gets to change their mind.
@@ -8,7 +8,7 @@
8
8
  * readback and the one-customer-per-call rule all live in that file.
9
9
  */
10
10
  import retailAgent from "virtual:aai/agent";
11
- import type { SessionEvent } from "@alexkroman1/aai/protocol";
11
+ import type { SessionEvent } from "@alexkroman1/aai";
12
12
  // An EVAL: does this desk actually behave? Run it with `aai eval`.
13
13
  //
14
14
  // `agent.test.ts` drives each tool directly and asserts about its result;
@@ -4,10 +4,39 @@ import { callFlow, gateFor, record, retailSlot } from "./store.ts";
4
4
 
5
5
  export default agent({
6
6
  name: "Retail Support",
7
+ description: "Looks up orders, returns and store credit for an authenticated retail caller",
7
8
 
8
- // No provider spread: pipeline mode is the default, and an unset stage is
9
- // filled from the all-AssemblyAI pipeline at parse time. Only `stt` is
10
- // overridden below; `llm` and `tts` take the defaults.
9
+ /**
10
+ * A per-session ceiling on what the model may spend.
11
+ *
12
+ * This is the template where a budget earns its place: authentication, an
13
+ * order lookup and a staged change are three tool chains deep, the store's
14
+ * projection is large, and a caller who keeps re-asking can run a session for
15
+ * as long as they like. `maxSteps` bounds a REPLY and says nothing about a
16
+ * call — one step that sends a 100k-token context and one that sends a
17
+ * greeting are the same step.
18
+ *
19
+ * Tokens rather than money: a price is per-model and per-contract, and the
20
+ * SDK carries no table of them (see `UsageLimits`). The number here is a
21
+ * generous ceiling for a support call, not a target — pick yours from what
22
+ * `usage.updated` reports on a real conversation.
23
+ *
24
+ * Reaching it ends the session. An agent that wants a softer landing watches
25
+ * `usage.updated` through `agent({ events })` and says something first.
26
+ *
27
+ * **It was 200_000, and a real call reached 252,825 and ended mid-support.**
28
+ * This is the template with the deepest tool chains and the largest
29
+ * projection, so the old number was a ceiling a legitimate call could touch
30
+ * — and reaching it is not a soft landing, it ends the session. Raised with
31
+ * headroom rather than tuned: read `usage.updated` on a few real
32
+ * conversations and pick from that.
33
+ *
34
+ * The overshoot past whatever number is here is expected and bounded by the
35
+ * requests in flight: the cap is checked BEFORE each request, never
36
+ * mid-stream, because a limit enforced mid-sentence reads to the caller as a
37
+ * dropped call.
38
+ */
39
+ usageLimits: { totalTokens: 2_000_000 },
11
40
 
12
41
  // The store lives in one `sessionSlot` (`store.ts`), a pristine copy per
13
42
  // session — callers must not see each other's cancellations. Nothing declares