@alexkroman1/aai-cli 17.0.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 (61) hide show
  1. package/dist/_console-audio.d.ts +17 -0
  2. package/dist/_console-session.d.ts +70 -0
  3. package/dist/{_dev-server-CLU9xjH5.mjs → _dev-server-Dtp4aAlo.mjs} +1 -1
  4. package/dist/_dev-server.d.ts +1 -0
  5. package/dist/_templates-DXadVNsL.mjs +135 -0
  6. package/dist/_templates.d.ts +11 -34
  7. package/dist/cli.mjs +27 -7
  8. package/dist/console-BsyE3DyB.mjs +422 -0
  9. package/dist/console.d.ts +37 -0
  10. package/dist/{dev-ChsrNHpK.mjs → dev-BGWU2zPP.mjs} +1 -1
  11. package/dist/{init-W-4k-lCF.mjs → init-CbOhyNYe.mjs} +1 -1
  12. package/dist/scaffold/CLAUDE.md +110 -102
  13. package/dist/scaffold/package.json +4 -4
  14. package/dist/start.d.ts +3 -3
  15. package/dist/{studio-DEAJGBXa.mjs → studio-BRJsw7lr.mjs} +1 -1
  16. package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
  17. package/dist/templates/applicant-screening-agent/crews.ts +4 -4
  18. package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
  19. package/dist/templates/coding-agent/agent.ts +1 -1
  20. package/dist/templates/custom-pipeline-agent/agent.ts +2 -2
  21. package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
  22. package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
  23. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
  24. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +1 -1
  25. package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
  26. package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
  27. package/dist/templates/executive-inbox-agent/meeting.ts +2 -2
  28. package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
  29. package/dist/templates/front-desk-agent/agent.test.ts +150 -0
  30. package/dist/templates/front-desk-agent/agent.ts +22 -0
  31. package/dist/templates/front-desk-agent/shared.ts +234 -0
  32. package/dist/templates/front-desk-agent/system-prompt.md +13 -0
  33. package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
  34. package/dist/templates/hotel-reception-agent/agent.test.ts +1 -2
  35. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +1 -2
  36. package/dist/templates/medication-safety-agent/agent.test.ts +3 -4
  37. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
  38. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
  39. package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
  40. package/dist/templates/push-to-talk-agent/agent.ts +22 -0
  41. package/dist/templates/push-to-talk-agent/client.tsx +124 -0
  42. package/dist/templates/push-to-talk-agent/shared.ts +34 -0
  43. package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
  44. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
  45. package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
  46. package/dist/templates/quickstart-agent/agent.eval.test.ts +52 -0
  47. package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
  48. package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
  49. package/dist/templates/research-planner-agent/agent.test.ts +26 -16
  50. package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
  51. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +87 -0
  52. package/dist/templates/roadside-assistance-agent/agent.test.ts +1 -1
  53. package/dist/templates/technical-support-agent/agent.test.ts +26 -20
  54. package/dist/templates/technical-support-agent/procedure.ts +3 -3
  55. package/dist/templates/topic-briefing-agent/agent.test.ts +38 -25
  56. package/dist/templates/topic-briefing-agent/shared.ts +10 -9
  57. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
  58. package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
  59. package/dist/templates/word-game-agent/agent.test.ts +3 -1
  60. package/package.json +4 -4
  61. package/dist/_templates-IMeKMVIj.mjs +0 -291
@@ -2,9 +2,9 @@
2
2
  * The provider catalog: every stage, every vendor, as compiling code.
3
3
  *
4
4
  * `agent.ts` declares ONE stage, because an agent should. This file is the menu
5
- * it picked that line off — the shape of each of the other twenty-odd provider
6
- * factories, the option type each takes, and the published constants an author
7
- * needs to spell a default out loud.
5
+ * it picked that line off — the shape of each of the other provider factories,
6
+ * the option type each takes, and the published constants an author needs to
7
+ * spell a default out loud.
8
8
  *
9
9
  * It lives in the spec rather than in `agent.ts` for a reason worth copying: a
10
10
  * deployed agent needs a key per vendor it names, and the all-AssemblyAI
@@ -21,32 +21,14 @@
21
21
  import type { ProviderCredentialOptions, ProviderDescriptor } from "@alexkroman1/aai";
22
22
  import { agent } from "@alexkroman1/aai";
23
23
  import {
24
- type AnthropicLlmOptions,
25
24
  ASSEMBLYAI_LLM_DEFAULT_MODEL,
26
- ASSEMBLYAI_LLM_GATEWAY_EU_URL,
27
- ASSEMBLYAI_LLM_GATEWAY_URL,
28
25
  type AssemblyAIGatewayModel,
29
- type AssemblyAILlmOptions,
26
+ type AssemblyAILlmProviderOptions,
30
27
  type AssemblyAIReasoningEffort,
31
- anthropicLlm,
32
- assemblyAILlm,
33
- type GatewayLlmOptions,
34
- type GoogleLlmOptions,
35
- type GroqLlmOptions,
36
- gatewayLlm,
37
- googleLlm,
38
- groqLlm,
28
+ type KnownLlmProvider,
29
+ type LlmOptions,
39
30
  type LlmProvider,
40
- type MistralLlmOptions,
41
- type ModelOptions,
42
- mistralLlm,
43
- OPENROUTER_BASE_URL,
44
- type OpenAILlmOptions,
45
- type OpenRouterLlmOptions,
46
- openAILlm,
47
- openRouterLlm,
48
- type XAILlmOptions,
49
- xAILlm,
31
+ llm,
50
32
  } from "@alexkroman1/aai/llm";
51
33
  import { toAgentConfig } from "@alexkroman1/aai/manifest";
52
34
  import {
@@ -107,41 +89,54 @@ function shape(stage: ProviderDescriptor<string, Record<string, unknown>>): stri
107
89
  return `${stage.kind}(${Object.keys(stage.options).sort().join(", ")})`;
108
90
  }
109
91
 
110
- describe("the LLM stage: nine vendors, one field", () => {
111
- test("each factory returns a descriptor whose `kind` names the vendor", () => {
112
- // Keyed BY the kind, so the table is its own assertion: a factory returning
113
- // the wrong kind fails on its own row rather than in an aggregate.
114
- const byKind: Record<string, LlmProvider> = {
115
- anthropic: anthropicLlm({ model: "claude-haiku-4-5" } satisfies AnthropicLlmOptions),
116
- assemblyai: assemblyAILlm({} satisfies AssemblyAILlmOptions),
117
- gateway: gatewayLlm({ model: "zai/glm-4.6" } satisfies GatewayLlmOptions),
118
- google: googleLlm({ model: "gemini-2.5-flash" } satisfies GoogleLlmOptions),
119
- groq: groqLlm({ model: "llama-3.3-70b-versatile" } satisfies GroqLlmOptions),
120
- mistral: mistralLlm({ model: "mistral-large-latest" } satisfies MistralLlmOptions),
121
- openai: openAILlm({ model: "gpt-5-mini" } satisfies OpenAILlmOptions),
122
- openrouter: openRouterLlm({
123
- model: "meta-llama/llama-3.3-70b-instruct",
124
- } satisfies OpenRouterLlmOptions),
125
- xai: xAILlm({ model: "grok-4" } satisfies XAILlmOptions),
92
+ describe("the LLM stage: one factory, the provider is data", () => {
93
+ test("`llm({ provider })` returns a descriptor whose `kind` IS the provider", () => {
94
+ // Keyed BY the provider, so the table is its own assertion: a descriptor
95
+ // with the wrong kind fails on its own row rather than in an aggregate.
96
+ // `KnownLlmProvider` is the autocomplete; the field itself is open.
97
+ const byProvider: Record<KnownLlmProvider, LlmProvider> = {
98
+ anthropic: llm({ provider: "anthropic", model: "claude-haiku-4-5" }),
99
+ assemblyai: llm({ provider: "assemblyai", model: ASSEMBLYAI_LLM_DEFAULT_MODEL }),
100
+ cerebras: llm({ provider: "cerebras", model: "qwen-3.8-27b" }),
101
+ gateway: llm({ provider: "gateway", model: "zai/glm-4.6" }),
102
+ google: llm({ provider: "google", model: "gemini-2.5-flash" }),
103
+ groq: llm({ provider: "groq", model: "llama-3.3-70b-versatile" }),
104
+ mistral: llm({ provider: "mistral", model: "mistral-large-latest" }),
105
+ openai: llm({ provider: "openai", model: "gpt-5-mini" }),
106
+ openrouter: llm({ provider: "openrouter", model: "meta-llama/llama-3.3-70b-instruct" }),
107
+ xai: llm({ provider: "xai", model: "grok-4" }),
126
108
  };
127
109
 
128
- for (const [kind, llm] of Object.entries(byKind)) {
129
- expect(llm.kind, kind).toBe(kind);
110
+ for (const [kind, stage] of Object.entries(byProvider)) {
111
+ expect(stage.kind, kind).toBe(kind);
130
112
  // And it survives the conversion a deploy runs, which is the claim that
131
113
  // matters: a descriptor the config drops is a stage that silently isn't.
132
- expect(toAgentConfig(agent({ name: NAME, llm })).llm?.kind, kind).toBe(kind);
114
+ expect(toAgentConfig(agent({ name: NAME, llm: stage })).llm?.kind, kind).toBe(kind);
133
115
  }
134
116
  });
135
117
 
136
- test("eight of the nine take exactly `ModelOptions` — one id, one key name", () => {
137
- // The shared base is why swapping vendors is a one-word edit: everything
138
- // except the AssemblyAI gateway is reached by naming a model and nothing
139
- // else. Each vendor still gets its own NAME for that options type so its
140
- // first vendor-specific setting is an additive field rather than a re-split
141
- // of the shared interface across eight call sites.
142
- const options: ModelOptions = { model: "gpt-5-mini" };
143
- expect(shape(openAILlm(options))).toBe("openai(model)");
144
- expect(shape(googleLlm({ ...options, model: "gemini-2.5-flash" }))).toBe("google(model)");
118
+ test("swapping vendors is a one-word edit: every provider takes the same options", () => {
119
+ // One options type for all of them — a model id, plus the optional
120
+ // `baseUrl`, `apiKeyEnv` and `providerOptions` — which is why there is no
121
+ // per-vendor factory to learn.
122
+ const options: LlmOptions<"openai"> = { provider: "openai", model: "gpt-5-mini" };
123
+ expect(shape(llm(options))).toBe("openai(model)");
124
+ expect(shape(llm({ ...options, provider: "google", model: "gemini-2.5-flash" }))).toBe(
125
+ "google(model)",
126
+ );
127
+ });
128
+
129
+ test("an unlisted provider is reached by naming its OpenAI-compatible endpoint", () => {
130
+ // `provider` is open (`KnownLlmProvider | (string & {})`): a vendor this
131
+ // release has not heard of compiles, and `baseUrl` is what the host
132
+ // resolver dials it through. `aai build` warns about one with neither.
133
+ const stage = llm({
134
+ provider: "my-inference-host",
135
+ model: "my-model",
136
+ baseUrl: "https://inference.example.com/v1",
137
+ apiKeyEnv: "MY_INFERENCE_KEY",
138
+ });
139
+ expect(shape(stage)).toBe("my-inference-host(apiKeyEnv, baseUrl, model)");
145
140
  });
146
141
 
147
142
  test("`apiKeyEnv` renames the variable the platform reads for this stage", () => {
@@ -153,32 +148,31 @@ describe("the LLM stage: nine vendors, one field", () => {
153
148
  // field only changes WHICH variable it reads, for an agent that keeps two
154
149
  // OpenAI keys, or names the vendor's key something of its own.
155
150
  const credential: ProviderCredentialOptions = { apiKeyEnv: "TEAM_OPENAI_KEY" };
156
- const llm = openAILlm({ model: "gpt-5-mini", ...credential });
157
- expect(llm.options.apiKeyEnv).toBe("TEAM_OPENAI_KEY");
151
+ const stage = llm({ provider: "openai", model: "gpt-5-mini", ...credential });
152
+ expect(stage.options.apiKeyEnv).toBe("TEAM_OPENAI_KEY");
158
153
  // Not a secret and not a value — the NAME of an env var, so it is safe in
159
154
  // the bundle. Nothing here reads `process.env`.
160
- expect(llm.options.model).toBe("gpt-5-mini");
155
+ expect(stage.options.model).toBe("gpt-5-mini");
161
156
  });
162
157
 
163
- test("the AssemblyAI gateway is the one that needs no model id", () => {
158
+ test("the AssemblyAI gateway is the one with a published default model", () => {
164
159
  // The stage `agent.ts` leaves unset. It bills to `ASSEMBLYAI_API_KEY` — the
165
160
  // one key a published agent is guaranteed to have — so its default model is
166
- // published rather than implied: a bare call is a REAL model id in the
167
- // descriptor, not an empty options bag the service has to guess at.
168
- expect(assemblyAILlm().options.model).toBe(ASSEMBLYAI_LLM_DEFAULT_MODEL);
161
+ // published rather than implied.
162
+ expect(typeof ASSEMBLYAI_LLM_DEFAULT_MODEL).toBe("string");
169
163
  // A gateway id is a free-form string the service rejects with a 400 at the
170
- // first session — no compile-time check, no deploy-time check — so an
171
- // invented one ships. `AssemblyAIGatewayModel` is the id set this release
172
- // knows, and the union stays open so a model shipped after it still
173
- // compiles.
164
+ // first session, so an invented one ships. `AssemblyAIGatewayModel`
165
+ // autocompletes the ids this release knows, and stays open so a model
166
+ // shipped after it still compiles.
174
167
  const model: AssemblyAIGatewayModel = "claude-sonnet-4-6";
175
168
  // On a voice line, time-to-first-token IS the quality: the measured cost of
176
169
  // leaving a reasoning model on its server-side default was 1786ms p50
177
170
  // against 999ms with reasoning off.
178
171
  const reasoningEffort: AssemblyAIReasoningEffort = "none";
179
- expect(assemblyAILlm({ model, reasoningEffort }).options).toMatchObject({
172
+ const providerOptions: AssemblyAILlmProviderOptions = { reasoningEffort };
173
+ expect(llm({ provider: "assemblyai", model, providerOptions }).options).toMatchObject({
180
174
  model,
181
- reasoningEffort,
175
+ providerOptions: { reasoningEffort },
182
176
  });
183
177
  });
184
178
  });
@@ -186,33 +180,31 @@ describe("the LLM stage: nine vendors, one field", () => {
186
180
  describe("EU residency: a shorthand, and the URL it is short for", () => {
187
181
  test("`region` sets STT and the LLM gateway; TTS has a single endpoint", () => {
188
182
  expect(assemblyAIStt({ region: "eu" }).options.region).toBe("eu");
189
- expect(assemblyAILlm({ region: "eu" }).options.region).toBe("eu");
183
+ const stage = llm({
184
+ provider: "assemblyai",
185
+ model: "claude-sonnet-4-6",
186
+ providerOptions: { region: "eu" },
187
+ });
188
+ expect(stage.options.providerOptions).toEqual({ region: "eu" });
190
189
  });
191
190
 
192
191
  test("an explicit endpoint is the long form, and it WINS over `region`", () => {
193
192
  // Naming a URL is deliberate, so the residency shorthand must not silently
194
- // overwrite it. Both endpoints are published so the long form is a constant
195
- // rather than a string an author retypes — and an EU agent must also pick a
196
- // model the EU gateway carries (Claude and most Gemini ids), which is the
197
- // half a bare `region: "eu"` cannot do for you.
193
+ // overwrite it — and an EU agent must also pick a model the EU gateway
194
+ // carries (Claude and most Gemini ids), which is the half a bare
195
+ // `region: "eu"` cannot do for you.
198
196
  const stt = assemblyAIStt({
199
197
  streamingUrl: ASSEMBLYAI_STT_EU_URL,
200
198
  } satisfies AssemblyAISttOptions);
201
- const llm = assemblyAILlm({
202
- gatewayUrl: ASSEMBLYAI_LLM_GATEWAY_EU_URL,
199
+ const stage = llm({
200
+ provider: "assemblyai",
203
201
  model: "claude-sonnet-4-6",
202
+ baseUrl: "https://llm-gateway.eu.assemblyai.com/v1",
204
203
  });
205
204
  expect(stt.options.streamingUrl).toBe(ASSEMBLYAI_STT_EU_URL);
206
- expect(llm.options.gatewayUrl).toBe(ASSEMBLYAI_LLM_GATEWAY_EU_URL);
207
- // The US gateway is published for the same reason: a tool body calling the
208
- // same endpoint directly should not retype it. Both are OpenAI-compatible
209
- // bases and carry the version path, so they drop into an OpenAI client as
210
- // they are; `OPENROUTER_BASE_URL` is the third of that shape. The streaming
211
- // one is a WebSocket URL and carries its own versioned path.
212
- for (const url of [ASSEMBLYAI_LLM_GATEWAY_URL, OPENROUTER_BASE_URL]) {
213
- expect(new URL(url).protocol).toBe("https:");
214
- expect(url.endsWith("/v1"), url).toBe(true);
215
- }
205
+ // An OpenAI-compatible base carries the version path; the client appends
206
+ // `/chat/completions`. The streaming one is a WebSocket URL.
207
+ expect(stage.options.baseUrl?.toString().endsWith("/v1")).toBe(true);
216
208
  expect(new URL(ASSEMBLYAI_STT_EU_URL).protocol).toBe("wss:");
217
209
  });
218
210
  });
@@ -14,7 +14,7 @@
14
14
  * this file SHIPS — it is what a scaffolded project runs.
15
15
  */
16
16
  import dispatchAgent from "virtual:aai/agent";
17
- import type { SessionEvent } from "@alexkroman1/aai/protocol";
17
+ import type { SessionEvent } from "@alexkroman1/aai";
18
18
  // An EVAL: does the desk actually behave? Run it with `aai eval`.
19
19
  //
20
20
  // `agent.test.ts` drives each tool directly. What it cannot ask is whether the
@@ -27,7 +27,7 @@
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,
@@ -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,10 +35,12 @@ const run = toolRunner(agentDef);
35
35
  const desk = () =>
36
36
  scriptedToolContext({
37
37
  generate: {
38
- [TRIAGE_SYSTEM]: { object: { logic: "scripted", response: "email" } },
39
- [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: [] } },
38
+ routes: {
39
+ [TRIAGE_SYSTEM]: { object: { logic: "scripted", response: "email" } },
40
+ [CHOOSE_MEMORY_SYSTEM]: { object: { memoryTypesToUpdate: [] } },
41
+ },
40
42
  },
41
- delegate: { "meeting-assistant": "Maya is free Wednesday 1pm-3pm." },
43
+ delegate: { routes: { "meeting-assistant": "Maya is free Wednesday 1pm-3pm." } },
42
44
  });
43
45
 
44
46
  const openM4 = async () => {
@@ -109,11 +111,15 @@ describe("the meeting assistant's calendar tool", () => {
109
111
 
110
112
  test("a report the guardrail never accepted comes back marked unusable", async () => {
111
113
  const { ctx } = scriptedToolContext({
112
- generate: { [TRIAGE_SYSTEM]: { object: { logic: "scripted", response: "email" } } },
114
+ generate: {
115
+ routes: { [TRIAGE_SYSTEM]: { object: { logic: "scripted", response: "email" } } },
116
+ },
113
117
  delegate: {
114
- "meeting-assistant": {
115
- text: "I looked at her calendar.",
116
- complaint: "Name the open slots as clock times.",
118
+ routes: {
119
+ "meeting-assistant": {
120
+ text: "I looked at her calendar.",
121
+ complaint: "Name the open slots as clock times.",
122
+ },
117
123
  },
118
124
  },
119
125
  });
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  import {
22
- DEFAULT_GUARDRAIL_MAX_RETRIES,
22
+ DEFAULT_GUARDRAIL_MAX_REVISIONS,
23
23
  type DelegateFn,
24
24
  type GuardrailVerdict,
25
25
  isoDate,
@@ -114,7 +114,7 @@ export const meetingAssistant = subagent({
114
114
  // Stated rather than left to the default, because the guardrail is what makes
115
115
  // a retry possible and a retry is another whole run: the executive is on the
116
116
  // phone, and what they wait through is `MAX_MEETING_STEPS` lookups twice over.
117
- maxRetries: DEFAULT_GUARDRAIL_MAX_RETRIES,
117
+ maxRevisions: DEFAULT_GUARDRAIL_MAX_REVISIONS,
118
118
  });
119
119
 
120
120
  /**
@@ -0,0 +1,174 @@
1
+ /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
2
+ import agentDef from "virtual:aai/agent";
3
+ // An EVAL: does the front desk actually hand the caller to the right desk, and
4
+ // does the desk it lands on act as itself?
5
+ //
6
+ // `agent.test.ts` drives the tools directly, which settles what each one does.
7
+ // What no test in it can settle is whether the MODEL verifies before it looks
8
+ // up an invoice, hands a "my line is down" caller to support without a script,
9
+ // and — the claim personas exist for — whether the desk the caller lands on is
10
+ // still speaking on the NEXT turn, over the slot the first desk wrote.
11
+ //
12
+ // Run it with `aai eval`. Without a provider key every case runs against a
13
+ // SCRIPTED model (its `stubReply`), which still boots this agent, still gates
14
+ // every tool on the active persona, and still executes the tool a script names
15
+ // — so a stub run proves the wiring and proves nothing about what the agent chose.
16
+ import { HANDOFF_TOOL_NAME } from "@alexkroman1/aai";
17
+ import { toolNames, toolResultIn } from "@alexkroman1/aai-runtime/eval";
18
+ import { evalSimulation } from "@alexkroman1/aai-runtime/eval/simulate";
19
+ import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
20
+ import { expect } from "vitest";
21
+ import { z } from "zod";
22
+
23
+ const Handoff = z.object({ handoff: z.literal(true), from: z.string(), to: z.string() });
24
+ const Refusal = z.object({ error: z.string() });
25
+ const Invoices = z.object({
26
+ invoices: z.array(z.object({ id: z.string(), amount: z.number(), status: z.string() })),
27
+ });
28
+
29
+ describeEval(agentDef, (test) => {
30
+ test(
31
+ "verifies the caller and hands them to billing in one call",
32
+ async ({ session }) => {
33
+ const turn = await session.say(
34
+ "Hi, my account number is 1001 and my zip is 94107. I have a question about my last bill.",
35
+ );
36
+ expect(toolNames(turn.toolCalls)).toEqual(["verify_account"]);
37
+ const handed = toolResultIn(turn.toolCalls, "verify_account", Handoff);
38
+ expect(handed).toMatchObject({ from: "triage", to: "billing" });
39
+ expect(turn.completed).toBe(true);
40
+ },
41
+ {
42
+ stubReply: [
43
+ { tool: "verify_account", args: { accountNumber: "1001", zip: "94107", needs: "billing" } },
44
+ "Thanks Dana, you're verified — this is billing. Which invoice is it about?",
45
+ ],
46
+ },
47
+ );
48
+
49
+ test(
50
+ "does not open an invoice for an unverified caller — the desk's own tool refuses",
51
+ async ({ session }) => {
52
+ const turn = await session.say("Can you look up my latest invoice?");
53
+ // Whatever the model chose, no invoice may have been READ: an invoice
54
+ // lookup before verification is exactly what the gate exists to stop, and
55
+ // a lookup attempted here is refused because billing is not speaking.
56
+ for (const call of turn.toolCalls.filter((c) => c.name === "lookup_invoice")) {
57
+ expect(toolResultIn([call], call.name, Refusal).error).toContain("billing persona");
58
+ }
59
+ expect(turn.completed).toBe(true);
60
+ },
61
+ {
62
+ stubReply: [
63
+ { tool: "lookup_invoice", args: {} },
64
+ "Before I can do that I'll need your account number and zip code.",
65
+ ],
66
+ },
67
+ );
68
+
69
+ test(
70
+ "routes a service problem to support on the caller's words alone",
71
+ async ({ session }) => {
72
+ const turn = await session.say(
73
+ "I don't have a billing question, my internet has been down since this morning.",
74
+ );
75
+ expect(toolNames(turn.toolCalls)).toContain(HANDOFF_TOOL_NAME);
76
+ expect(toolResultIn(turn.toolCalls, HANDOFF_TOOL_NAME, Handoff)).toMatchObject({
77
+ from: "triage",
78
+ to: "support",
79
+ });
80
+ },
81
+ {
82
+ stubReply: [
83
+ {
84
+ tool: HANDOFF_TOOL_NAME,
85
+ args: { persona: "support", note: "Internet down since morning." },
86
+ },
87
+ "I'm sorry to hear that — this is support. Let me check your line.",
88
+ ],
89
+ },
90
+ );
91
+
92
+ test(
93
+ "the desk the caller landed on is still speaking on the next turn",
94
+ async ({ session }) => {
95
+ await session.say("Account 1001, zip 94107, it's about a bill.");
96
+ // Turn 2 names no desk and re-verifies nothing: billing's tool runs only
97
+ // because the handoff turn 1 made is the session's, not the turn's.
98
+ const turn = await session.say("What's on invoice INV-1001-2?");
99
+ expect(toolNames(turn.toolCalls)).toEqual(["lookup_invoice"]);
100
+ expect(toolResultIn(turn.toolCalls, "lookup_invoice", Invoices).invoices).toEqual([
101
+ { id: "INV-1001-2", amount: 79.5, status: "open" },
102
+ ]);
103
+ },
104
+ {
105
+ stubReply: [
106
+ { tool: "verify_account", args: { accountNumber: "1001", zip: "94107", needs: "billing" } },
107
+ "You're verified, Dana. Which invoice?",
108
+ { tool: "lookup_invoice", args: { invoiceId: "INV-1001-2" } },
109
+ "Invoice one-oh-oh-one dash two is seventy-nine fifty, and it's still open.",
110
+ ],
111
+ },
112
+ );
113
+
114
+ test(
115
+ "a simulated caller who volunteers nothing still gets verified and hears their bill",
116
+ async ({ session, mode }) => {
117
+ // The cases above hand the desk the account number and zip in the
118
+ // caller's first breath, because a scripted line has to. A real caller
119
+ // opens with the question and gives the numbers only when asked, which is
120
+ // the order that tests whether the desk ASKS rather than whether it can
121
+ // parse. A second model plays that caller. Keyless, it and the judge are
122
+ // scripted, and the case proves the loop is wired and nothing else.
123
+ const { simulate, judge } = evalSimulation({
124
+ agent: agentDef,
125
+ mode,
126
+ target: session,
127
+ stubCaller: [
128
+ "Hi, I have a question about the invoice that's still open on my bill.",
129
+ "Sure, account number 1001, zip code 94107.",
130
+ "How much is the open one?",
131
+ { tool: "end_call", args: { reason: "heard the amount" } },
132
+ ],
133
+ });
134
+ const call = await simulate({
135
+ persona:
136
+ "Dana, a Northwind customer on the phone, who gives the account number 1001 and the " +
137
+ "zip code 94107 only when the agent asks for them",
138
+ goal: "find out how much the invoice that is still open on the account is for",
139
+ });
140
+
141
+ expect(call.endedBy, call.transcript()).toBe("caller");
142
+ // Deterministic first: an invoice was really READ. `lookup_invoice` is
143
+ // billing's tool and refuses anyone unverified, so a successful read is
144
+ // proof the verification happened, whatever order the model tried things
145
+ // in — and a refused attempt along the way is the gate working.
146
+ const reads = call.metrics.toolCalls
147
+ .filter((c) => c.name === "lookup_invoice")
148
+ .map((c) => toolResultIn([c], c.name, Invoices.or(Refusal)))
149
+ .flatMap((result) => ("invoices" in result ? result.invoices : []));
150
+ expect(reads, call.transcript()).toContainEqual({
151
+ id: "INV-1001-2",
152
+ amount: 79.5,
153
+ status: "open",
154
+ });
155
+
156
+ // What the tool results cannot show is the order the caller HEARD things
157
+ // in, and whether the figure reached them in words.
158
+ const verdict = await judge(call, [
159
+ "The agent asked for the account number and zip code before giving any invoice details.",
160
+ "The agent told the caller the open invoice is for $79.50.",
161
+ ]);
162
+ expect(verdict.pass, verdict.explain()).toBe(true);
163
+ },
164
+ {
165
+ stubReply: [
166
+ "I can help with that. What's your account number and zip code?",
167
+ { tool: "verify_account", args: { accountNumber: "1001", zip: "94107", needs: "billing" } },
168
+ "Thanks Dana, you're verified — this is billing. What would you like to know?",
169
+ { tool: "lookup_invoice", args: {} },
170
+ "Your open invoice, INV-1001-2, is for seventy-nine fifty.",
171
+ ],
172
+ },
173
+ );
174
+ });