@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
@@ -42,6 +42,7 @@ The fast loop: edit → `pnpm dev` (browser, talk to it) →
42
42
  Cases live in `agent.eval.test.ts` (the `quickstart-agent` template ships one):
43
43
 
44
44
  ```ts no-check
45
+ import { expectCalled } from "@alexkroman1/aai-runtime/eval";
45
46
  import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
46
47
  import { expect } from "vitest";
47
48
  import agentDef from "./agent.ts";
@@ -52,7 +53,7 @@ The fast loop: edit → `pnpm dev` (browser, talk to it) →
52
53
  async ({ session }) => {
53
54
  // `say()` returns THAT turn — the reply, its tool calls, its events.
54
55
  const turn = await session.say("where is order W1234?");
55
- expect(turn.toolCalls.map((c) => c.name)).toContain("look_up");
56
+ expectCalled(turn, "look_up");
56
57
  expect(turn.text).toMatch(/shipped/i);
57
58
  },
58
59
  // What a SCRIPTED model answers with when there is no key (below).
@@ -329,9 +330,12 @@ export default agent({
329
330
  silencePrompt?: string; // instruction injected on silence timeout (requires silenceTimeoutMs)
330
331
  minBargeInWords?: number; // pipeline only — words before user speech interrupts the reply (default 2)
331
332
  interruptionMinDurationMs?: number; // pipeline only — sustained speech (ms) before an interim barge-in interrupts (default 500; 0 disables)
332
- deadAirCoverMs?: number; // pipeline only — speak a short filler after this much silence in a turn (default 5000; 0 disables)
333
+ deadAirCoverMs?: number; // pipeline only — speak a short filler after this much silence in a turn (default 2400; 0 disables)
333
334
  resumeFalseInterruption?: boolean; // pipeline only — resume an interrupted reply if no user turn commits (default true)
334
335
  preemptiveGeneration?: boolean; // pipeline only — start the reply from a high-confidence interim (default false; true opts in)
336
+ userTurnLimit?: { maxWords?: number; // pipeline only — cap ONE user turn: end it after this many words
337
+ maxDurationMs?: number };// and/or this long (ms). Default: no cap. Emits `user-turn.exceeded`.
338
+ turnDetection?: "auto" | "manual"; // pipeline only — "manual" is push-to-talk: the CLIENT ends each turn
335
339
  syncState?: StateProjection; // show a slot to the client: slot.projection(view)
336
340
  // (read it with useAgentState; see UI hooks)
337
341
  minTurnSilenceMs?: number; // pipeline only — pause (ms) that ENDS a user turn once the
@@ -345,7 +349,9 @@ export default agent({
345
349
  // missing key fails at `aai push` instead of mid-call.
346
350
  // Declare every key any tool or step reads.
347
351
  text?: true; // text-only agent: no STT, no TTS, `llm` is the one stage
348
- events?: SessionEventHandlers; // observe the session (see "Watching the session")
352
+ events?: SessionEventHandlers; // observe the session; "metrics.collected" is each
353
+ // reply's latency/tokens: createMetricsCollector()
354
+ personas?: Personas; // see "Personas"
349
355
  });
350
356
  ```
351
357
 
@@ -355,8 +361,8 @@ export default agent({
355
361
  > through the Vercel AI Gateway (`AI_GATEWAY_API_KEY`), a bare id through
356
362
  > the AssemblyAI LLM Gateway (`ASSEMBLYAI_API_KEY`).
357
363
 
358
- Minimal agent — a cascaded pipeline, which is what you should build unless
359
- the user asks for the speech-to-speech API:
364
+ Minimal agent — a cascaded pipeline, what to build unless the user asks
365
+ for speech-to-speech:
360
366
 
361
367
  ```ts
362
368
  import { agent } from "@alexkroman1/aai";
@@ -368,8 +374,7 @@ export default agent({
368
374
 
369
375
  No provider fields means the default all-AssemblyAI pipeline: all three
370
376
  stages bill to the one key a published agent is guaranteed to have. Pick
371
- its voice with the `voice` field — this is the normal way to choose a
372
- voice:
377
+ its voice with the `voice` field:
373
378
 
374
379
  ```ts
375
380
  import { agent } from "@alexkroman1/aai";
@@ -380,9 +385,8 @@ export default agent({
380
385
  });
381
386
  ```
382
387
 
383
- Swap a single stage by declaring just that field — everything you leave
384
- unset stays on the default. `llm` accepts the gateway model id as a plain
385
- string:
388
+ Swap one stage by declaring just that field; the rest stay default.
389
+ `llm` accepts the gateway model id as a plain string:
386
390
 
387
391
  ```ts
388
392
  import { agent } from "@alexkroman1/aai";
@@ -1334,13 +1338,13 @@ descriptor (the descriptor owns its own voice). A raw config that skips
1334
1338
  ```ts
1335
1339
  import { agent } from "@alexkroman1/aai";
1336
1340
  import { assemblyAIStt } from "@alexkroman1/aai/stt";
1337
- import { anthropicLlm } from "@alexkroman1/aai/llm";
1341
+ import { llm } from "@alexkroman1/aai/llm";
1338
1342
  import { cartesiaTts } from "@alexkroman1/aai/tts";
1339
1343
 
1340
1344
  export default agent({
1341
1345
  name: "My Agent",
1342
1346
  stt: assemblyAIStt({ model: "universal-3-5-pro" }),
1343
- llm: anthropicLlm({ model: "claude-haiku-4-5" }),
1347
+ llm: llm({ provider: "anthropic", model: "claude-haiku-4-5" }),
1344
1348
  tts: cartesiaTts(),
1345
1349
  });
1346
1350
  ```
@@ -1409,9 +1413,9 @@ assistant proactively take a turn after that much user silence (e.g.
1409
1413
  assistant stops nudging after 3 consecutive unanswered nudges until the
1410
1414
  user speaks again.
1411
1415
 
1412
- **Voice-UX tuning (pipeline only):** `minBargeInWords` controls how many
1413
- words of user speech interrupt the assistant mid-reply (default 2, so
1414
- one-word backchannels like "yeah" don't cut it off);
1416
+ **Voice-UX tuning (`PipelineVoiceTuning`, pipeline only):**
1417
+ `minBargeInWords` controls how many words of user speech interrupt the
1418
+ assistant mid-reply (default 2, so a one-word "yeah" doesn't cut it off);
1415
1419
  `interruptionMinDurationMs` adds a sustained-speech gate on top (default
1416
1420
  500 ms; `0` disables; interim transcripts only — committed turns always
1417
1421
  land). End-of-turn detection (how long a pause ends the user's turn)
@@ -1425,23 +1429,22 @@ promptly pays nothing; `0` disables it. The wording is not yours to set — the
1425
1429
  filler must be purely declarative and never a request for patience, or the
1426
1430
  caller answers it and the answer barges in.
1427
1431
  `resumeFalseInterruption` (default `true`) resumes an interrupted reply when
1428
- a barge-in turns out to be noise — no user turn ever commits. The wait is not
1429
- configurable: the resume fires once the transcript stream goes quiet with no
1430
- final, so it can never race a real turn the STT is still endpointing.
1431
- `preemptiveGeneration` (default **`false`**) starts generating the reply as
1432
- soon as transcription is confident the caller has finished, and uses that
1433
- already-running answer if the committed transcript matches. It can shorten the
1434
- pause before the agent speaks, and it is off by default because the measurement
1435
- came back negative: over a tau2-bench retail run, 16 speculations started, 14
1436
- were adopted at a p50 head start of 0.44s, and 5 of those 14 (36%) were poisoned
1437
- after adoption by a tool call — discarded whole, each having burned p50 0.69s
1438
- first. Net **+8ms per caller turn**, for 44% of its LLM requests thrown away.
1439
- What bounds the downside either way is that a speculation never speaks, calls a
1440
- tool, or enters history until the real turn adopts it, so the worst case is a
1441
- wasted request and a turn that behaves exactly as it would with the flag off.
1442
- Set `preemptiveGeneration: true` to opt in — worth trying on a text-heavy agent,
1443
- since 36% poisoned is a tool-calling agent's number, and pointless on a
1444
- tool-heavy one, where a speculation that reaches a tool call is thrown away.
1432
+ a barge-in turns out to be noise — no user turn ever commits. It fires once the
1433
+ transcript stream goes quiet with no final, so it never races a real turn.
1434
+ `userTurnLimit` (a `UserTurnLimit`; default: no cap) bounds ONE user turn —
1435
+ `{ maxWords }`, `{ maxDurationMs }`, or both. A caller who never pauses never
1436
+ ends a turn; past either cap the transcriber ends it as a pause would — what
1437
+ was heard commits,
1438
+ the rest opens the next turn. Each cut is a `user-turn.exceeded` event
1439
+ (`limit`, `words`, `durationMs`); `{}` is refused. Inert (logged once) on a
1440
+ transcriber that cannot end a turn on demand; the default `assemblyAIStt()` can.
1441
+ `turnDetection: "manual"` is PUSH-TO-TALK (`usePushToTalk()` in `aai-ui`):
1442
+ the mic is heard only while held, all of it is ONE turn answered on release,
1443
+ and pressing is the barge-in.
1444
+ `preemptiveGeneration` (default **`false`**) starts the reply from a confident
1445
+ interim and adopts it if the committed transcript matches. Off because it
1446
+ measured net **+8ms per turn**, 44% of requests thrown away; a speculation never
1447
+ speaks or calls a tool until adopted.
1445
1448
 
1446
1449
  ## Providers
1447
1450
 
@@ -1474,41 +1477,41 @@ API keys require it; the US endpoints reject them. Example:
1474
1477
 
1475
1478
  ### LLM — `@alexkroman1/aai/llm`
1476
1479
 
1477
- | Factory | SDK package | Env var |
1478
- | --------------- | ------------------- | ------------------------------ |
1479
- | `anthropicLlm` | `@ai-sdk/anthropic` | `ANTHROPIC_API_KEY` |
1480
- | `openAILlm` | `@ai-sdk/openai` | `OPENAI_API_KEY` |
1481
- | `googleLlm` | `@ai-sdk/google` | `GOOGLE_GENERATIVE_AI_API_KEY` |
1482
- | `mistralLlm` | `@ai-sdk/mistral` | `MISTRAL_API_KEY` |
1483
- | `xAILlm` | `@ai-sdk/xai` | `XAI_API_KEY` |
1484
- | `groqLlm` | `@ai-sdk/groq` | `GROQ_API_KEY` |
1485
- | `openRouterLlm` | `@ai-sdk/openai` | `OPENROUTER_API_KEY` |
1486
- | `gatewayLlm` | `ai` (built in) | `AI_GATEWAY_API_KEY` |
1487
- | `assemblyAILlm` | `@ai-sdk/openai` | `ASSEMBLYAI_API_KEY` |
1488
-
1489
- LLM factories require `{ model: string }` — the `ModelOptions` interface,
1490
- shared by all of them except `assemblyAILlm`. Example:
1491
- `anthropicLlm({ model: "claude-haiku-4-5" })`. The argument is required
1492
- because a third-party vendor's catalog is not this SDK's to default from;
1493
- `assemblyAILlm()` is the one bare call, since it has a default model.
1494
-
1495
- `openRouterLlm` routes through [OpenRouter](https://openrouter.ai) — an
1496
- OpenAI-compatible endpoint fronting hundreds of models addressed as
1497
- `"creator/model"`, e.g.
1498
- `openRouterLlm({ model: "meta-llama/llama-3.3-70b-instruct" })`. It needs
1499
- no extra SDK install (it reuses the `@ai-sdk/openai` client).
1500
-
1501
- `gatewayLlm` routes through the [Vercel AI
1502
- Gateway](https://vercel.com/docs/ai-gateway) — one endpoint fronting
1503
- hundreds of models addressed as `"creator/model"`, e.g.
1504
- `gatewayLlm({ model: "zai/glm-4.6" })`. It needs no extra SDK install
1505
- (the gateway client ships inside the `ai` package).
1506
-
1507
- `assemblyAILlm` routes through the [AssemblyAI LLM
1480
+ ONE factory, `llm({ provider, model, baseUrl?, apiKeyEnv?, providerOptions? })`.
1481
+ The provider is a string, not a function name:
1482
+
1483
+ | `provider` | SDK package | Env var |
1484
+ | -------------- | ------------------- | ------------------------------ |
1485
+ | `"anthropic"` | `@ai-sdk/anthropic` | `ANTHROPIC_API_KEY` |
1486
+ | `"openai"` | `@ai-sdk/openai` | `OPENAI_API_KEY` |
1487
+ | `"google"` | `@ai-sdk/google` | `GOOGLE_GENERATIVE_AI_API_KEY` |
1488
+ | `"mistral"` | `@ai-sdk/mistral` | `MISTRAL_API_KEY` |
1489
+ | `"xai"` | `@ai-sdk/xai` | `XAI_API_KEY` |
1490
+ | `"groq"` | `@ai-sdk/groq` | `GROQ_API_KEY` |
1491
+ | `"cerebras"` | `@ai-sdk/openai` | `CEREBRAS_API_KEY` |
1492
+ | `"openrouter"` | `@ai-sdk/openai` | `OPENROUTER_API_KEY` |
1493
+ | `"gateway"` | `ai` (built in) | `AI_GATEWAY_API_KEY` |
1494
+ | `"assemblyai"` | `@ai-sdk/openai` | `ASSEMBLYAI_API_KEY` |
1495
+
1496
+ `model` is required. Example:
1497
+ `llm({ provider: "anthropic", model: "claude-haiku-4-5" })`.
1498
+ `"openrouter"` and `"gateway"` (the [Vercel AI
1499
+ Gateway](https://vercel.com/docs/ai-gateway)) address a model as
1500
+ `"creator/model"`; every other provider takes its own bare id.
1501
+
1502
+ `provider` is OPEN: any other string compiles. A provider with no built-in
1503
+ entry is reached as an OpenAI-compatible endpoint by naming its `baseUrl` (and
1504
+ `apiKeyEnv`, the variable its key is in); `aai build` warns about an unknown
1505
+ provider that has neither. `providerOptions` carries provider-specific
1506
+ settings: a native client's AI SDK `providerOptions`; on `openrouter`,
1507
+ `cerebras` or a `baseUrl` provider, raw request-body fields (`top_k`).
1508
+
1509
+ `"assemblyai"` routes through the [AssemblyAI LLM
1508
1510
  Gateway](https://www.assemblyai.com/docs/llm-gateway) — an
1509
1511
  OpenAI-compatible endpoint fronting 25+ models (Claude, GPT, Gemini,
1510
1512
  etc.) with the same API key as AssemblyAI STT. A bare model-id string on
1511
- `llm` is shorthand for it, and unset stages keep the AssemblyAI default:
1513
+ `llm` is shorthand for it (and a `"creator/model"` string for `"gateway"`), and
1514
+ unset stages keep the AssemblyAI default:
1512
1515
 
1513
1516
  ```ts
1514
1517
  import { agent } from "@alexkroman1/aai";
@@ -1519,8 +1522,9 @@ export default agent({
1519
1522
  });
1520
1523
  ```
1521
1524
 
1522
- `assemblyAILlm({ model, region: "eu" })` is the explicit form; `region`
1523
- selects EU data residency.
1525
+ `llm({ provider: "assemblyai", model, providerOptions: { region: "eu" } })` is
1526
+ the explicit form; `region` selects EU data residency, and `reasoningEffort`
1527
+ beside it sets the model's reasoning effort.
1524
1528
 
1525
1529
  Mixing providers works the same way — declare the stages you're changing:
1526
1530
 
@@ -1809,7 +1813,7 @@ an SDK dependency. `technical-support-agent` is the worked example.
1809
1813
 
1810
1814
  `ctx.generate` is ONE prompt. When answering takes an unknown number of tool
1811
1815
  calls whose intermediate results the conversation has no reason to carry,
1812
- delegate to a **subagent** instead: a second tool loop with its own system
1816
+ delegate to a **subagent**: a second tool loop with its own system
1813
1817
  prompt, model, tools and — the whole point — its own context window.
1814
1818
 
1815
1819
  ```ts
@@ -1818,11 +1822,8 @@ import { z } from "zod";
1818
1822
 
1819
1823
  const researcher = subagent({
1820
1824
  name: "researcher",
1821
- // `systemPrompt`, the same field name `agent()` uses — a subagent is a
1822
- // field-for-field smaller agent, so nothing about it is spelled differently.
1823
- systemPrompt:
1824
- "Research the task with the tools you have. IMPORTANT: your final message " +
1825
- "is the only thing the caller sees — end with a self-contained summary.",
1825
+ systemPrompt: "Research the task with the tools you have.",
1826
+ expectedOutput: "A self-contained summary — the only thing the caller sees.",
1826
1827
  builtinTools: ["web_search", "visit_webpage"],
1827
1828
  maxSteps: 6,
1828
1829
  });
@@ -1837,37 +1838,45 @@ export default tool({
1837
1838
  });
1838
1839
  ```
1839
1840
 
1840
- Four rules, each of which is how a subagent disappoints when you skip it:
1841
+ Four rules, each the way a subagent disappoints when skipped: you receive its
1842
+ FINAL message, so declare `expectedOutput`; its context is isolated, so `task`
1843
+ must be a complete brief; `maxSteps` bounds the loop, and a capped run is asked
1844
+ for its answer with tools withheld; and say you are looking it up before you
1845
+ call. A subagent may name its own `llm` and its own `tools` map; **delegation is
1846
+ one level deep**. In tests, `stubDelegate` (`@alexkroman1/aai/testing`) fakes it
1847
+ by subagent name.
1841
1848
 
1842
- - **Tell it to summarize.** You receive its FINAL message. A subagent that
1843
- signs off with "Done." has thrown away everything it read.
1844
- - **Write the task as a complete brief.** Its context is isolated — it has not
1845
- heard the conversation. Anything it needs from the call goes in `task`, or in
1846
- the optional `context` string.
1847
- - **Give it a budget.** `maxSteps` (default: the framework's) bounds the loop;
1848
- past it the subagent is asked for its answer with its tools withheld, so a
1849
- capped run still answers. In a voice session the tool timeout bounds the
1850
- whole thing, so keep it small.
1851
- - **Say you are looking it up before you call.** A delegated run takes a
1852
- moment, and a silent line is the worst thing on a phone call.
1849
+ ### Personas and `handoff` (`personas()`)
1853
1850
 
1854
- Runs are ordinary promises, so several fan out at once — this is the other
1855
- reason to reach for a subagent:
1851
+ When the SPEAKER has to change — triage verifies the caller, billing takes over
1852
+ with its own instructions and tools, one history — declare a roster of
1853
+ **personas**; the first entry answers the call.
1856
1854
 
1857
- ```ts no-check
1858
- const runs = await Promise.allSettled(
1859
- angles.map((angle) => ctx.delegate(researcher, { task: angle })),
1860
- );
1861
- ```
1855
+ ```ts
1856
+ import { agent, persona, personas } from "@alexkroman1/aai";
1862
1857
 
1863
- A subagent may name its own `llm` (a cheaper model for a narrower job) and its
1864
- own `tools` — an explicit map of `tool()` values, which is how you give one
1865
- run a strictly smaller surface than the agent has. **Delegation is one level
1866
- deep**: a subagent's own tools get a `ctx.delegate` that refuses.
1858
+ const triage = persona({
1859
+ name: "triage",
1860
+ description: "Answers the phone and picks the desk",
1861
+ systemPrompt: "Bill or fault? Find out, then hand off.",
1862
+ });
1863
+ const billing = persona({
1864
+ name: "billing",
1865
+ description: "Invoices, payments and refunds",
1866
+ systemPrompt: "You are the billing desk.",
1867
+ });
1868
+ export const desk = personas([triage, billing]);
1869
+
1870
+ export default agent({ name: "Front Desk", personas: desk });
1871
+ ```
1867
1872
 
1868
- In tests, `stubDelegate` from `@alexkroman1/aai/testing` fakes the capability,
1869
- routed by subagent name; `createToolContext()` defaults `delegate` to a
1870
- rejection so an unstubbed run cannot reach a real model.
1873
+ The roster mints one `handoff` tool the model routes with, described by each
1874
+ persona's `description`. A tool body hands off in code with
1875
+ `desk.handoff(ctx, billing, { note })` and returns the result; the same turn
1876
+ continues as the new persona. A persona's `tools` (a map) refuse at
1877
+ execution while another persona speaks, naming who is and how to hand off.
1878
+ `tools/` and `system-prompt.md` hold under every persona; a dialog state pins one
1879
+ with `persona`. Example: `front-desk-agent`.
1871
1880
 
1872
1881
  ### A tool that calls an API
1873
1882
 
@@ -2007,10 +2016,9 @@ the tool simply never reached the model.
2007
2016
 
2008
2017
  ## Built-in tools
2009
2018
 
2010
- Enable via `builtinTools` in `agent()`. **When `builtinTools` is omitted, none
2011
- are enabled** — omitting the field and passing `[]` mean the same thing. Name
2012
- the ones you want; a built-in is something an agent asks for rather than
2013
- something it has to notice and switch off.
2019
+ Enable via `builtinTools` in `agent()`. **Omitted, only `think` is on**; the
2020
+ rest are opt-in. Setting the field REPLACES the default: list `"think"` to keep
2021
+ it, `[]` for none.
2014
2022
 
2015
2023
  | Tool | Description | Params |
2016
2024
  | --- | --- | --- |
@@ -15,10 +15,10 @@
15
15
  "publish:agent": "aai publish"
16
16
  },
17
17
  "dependencies": {
18
- "@alexkroman1/aai": "^17.0.0",
19
- "@alexkroman1/aai-cli": "^17.0.0",
20
- "@alexkroman1/aai-runtime": "^17.0.0",
21
- "@alexkroman1/aai-ui": "^17.0.0",
18
+ "@alexkroman1/aai": "^18.0.0",
19
+ "@alexkroman1/aai-cli": "^18.0.0",
20
+ "@alexkroman1/aai-runtime": "^18.0.0",
21
+ "@alexkroman1/aai-ui": "^18.0.0",
22
22
  "react": "^19.2.8",
23
23
  "react-dom": "^19.2.8",
24
24
  "tailwindcss": "^4.0.0",
package/dist/start.d.ts CHANGED
@@ -46,7 +46,7 @@ export { CLIENT_ARTIFACT_REL } from "./_artifacts.ts";
46
46
  /** The port `aai start` binds when neither an argument nor `PORT` says otherwise. */
47
47
  export declare const DEFAULT_START_PORT = 3000;
48
48
  /** Options for {@link createProjectServer} and {@link executeStart}. */
49
- export interface StartOptions {
49
+ export interface ProjectServerOptions {
50
50
  /** Project root — the directory holding `agent.ts` and `.aai/`. */
51
51
  cwd: string;
52
52
  /** Port to bind. Defaults to `PORT`, then {@link DEFAULT_START_PORT}. */
@@ -91,7 +91,7 @@ export declare function loadBuiltAgent(cwd: string): Promise<AgentDef>;
91
91
  * }
92
92
  * ```
93
93
  */
94
- export declare function createProjectServer(options: StartOptions): Promise<AgentServer>;
94
+ export declare function createProjectServer(options: ProjectServerOptions): Promise<AgentServer>;
95
95
  /** What {@link executeStart} answers, for `--json` and for tests. */
96
96
  export interface StartResult {
97
97
  ok: true;
@@ -109,4 +109,4 @@ export interface StartResult {
109
109
  * rejected would surface as an unhandled rejection, i.e. a crash with a stack
110
110
  * trace on Ctrl-C, instead of the non-zero exit a failed shutdown should be.
111
111
  */
112
- export declare function executeStart(options: StartOptions): Promise<StartResult>;
112
+ export declare function executeStart(options: ProjectServerOptions): Promise<StartResult>;
@@ -5,7 +5,7 @@ import { l as formatCappedList } from "./_utils-D5JGcjiW.mjs";
5
5
  import { s as updateProjectConfig } from "./_config-DYzC6WMD.mjs";
6
6
  import { i as resolveServerEnv } from "./_server-common-DAcv1nC5.mjs";
7
7
  import { o as resolveDeployTarget } from "./_agent-BzUeqOdj.mjs";
8
- import { layerScaffold } from "./_templates-IMeKMVIj.mjs";
8
+ import { layerScaffold } from "./_templates-DXadVNsL.mjs";
9
9
  import { a as publishStudioProject, c as studioProjectUrl, f as checkedResponse, i as projectNameFromDir, n as fetchStudioProject, o as pushStudioSource, r as listStudioProjects, s as studioProjectApiUrl, t as collectSourceFiles, u as apiRequest } from "./_studio-DnR_BqFp.mjs";
10
10
  import { existsSync } from "node:fs";
11
11
  import path from "node:path";
@@ -23,7 +23,7 @@ import {
23
23
  crewAgentPrompt,
24
24
  crewExpectedOutput,
25
25
  EMAIL_FOLLOWUP_AGENT,
26
- EMAIL_GUARDRAIL_RETRIES,
26
+ EMAIL_GUARDRAIL_REVISIONS,
27
27
  EVALUATOR_SYSTEM,
28
28
  emailGuardrail,
29
29
  emailTask,
@@ -125,19 +125,23 @@ interface Script {
125
125
  function scriptedDesk(script: Script = {}) {
126
126
  const scripted = scriptedToolContext({
127
127
  generate: {
128
- [EVALUATOR_SYSTEM]: (call: StubGenerateCall) => {
129
- const id = candidateIdIn(call.prompt);
130
- if (script.failScoring?.includes(id)) throw new Error(`gateway said no for ${id}`);
131
- const table = script.scores ?? SCORES;
132
- return { object: { score: table[id] ?? 50, reason: `Scripted reasoning for ${id}.` } };
128
+ routes: {
129
+ [EVALUATOR_SYSTEM]: (call: StubGenerateCall) => {
130
+ const id = candidateIdIn(call.prompt);
131
+ if (script.failScoring?.includes(id)) throw new Error(`gateway said no for ${id}`);
132
+ const table = script.scores ?? SCORES;
133
+ return { object: { score: table[id] ?? 50, reason: `Scripted reasoning for ${id}.` } };
134
+ },
133
135
  },
134
136
  },
135
137
  delegate: {
136
- "hr-coordinator": (call) => {
137
- const name = call.task.match(/^Name: (.+)$/m)?.[1] ?? "";
138
- if (script.failEmail?.includes(name)) throw new Error(`coordinator timed out on ${name}`);
139
- const reply = script.email ? script.email(call) : emailFor(call);
140
- return typeof reply === "string" ? { text: reply } : reply;
138
+ routes: {
139
+ "hr-coordinator": (call) => {
140
+ const name = call.task.match(/^Name: (.+)$/m)?.[1] ?? "";
141
+ if (script.failEmail?.includes(name)) throw new Error(`coordinator timed out on ${name}`);
142
+ const reply = script.email ? script.email(call) : emailFor(call);
143
+ return typeof reply === "string" ? { text: reply } : reply;
144
+ },
141
145
  },
142
146
  },
143
147
  });
@@ -900,8 +904,8 @@ describe("the crews", () => {
900
904
  // declaration. Pinned to the NUMBER as well as to the constant, so an SDK
901
905
  // default that moved is a decision this template makes again rather than
902
906
  // one it inherits.
903
- expect(emailWriter.maxRetries).toBe(EMAIL_GUARDRAIL_RETRIES);
904
- expect(EMAIL_GUARDRAIL_RETRIES).toBe(1);
907
+ expect(emailWriter.maxRevisions).toBe(EMAIL_GUARDRAIL_REVISIONS);
908
+ expect(EMAIL_GUARDRAIL_REVISIONS).toBe(1);
905
909
  });
906
910
 
907
911
  test("the guardrail accepts a subject line and a signature, and names what is missing", () => {
@@ -51,7 +51,7 @@
51
51
  */
52
52
 
53
53
  import {
54
- DEFAULT_GUARDRAIL_MAX_RETRIES,
54
+ DEFAULT_GUARDRAIL_MAX_REVISIONS,
55
55
  type DelegateFn,
56
56
  type DelegateResult,
57
57
  type GenerateFn,
@@ -311,7 +311,7 @@ export const emailGuardrail: SubagentGuardrail = ({ text }) => {
311
311
  * What a complaint buys the coordinator: one more run, and no more.
312
312
  *
313
313
  * CrewAI's task `guardrail` retries three times; the SDK's default is
314
- * {@link DEFAULT_GUARDRAIL_MAX_RETRIES}, which is one, and one is the right
314
+ * {@link DEFAULT_GUARDRAIL_MAX_REVISIONS}, which is one, and one is the right
315
315
  * budget on a phone. A retry is another run of the coordinator inside a
316
316
  * twelve-email fan-out the caller is holding the line through, and the two
317
317
  * things this guardrail checks — a subject line, a signature — are ones a model
@@ -322,7 +322,7 @@ export const emailGuardrail: SubagentGuardrail = ({ text }) => {
322
322
  * Written out rather than inherited, because a retry budget nobody can see at
323
323
  * the declaration is a budget nobody decided.
324
324
  */
325
- export const EMAIL_GUARDRAIL_RETRIES = DEFAULT_GUARDRAIL_MAX_RETRIES;
325
+ export const EMAIL_GUARDRAIL_REVISIONS = DEFAULT_GUARDRAIL_MAX_REVISIONS;
326
326
 
327
327
  /**
328
328
  * Their `LeadResponseCrew`: `email_followup_agent` running
@@ -337,7 +337,7 @@ export const emailWriter = subagent({
337
337
  systemPrompt: crewAgentPrompt(EMAIL_FOLLOWUP_AGENT),
338
338
  expectedOutput: EMAIL_EXPECTED_OUTPUT,
339
339
  guardrail: emailGuardrail,
340
- maxRetries: EMAIL_GUARDRAIL_RETRIES,
340
+ maxRevisions: EMAIL_GUARDRAIL_REVISIONS,
341
341
  maxSteps: 1,
342
342
  });
343
343
 
@@ -39,8 +39,8 @@ describe("code-interpreter-agent template", () => {
39
39
  test("run_code survives into the config a deploy carries", () => {
40
40
  // The template's whole capability, asserted on the CONFIG rather than the
41
41
  // def because that is what a deploy ships. `DEFAULT_BUILTIN_TOOLS` is
42
- // EMPTY — a builtin is something an agent asks for, never something it has
43
- // to notice and switch off — so a dropped `builtinTools` is not a degraded
42
+ // `think` alone — every other builtin is something an agent asks for — so
43
+ // a dropped `builtinTools` is not a degraded
44
44
  // Coda, it is an agent whose prompt forbids mental arithmetic and leaves it
45
45
  // nothing else to do. Adding builtins beside it is fine; losing this one is
46
46
  // the regression.
@@ -33,7 +33,7 @@ export default agent({
33
33
  name: "Coding Agent",
34
34
  description: "Reads, edits and runs a codebase from a terminal chat",
35
35
  // No `llm` declared, so it runs the default AssemblyAI LLM gateway on
36
- // ASSEMBLYAI_API_KEY. Swap in `anthropicLlm({ model: "claude-opus-5" })` (or
36
+ // ASSEMBLYAI_API_KEY. Swap in `llm({ provider: "anthropic", model: "claude-opus-5" })` (or
37
37
  // any provider from `@alexkroman1/aai/llm`) when a task needs a stronger
38
38
  // model — the credential follows the descriptor.
39
39
  text: true,
@@ -1,5 +1,5 @@
1
1
  import { agent } from "@alexkroman1/aai";
2
- import { anthropicLlm } from "@alexkroman1/aai/llm";
2
+ import { llm } from "@alexkroman1/aai/llm";
3
3
 
4
4
  export default agent({
5
5
  name: "Custom Pipeline Assistant",
@@ -9,5 +9,5 @@ export default agent({
9
9
  // left unset (STT and TTS here) runs on the AssemblyAI default, billed to
10
10
  // the one key a published agent is guaranteed to have, so swapping a stage
11
11
  // never means restating the other two.
12
- llm: anthropicLlm({ model: "claude-haiku-4-5" }),
12
+ llm: llm({ provider: "anthropic", model: "claude-haiku-4-5" }),
13
13
  });
@@ -23,7 +23,7 @@ import {
23
23
  type SharedAgentParams,
24
24
  type TextAgentParams,
25
25
  } from "@alexkroman1/aai";
26
- import { anthropicLlm } from "@alexkroman1/aai/llm";
26
+ import { llm } from "@alexkroman1/aai/llm";
27
27
  import { toAgentConfig } from "@alexkroman1/aai/manifest";
28
28
  import { describe, expect, test } from "vitest";
29
29
 
@@ -55,7 +55,7 @@ describe("three modes, three arms", () => {
55
55
  // all-AssemblyAI preset.
56
56
  pipeline: {
57
57
  ...SHARED,
58
- llm: anthropicLlm({ model: "claude-haiku-4-5" }),
58
+ llm: llm({ provider: "anthropic", model: "claude-haiku-4-5" }),
59
59
  } satisfies PipelineAgentParams,
60
60
  // S2S replaces all three with one service-side loop.
61
61
  s2s: { ...SHARED, s2s: assemblyAIS2s() } satisfies S2sAgentParams,
@@ -94,13 +94,13 @@ test("the preset takes OPTIONS — one setting across the three stages at once",
94
94
  const options: AssemblyAIPipelineOptions = { region: "eu", voice: "michael" };
95
95
  const pipeline = assemblyAIPipeline(options);
96
96
  expect(pipeline.stt.options.region).toBe("eu");
97
- expect(pipeline.llm.options.region).toBe("eu");
97
+ expect(pipeline.llm.options.providerOptions).toMatchObject({ region: "eu" });
98
98
  expect(pipeline.tts.options.voice).toBe("michael");
99
99
 
100
100
  // And a stage declared AFTER the spread still wins — that is the whole point
101
101
  // of it being a plain object, and it is how this template's own `agent.ts`
102
102
  // would read if it wanted the other two stages visible in the config.
103
- const mine = anthropicLlm({ model: "claude-haiku-4-5" });
103
+ const mine = llm({ provider: "anthropic", model: "claude-haiku-4-5" });
104
104
  expect(agent({ ...SHARED, ...pipeline, llm: mine }).llm).toBe(mine);
105
105
  });
106
106