@alexkroman1/aai-cli 0.13.0 → 0.14.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.
- package/README.md +15 -15
- package/dist/{_bundler-CgBw5Bcu.mjs → _bundler-B6v31ROV.mjs} +1 -1
- package/dist/_console-audio.d.ts +18 -0
- package/dist/{_dev-server-BNq5OnUJ.mjs → _dev-server-GoEXEVpA.mjs} +2 -2
- package/dist/_resource-commands.d.ts +34 -2
- package/dist/{_slug-api-DJuwYZ6T.mjs → _slug-api-BnmTHtjd.mjs} +1 -1
- package/dist/{_studio-BH05zugt.mjs → _studio-B5m4jBTD.mjs} +14 -9
- package/dist/_studio.d.ts +16 -4
- package/dist/_target-bundle.d.ts +2 -0
- package/dist/{_templates-Bv-rd0SO.mjs → _templates-BVMVsQh0.mjs} +10 -6
- package/dist/_templates.d.ts +9 -2
- package/dist/{build-B37oBfEv.mjs → build-CKhanHVv.mjs} +28 -32
- package/dist/cli-workflow.d.ts +7 -0
- package/dist/cli.mjs +213 -181
- package/dist/{client-bundler-D4SeZJ8E.mjs → client-bundler-DZ_Zoznn.mjs} +2 -1
- package/dist/client-bundler.d.ts +7 -1
- package/dist/client-bundler.mjs +1 -1
- package/dist/{console-D6OOjjeJ.mjs → console-Dxq26Adz.mjs} +14 -10
- package/dist/{delete-Br0EOH0g.mjs → delete-DwXCHzTl.mjs} +8 -8
- package/dist/delete.d.ts +4 -3
- package/dist/{deploy-CLUH5cv2.mjs → deploy-CbA8Ibiu.mjs} +2 -2
- package/dist/{dev-ZVuyPLUk.mjs → dev-BWBDbUEb.mjs} +1 -1
- package/dist/{init-x3FsKl2q.mjs → init-CidslZZz.mjs} +1 -1
- package/dist/{logs-BfRq1HX9.mjs → logs-CnPK-Prw.mjs} +25 -3
- package/dist/scaffold/CLAUDE.md +52 -52
- package/dist/scaffold/agent-guide/AGENT-API.md +20 -20
- package/dist/scaffold/agent-guide/HOSTING.md +32 -33
- package/dist/scaffold/agent-guide/PIPELINE-TUNING.md +44 -47
- package/dist/scaffold/agent-guide/PROVIDERS.md +54 -57
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +31 -31
- package/dist/scaffold/agent-guide/TOOLS.md +86 -87
- package/dist/scaffold/agent-guide/UI.md +59 -58
- package/dist/scaffold/agent-guide/WORKFLOWS.md +129 -127
- package/dist/scaffold/package.json +4 -4
- package/dist/scaffold/vitest.config.ts +3 -3
- package/dist/{secret-Db1UWLSZ.mjs → secret-DPdPEet2.mjs} +2 -2
- package/dist/{studio-DAoJApzD.mjs → studio-COjK25Rl.mjs} +23 -24
- package/dist/studio.d.ts +5 -4
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +6 -6
- package/dist/templates/call-audit-workflow/agent.test.ts +2 -2
- package/dist/templates/document-redline-workflow/agent.eval.test.ts +14 -17
- package/dist/templates/home-assistant-agent/agent.test.ts +0 -1
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +2 -2
- package/dist/templates/link-digest-workflow/agent.test.ts +24 -25
- package/dist/templates/medication-safety-agent/agent.test.ts +15 -18
- package/dist/templates/medication-safety-agent/fda.test.ts +16 -17
- package/dist/templates/medication-safety-agent/fda.ts +7 -0
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +61 -53
- package/dist/templates/medication-safety-agent/tools/medication_lookup.ts +42 -32
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +29 -16
- package/dist/templates/podcast-digest-workflow/agent.eval.test.ts +3 -3
- package/dist/templates/podcast-digest-workflow/agent.test.ts +17 -17
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +22 -15
- package/dist/templates/research-handoff-agent/agent.test.ts +2 -15
- package/dist/templates/research-planner-agent/agent.test.ts +22 -17
- package/dist/templates/research-planner-agent/shared.ts +122 -93
- package/dist/templates/retail-orders-agent/shared.ts +2 -2
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +1 -1
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +6 -6
- package/dist/templates/spoken-summary-workflow/agent.test.ts +2 -2
- package/dist/templates/transcription-workflow/agent.eval.test.ts +3 -3
- package/dist/templates/transcription-workflow/agent.test.ts +2 -1
- package/dist/templates/transcription-workflow/recover.test.ts +4 -7
- package/dist/templates/web-research-agent/agent.test.ts +4 -3
- package/dist/templates/word-game-agent/agent.test.ts +11 -5
- package/package.json +6 -6
|
@@ -164,7 +164,7 @@ async function resolveDevDeps(deps) {
|
|
|
164
164
|
ui: deps.ui ?? defaultUi,
|
|
165
165
|
startQuickTunnel: deps.startQuickTunnel ?? startQuickTunnel,
|
|
166
166
|
runPublicUrlHook: deps.runPublicUrlHook ?? runPublicUrlHook,
|
|
167
|
-
startDevServer: deps.startDevServer ?? (await import("./_dev-server-
|
|
167
|
+
startDevServer: deps.startDevServer ?? (await import("./_dev-server-GoEXEVpA.mjs")).startDevServer
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
@@ -3,7 +3,7 @@ import { a as ok } from "./_output-DBP9Op_d.mjs";
|
|
|
3
3
|
import { i as unwrapCancel, t as defaultUi } from "./_ui-Coe0zwmm.mjs";
|
|
4
4
|
import { c as fileExists, d as readJson, i as compareCodeUnits, m as resolveCwd, s as errorMessage, t as AGENT_ENTRY, u as isEexist, v as writeJson } from "./_utils-BVLdBvdT.mjs";
|
|
5
5
|
import { r as isDevMode, t as getMonorepoRoot } from "./_agent-BopNO5Bq.mjs";
|
|
6
|
-
import { REPO_URL, downloadAndMergeTemplate, listTemplates } from "./_templates-
|
|
6
|
+
import { REPO_URL, downloadAndMergeTemplate, listTemplates } from "./_templates-BVMVsQh0.mjs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { styleText } from "node:util";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as ok } from "./_output-DBP9Op_d.mjs";
|
|
3
3
|
import { t as defaultUi } from "./_ui-Coe0zwmm.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { r as slugRequestOn, t as REAL_PLATFORM } from "./_slug-api-
|
|
4
|
+
import { p as checkedResponse } from "./_studio-B5m4jBTD.mjs";
|
|
5
|
+
import { r as slugRequestOn, t as REAL_PLATFORM } from "./_slug-api-BnmTHtjd.mjs";
|
|
6
6
|
import { isRecord, omitUndefined } from "@alexkroman1/aai/utils";
|
|
7
7
|
import { sleep } from "@alexkroman1/aai/internal";
|
|
8
|
+
//#region src/logs.ts
|
|
9
|
+
/**
|
|
10
|
+
* `aai logs` — what the deployed agent has printed.
|
|
11
|
+
*
|
|
12
|
+
* The terminal half of the same read the studio's Logs pane makes
|
|
13
|
+
* (`GET /:slug/logs`, aai-server/agent-logs.ts): a bounded ring the GUEST holds,
|
|
14
|
+
* paged by cursor. Two things follow from that and are what this command has to
|
|
15
|
+
* be honest about, because neither is visible in a wall of lines:
|
|
16
|
+
*
|
|
17
|
+
* - **The ring dies with the sandbox.** This is "what my agent printed
|
|
18
|
+
* recently", never "what it printed last Tuesday", and the footer says so on
|
|
19
|
+
* a one-shot read rather than leaving the absence to be inferred.
|
|
20
|
+
* - **`running` is not `lines.length`.** An agent that is up and quiet and one
|
|
21
|
+
* that is not up at all both print nothing, and they want opposite things
|
|
22
|
+
* from the reader. The one-shot read reports which it was.
|
|
23
|
+
*
|
|
24
|
+
* `--follow` polls. A stream would be the nicer shape and the source is not one:
|
|
25
|
+
* the guest holds a RING with a cursor, and a reconnecting stream would have to
|
|
26
|
+
* re-derive that cursor anyway.
|
|
27
|
+
*/
|
|
28
|
+
/** How often `--follow` asks for what is new. */
|
|
29
|
+
const FOLLOW_POLL_MS = 1e3;
|
|
8
30
|
function isLogsPage(value) {
|
|
9
31
|
return isRecord(value) && Array.isArray(value.lines) && typeof value.cursor === "number" && typeof value.running === "boolean";
|
|
10
32
|
}
|
|
@@ -77,4 +99,4 @@ function printPage(page, ui) {
|
|
|
77
99
|
return page.lines.length;
|
|
78
100
|
}
|
|
79
101
|
//#endregion
|
|
80
|
-
export { executeLogs };
|
|
102
|
+
export { FOLLOW_POLL_MS, executeLogs, formatLine, formatTime };
|
package/dist/scaffold/CLAUDE.md
CHANGED
|
@@ -40,23 +40,23 @@ The fast loop: edit → `pnpm dev` (browser, talk to it) → `pnpm test` (logic)
|
|
|
40
40
|
what it did. With a provider key it uses a LIVE model (spends tokens, noisy);
|
|
41
41
|
without one a SCRIPTED model, which proves wiring and nothing about what the
|
|
42
42
|
agent says.
|
|
43
|
-
4. **Run `pnpm build` before declaring done** — bundles `agent.ts`,
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
4. **Run `pnpm build` before declaring done** — bundles `agent.ts`, type-checks,
|
|
44
|
+
validates the manifest, and runs the WHOLE spec suite first. Catches issues
|
|
45
|
+
`dev` won't.
|
|
46
46
|
5. **Make small, focused changes** — verify each one before stacking the next.
|
|
47
47
|
6. **Look at templates before writing custom code** — the CLI ships working
|
|
48
48
|
examples inside its own package, at
|
|
49
49
|
`node_modules/@alexkroman1/aai-cli/dist/templates/`. Read them directly;
|
|
50
50
|
`aai init --template <name>` scaffolds a fresh project from one. Closest:
|
|
51
51
|
`quickstart-agent`, `custom-pipeline-agent`, `web-research-agent`,
|
|
52
|
-
`pizza-ordering-agent`, `retail-orders-agent` (the most complex). Built
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
`pizza-ordering-agent`, `retail-orders-agent` (the most complex). Built entry
|
|
53
|
+
points under `node_modules/@alexkroman1/aai*/dist/` re-export with source
|
|
54
|
+
specifiers — rewrite `.ts`/`.tsx` to `.d.ts` to find the file.
|
|
55
55
|
|
|
56
56
|
## CLI
|
|
57
57
|
|
|
58
|
-
The scaffold's `package.json` runs the project's own CLI as `pnpm dev`,
|
|
59
|
-
`
|
|
58
|
+
The scaffold's `package.json` runs the project's own CLI as `pnpm dev`, `build`,
|
|
59
|
+
`test`, `eval`, `start` and `publish:agent`; anywhere else it is
|
|
60
60
|
`npx aai <command>` (or `npm i -g @alexkroman1/aai-cli` once).
|
|
61
61
|
|
|
62
62
|
```sh
|
|
@@ -116,8 +116,8 @@ my-agent/
|
|
|
116
116
|
|
|
117
117
|
**`tools/` is not a convention, it is the mechanism.** A file there is named for
|
|
118
118
|
the tool the model calls, default-exports it, and is picked up by the build. It
|
|
119
|
-
is not imported by `agent.ts` and not listed anywhere — `agent()` has no
|
|
120
|
-
|
|
119
|
+
is not imported by `agent.ts` and not listed anywhere — `agent()` has no `tools`
|
|
120
|
+
field at all:
|
|
121
121
|
|
|
122
122
|
```ts
|
|
123
123
|
// tools/roll_dice.ts → the model calls this "roll_dice"
|
|
@@ -139,15 +139,15 @@ Three rules come with it, each a build error naming the file:
|
|
|
139
139
|
letter, and join words with `_` — `tools/incident_create.ts`, never
|
|
140
140
|
`incident-create.ts`. Renaming the file renames the tool.
|
|
141
141
|
- **The export is the DEFAULT export**, and it must be a `tool()` (or a
|
|
142
|
-
`slot.tool()` / `slot.updateTool()`). A file exporting something else is
|
|
143
|
-
|
|
142
|
+
`slot.tool()` / `slot.updateTool()`). A file exporting something else is named
|
|
143
|
+
at build time rather than becoming a tool that fails per turn.
|
|
144
144
|
- **`tools/` is flat.** A nested file — a nested HELPER too — is rejected, so
|
|
145
145
|
put shared helpers beside `agent.ts` rather than under `tools/`.
|
|
146
146
|
|
|
147
147
|
## `agent()` basics
|
|
148
148
|
|
|
149
|
-
The minimal agent — a cascaded pipeline, what to build unless the user asks
|
|
150
|
-
|
|
149
|
+
The minimal agent — a cascaded pipeline, what to build unless the user asks for
|
|
150
|
+
speech-to-speech:
|
|
151
151
|
|
|
152
152
|
```ts
|
|
153
153
|
import { agent } from "@alexkroman1/aai";
|
|
@@ -177,8 +177,8 @@ export default agent({
|
|
|
177
177
|
});
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
The fields almost every agent sets: `name` (required), `greeting` (default:
|
|
181
|
-
|
|
180
|
+
The fields almost every agent sets: `name` (required), `greeting` (default: "Hey
|
|
181
|
+
there..."; `""` starts silent), `tts` (voice `jane` unless set), `llm`,
|
|
182
182
|
`builtinTools` (omitted = `["think"]` only; setting it REPLACES the default),
|
|
183
183
|
`maxSteps` (default 10 tool-calling steps per reply) and `requiredEnv` (every
|
|
184
184
|
env var a tool or step reads; **publishing checks it**, so a missing key fails
|
|
@@ -189,10 +189,10 @@ field.
|
|
|
189
189
|
mode this guide assumes. `mode: "s2s"` beside an `s2s: assemblyAIS2s()`
|
|
190
190
|
descriptor selects speech-to-speech; `mode: "text"` a text-only agent;
|
|
191
191
|
`workflowApp()` (`mode: "workflow-app"`) a form with no session at all
|
|
192
|
-
(`agent-guide/WORKFLOWS.md`). A field the chosen mode does not have is a
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
(`agent-guide/WORKFLOWS.md`). A field the chosen mode does not have is a compile
|
|
193
|
+
error naming the mode. `assemblyAIPipeline()` is the explicit spelling of the
|
|
194
|
+
default pipeline (spread it for `region: "eu"`). Pipeline knobs and S2S are in
|
|
195
|
+
`agent-guide/PIPELINE-TUNING.md`; vendors in `agent-guide/PROVIDERS.md`.
|
|
196
196
|
|
|
197
197
|
## `tool()` basics
|
|
198
198
|
|
|
@@ -218,30 +218,30 @@ export default tool({
|
|
|
218
218
|
|
|
219
219
|
- **`execute` must return a value** (sync or async); it goes to the model.
|
|
220
220
|
`fetch` works directly, identically in `aai dev` and deployed.
|
|
221
|
-
- **`inputSchema` is a `z.object(...)` or absent.** Make a FIELD optional,
|
|
222
|
-
|
|
221
|
+
- **`inputSchema` is a `z.object(...)` or absent.** Make a FIELD optional, never
|
|
222
|
+
the object; omit the schema for a no-argument tool.
|
|
223
223
|
- **Do not annotate `execute`'s return type** — it breaks the moment the tool
|
|
224
224
|
also returns an error shape. Let it infer.
|
|
225
225
|
- **`ctx`** carries `env` (secrets; every read is `string | undefined` —
|
|
226
226
|
`requireEnv(ctx, "KEY")` fails by name), `signal` (pass it to anything slow),
|
|
227
|
-
`messages`, `sessionId`, `send(event, data)` to the browser,
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
`messages`, `sessionId`, `send(event, data)` to the browser, `generate(...)`
|
|
228
|
+
for a one-shot model call, `delegate(...)` for a speaker, `speech` to say
|
|
229
|
+
something later and `workflows` to start a durable run.
|
|
230
230
|
- **State across tool calls lives in a `sessionSlot`** — `slot.tool` reads,
|
|
231
231
|
`slot.updateTool` writes. Never keep it in a module variable: every session
|
|
232
232
|
shares the module.
|
|
233
233
|
|
|
234
234
|
`agent-guide/TOOLS.md` has the rest: `ctx` in full, session state, `dialog()`
|
|
235
|
-
and `procedure()`, speakers and the roster, `clientTool()` (a tool the
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
and `procedure()`, speakers and the roster, `clientTool()` (a tool the browser
|
|
236
|
+
runs), the built-in tool table, `/utils`, `/html`, persistence and the speech
|
|
237
|
+
helpers.
|
|
238
238
|
|
|
239
239
|
## `system-prompt.md` IS the system prompt
|
|
240
240
|
|
|
241
241
|
**Write the prompt in `system-prompt.md` beside `agent.ts`, and declare
|
|
242
|
-
nothing.** The build discovers the file, so there is no import line and no
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
nothing.** The build discovers the file, so there is no import line and no field
|
|
243
|
+
— the same rule `tools/` follows, applied to the one part of an agent that is a
|
|
244
|
+
DOCUMENT rather than a value.
|
|
245
245
|
|
|
246
246
|
```markdown
|
|
247
247
|
<!-- system-prompt.md -->
|
|
@@ -252,8 +252,8 @@ You are a concise, friendly assistant.
|
|
|
252
252
|
- Never read a URL aloud.
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
**Your prompt is ADDED to the framework's voice sections, never a
|
|
256
|
-
|
|
255
|
+
**Your prompt is ADDED to the framework's voice sections, never a replacement**
|
|
256
|
+
— yours comes last and wins on conflict. Never interpolate
|
|
257
257
|
`DEFAULT_SYSTEM_PROMPT` (exported to be READ).
|
|
258
258
|
|
|
259
259
|
Three rules, each a build error naming the file:
|
|
@@ -263,8 +263,8 @@ Three rules, each a build error naming the file:
|
|
|
263
263
|
ignoring the file.
|
|
264
264
|
- **An empty file is an error**, not a silent fall-through to the framework
|
|
265
265
|
default. Delete the file if that is what you want.
|
|
266
|
-
- **A `system-prompt/` directory is rejected.** One file, no concatenation
|
|
267
|
-
|
|
266
|
+
- **A `system-prompt/` directory is rejected.** One file, no concatenation order
|
|
267
|
+
to guess.
|
|
268
268
|
|
|
269
269
|
Composing a prompt from the file plus computed text, and a per-request prompt
|
|
270
270
|
resolver, are in `agent-guide/AGENT-API.md`. `greeting` stays a field: a
|
|
@@ -284,15 +284,15 @@ Never hardcode secrets in agent code.
|
|
|
284
284
|
`ctx.env`.
|
|
285
285
|
- **Production:** `aai secret put NAME`, and list the name in `requiredEnv`.
|
|
286
286
|
- **Access:** `ctx.env.MY_KEY` in a tool; `stepEnv("MY_KEY")` in a step.
|
|
287
|
-
- **AssemblyAI key:** `aai login` links your account and stores the key
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
287
|
+
- **AssemblyAI key:** `aai login` links your account and stores the key globally
|
|
288
|
+
— the only way the CLI authenticates. No `.env` entry needed. For CI, point
|
|
289
|
+
`AAI_CONFIG_DIR` at a config dir holding a logged-in key (an exported
|
|
290
|
+
`ASSEMBLYAI_API_KEY` does not authenticate).
|
|
291
291
|
|
|
292
292
|
## Subpath exports
|
|
293
293
|
|
|
294
|
-
Most of the API is not on the root entry. Import each name from the subpath
|
|
295
|
-
|
|
294
|
+
Most of the API is not on the root entry. Import each name from the subpath that
|
|
295
|
+
owns it:
|
|
296
296
|
|
|
297
297
|
<!-- BEGIN GENERATED aai subpaths: pnpm sync:agent-guide -->
|
|
298
298
|
|
|
@@ -343,10 +343,10 @@ Framework-internal, never imported by an `agent.ts`: `/protocol`,
|
|
|
343
343
|
<!-- END GENERATED aai subpaths -->
|
|
344
344
|
|
|
345
345
|
`@alexkroman1/aai-ui` is the browser client (`agent-guide/UI.md`) and
|
|
346
|
-
`@alexkroman1/aai-runtime` the host runtime. **A test file imports testing
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
`@alexkroman1/aai-runtime` the host runtime. **A test file imports testing names
|
|
347
|
+
from its two doors only**: `@alexkroman1/aai-runtime/testing` (every fake and
|
|
348
|
+
reader, plus `runWorkflow`) and `/testing/vitest` (every `install*`, plus the
|
|
349
|
+
eval suites) — `agent-guide/TESTING-EVALS.md`.
|
|
350
350
|
|
|
351
351
|
## Gotchas
|
|
352
352
|
|
|
@@ -373,16 +373,16 @@ plus the eval suites) — `agent-guide/TESTING-EVALS.md`.
|
|
|
373
373
|
file or env access. Deployed, it runs in the platform's sandbox. Or use the
|
|
374
374
|
`calculate` builtin for simple arithmetic.
|
|
375
375
|
- **There is no `ctx.db`.** A tool that persists brings its own client — see
|
|
376
|
-
"Persisting data" in `agent-guide/TOOLS.md`. A secret is read when the
|
|
377
|
-
|
|
378
|
-
- **A wrong TTS voice id is silent**: it is refused after the socket opens.
|
|
379
|
-
|
|
380
|
-
|
|
376
|
+
"Persisting data" in `agent-guide/TOOLS.md`. A secret is read when the sandbox
|
|
377
|
+
is BUILT, so a newly set `DATABASE_URL` arrives on the next deploy.
|
|
378
|
+
- **A wrong TTS voice id is silent**: it is refused after the socket opens. Pick
|
|
379
|
+
from the catalog in `agent-guide/PROVIDERS.md`. **Rime language codes are ISO
|
|
380
|
+
639-3** (`"eng"`), not ISO 639-1 (`"en"`).
|
|
381
381
|
|
|
382
382
|
## Constraints
|
|
383
383
|
|
|
384
|
-
- Tool `execute` return values go into LLM context, capped at 4000 chars
|
|
385
|
-
|
|
384
|
+
- Tool `execute` return values go into LLM context, capped at 4000 chars (a
|
|
385
|
+
truncation marker replaces the tail) — filter large API responses
|
|
386
386
|
- Agent code runs in a sandboxed worker with open egress for your own `fetch`
|
|
387
387
|
- Tool execution timeout: 30 seconds
|
|
388
388
|
- `maxSteps` caps tool calls per turn (default 10) — lower it for latency. At
|
|
@@ -4,13 +4,13 @@ Part of the aai authoring guide (start with the core guide, which has the
|
|
|
4
4
|
minimal agent and the fields almost every agent sets). This file lists EVERY
|
|
5
5
|
field `agent()` takes, grouped by what it governs. The declarations are the
|
|
6
6
|
final word: `AgentDef` documents each field's meaning and default, and
|
|
7
|
-
`AgentParams` — a union with one member per `mode` — which fields each mode
|
|
8
|
-
|
|
7
|
+
`AgentParams` — a union with one member per `mode` — which fields each mode has.
|
|
8
|
+
Both are in `node_modules/@alexkroman1/aai/dist/`.
|
|
9
9
|
|
|
10
10
|
## `agent()` API
|
|
11
11
|
|
|
12
|
-
A field the chosen `mode` does not have is simply ABSENT from that member of
|
|
13
|
-
|
|
12
|
+
A field the chosen `mode` does not have is simply ABSENT from that member of the
|
|
13
|
+
parameter type, so setting one (a pipeline knob on `mode: "s2s"`, `stt` on
|
|
14
14
|
`mode: "text"`) is a compile error naming the member; a raw config that skips
|
|
15
15
|
`agent()` is checked at parse time.
|
|
16
16
|
|
|
@@ -158,8 +158,8 @@ export default agent({
|
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
MCP servers are declared here and CONNECTED by the host (`withMcpTools` from
|
|
161
|
-
`@alexkroman1/aai-runtime`), because discovery is a network round trip. A
|
|
162
|
-
|
|
161
|
+
`@alexkroman1/aai-runtime`), because discovery is a network round trip. A server
|
|
162
|
+
that is down costs its own tools and nothing else:
|
|
163
163
|
|
|
164
164
|
```ts
|
|
165
165
|
import { agent } from "@alexkroman1/aai";
|
|
@@ -203,21 +203,21 @@ document goes in a file, a value stays in the call.**
|
|
|
203
203
|
|
|
204
204
|
**JSON imports need no attribute.** `resolveJsonModule` is on, so
|
|
205
205
|
`import data from "./knowledge.json"` is all it takes. Do NOT write
|
|
206
|
-
`assert { type: "json" }` — import assertions were replaced by import
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
`assert { type: "json" }` — import assertions were replaced by import attributes
|
|
207
|
+
and TypeScript rejects them (`TS2880`). If you want to be explicit the modern
|
|
208
|
+
spelling is `with { type: "json" }`, but plain is fine.
|
|
209
209
|
|
|
210
210
|
### Opt-in prompt presets
|
|
211
211
|
|
|
212
212
|
`agent({ voicePresets: ["echoVerification", "natoAlphabet"] })` switches on
|
|
213
|
-
named behaviours instead of writing them. They compose, each is removable on
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
in
|
|
213
|
+
named behaviours instead of writing them. They compose, each is removable on its
|
|
214
|
+
own, and each is paid for on EVERY model request: `echoVerification` (~190
|
|
215
|
+
tokens — read critical values back and get a yes), `speechNormalization` (~920 —
|
|
216
|
+
money, dates, phone numbers and emails as spoken words, `"$758.08"` as "seven
|
|
217
|
+
fifty-eight dollars and eight cents") and `natoAlphabet` (~190 — "That's B as in
|
|
218
|
+
Bravo, 7, K as in Kilo, 2 — correct?"). `VOICE_PRESETS` holds the exact text.
|
|
219
|
+
The two spelling presets override the default "don't spell things back", so use
|
|
220
|
+
them where a wrong value costs more than a slow call; `speechNormalization` is
|
|
221
|
+
the PROMPT layer only, and for the agent's OWN data the speech renderers
|
|
222
|
+
(`spokenMoney`, `spokenDate`, … — "Speech goes both ways" in `TOOLS.md`) do it
|
|
223
|
+
in code for free.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Self-hosting, tracing and deploy targets
|
|
2
2
|
|
|
3
3
|
Part of the aai authoring guide (start with the core guide). The managed
|
|
4
|
-
platform is `aai publish`; this file is everything that runs the agent
|
|
5
|
-
|
|
4
|
+
platform is `aai publish`; this file is everything that runs the agent somewhere
|
|
5
|
+
else — `npm start`, OpenTelemetry tracing, and `aai build --target`.
|
|
6
6
|
|
|
7
7
|
## Running it yourself (`npm start`)
|
|
8
8
|
|
|
@@ -14,10 +14,10 @@ npm start # http://127.0.0.1:3000
|
|
|
14
14
|
PORT=8080 HOST=0.0.0.0 npm start # bind every interface, e.g. in a container
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
`npm start` **builds first** (that is the `prestart` script) and then serves
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
`npm start` **builds first** (that is the `prestart` script) and then serves the
|
|
18
|
+
result: `aai start` boots `.aai/worker.mjs`, the same artifact `aai publish`
|
|
19
|
+
uploads. It serves your own `client.tsx` build when there is one and falls back
|
|
20
|
+
to the prebuilt default UI shipped inside `@alexkroman1/aai-ui`.
|
|
21
21
|
|
|
22
22
|
There is no server file in your project, and that is deliberate — the boot
|
|
23
23
|
belongs to the framework, so it improves when you update rather than being
|
|
@@ -25,30 +25,30 @@ frozen at the moment you scaffolded. When you need to own it, import
|
|
|
25
25
|
`createProjectServer` from `@alexkroman1/aai-cli/start`: it builds the server
|
|
26
26
|
and binds nothing, so you decide how it is served. Building one from scratch
|
|
27
27
|
instead, `defaultClientDir()` (`@alexkroman1/aai-ui/client-dir`) is where that
|
|
28
|
-
prebuilt UI lives — the only export of `aai-ui` that runs on Node rather than
|
|
29
|
-
|
|
28
|
+
prebuilt UI lives — the only export of `aai-ui` that runs on Node rather than in
|
|
29
|
+
the browser.
|
|
30
30
|
|
|
31
31
|
The build is what makes `tools/` work — a tool is registered by existing, and
|
|
32
32
|
the enumeration happens where the bundle is assembled, so a server that loaded
|
|
33
33
|
`agent.ts` directly would run an agent with none of its tools. The same build
|
|
34
34
|
produces your `client.tsx`, so a custom UI is served with no extra step.
|
|
35
35
|
|
|
36
|
-
Secrets work the same as everywhere else: `ctx.env` holds the keys declared
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
Secrets work the same as everywhere else: `ctx.env` holds the keys declared in
|
|
37
|
+
`.env` (or `.env.example`), and a real environment variable of that name wins —
|
|
38
|
+
so `docker run -e MY_API_KEY=…` needs no `.env` in the image.
|
|
39
39
|
|
|
40
|
-
One thing to know: it binds **loopback by default**, because this server has
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
One thing to know: it binds **loopback by default**, because this server has no
|
|
41
|
+
request authentication of its own; set `HOST=0.0.0.0` only behind your own proxy
|
|
42
|
+
or auth.
|
|
43
43
|
|
|
44
|
-
`run_code` is the one feature that does not follow — it needs a sandbox
|
|
45
|
-
|
|
44
|
+
`run_code` is the one feature that does not follow — it needs a sandbox (the
|
|
45
|
+
platform's, or `AAI_RUN_CODE=deno`) and refuses outside one.
|
|
46
46
|
|
|
47
47
|
## Tracing (OpenTelemetry)
|
|
48
48
|
|
|
49
|
-
Point the runtime at any OTLP collector and it exports spans for the model
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
Point the runtime at any OTLP collector and it exports spans for the model calls
|
|
50
|
+
your agent makes — one per generation, with a child per step, per model call and
|
|
51
|
+
per tool call, carrying model id, token counts and finish reason.
|
|
52
52
|
|
|
53
53
|
**It is off unless you configure a collector, and that is the whole switch:**
|
|
54
54
|
|
|
@@ -72,8 +72,7 @@ npm i @opentelemetry/api @opentelemetry/sdk-trace-base \
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
`aai dev` and `aai start` arm it for you. Embedding the server in a process of
|
|
75
|
-
your own means calling it yourself, from
|
|
76
|
-
`@alexkroman1/aai-runtime/tracing`:
|
|
75
|
+
your own means calling it yourself, from `@alexkroman1/aai-runtime/tracing`:
|
|
77
76
|
|
|
78
77
|
```ts
|
|
79
78
|
import { startTracing, tracingEndpoint } from "@alexkroman1/aai-runtime/tracing";
|
|
@@ -91,11 +90,11 @@ that must not wait — constructing the exporter costs a few hundred ms.
|
|
|
91
90
|
`DEFAULT_SERVICE_NAME` the fallback, if you would rather read them than
|
|
92
91
|
hard-code the strings.
|
|
93
92
|
|
|
94
|
-
**Spans carry no conversation content.** Not a default you can change — there
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
**Spans carry no conversation content.** Not a default you can change — there is
|
|
94
|
+
no code path that reads a prompt, a completion, a transcript, a tool argument or
|
|
95
|
+
a tool result, so none of it can reach your collector. Attributes are built from
|
|
96
|
+
an allow-list of metadata names following OpenTelemetry's `gen_ai.*`
|
|
97
|
+
conventions, so existing dashboards find them.
|
|
99
98
|
|
|
100
99
|
### Deploying to a host that wants its own entry file
|
|
101
100
|
|
|
@@ -131,10 +130,10 @@ not copied.
|
|
|
131
130
|
|
|
132
131
|
One thing to know before deploying a VOICE agent to a serverless host: the
|
|
133
132
|
session is a WebSocket, so the host has to support one. Vercel does — it hands
|
|
134
|
-
the function the raw upgrade, and the emitted entry passes it to the same
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
needs
|
|
133
|
+
the function the raw upgrade, and the emitted entry passes it to the same server
|
|
134
|
+
`aai dev` runs. Deno Deploy does too, and more simply: it runs a long-lived
|
|
135
|
+
process, so the emitted entry just calls `listen()` and the session reaches the
|
|
136
|
+
same server unchanged. A host that serves only request/response still runs the
|
|
137
|
+
HTTP surface — `/health`, `/client-config`, `/workflows/*` and your static
|
|
138
|
+
assets — which is everything a workflow app needs and none of what a voice agent
|
|
139
|
+
needs.
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Part of the aai authoring guide (start with the core guide). This file covers
|
|
4
4
|
the session's MODES — the default pipeline, S2S, text — answering and placing
|
|
5
|
-
phone calls, speaking from outside a turn, and the pipeline's turn-taking
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
phone calls, speaking from outside a turn, and the pipeline's turn-taking knobs.
|
|
6
|
+
Which vendor runs each stage is `PROVIDERS.md`; the full `agent()` field list is
|
|
7
|
+
`AGENT-API.md`.
|
|
8
8
|
|
|
9
9
|
## Pipeline mode
|
|
10
10
|
|
|
11
|
-
Pipeline mode is the default: omitting `stt`/`llm`/`tts` (and `s2s`) gives
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
Pipeline mode is the default: omitting `stt`/`llm`/`tts` (and `s2s`) gives you
|
|
12
|
+
the all-AssemblyAI pipeline, and any stage you do declare replaces just that
|
|
13
|
+
stage — the rest keep the default.
|
|
14
14
|
|
|
15
15
|
**S2S mode is an explicit opt-in.** `mode: "s2s"` beside an
|
|
16
16
|
`s2s: assemblyAIS2s()` descriptor (imported from `@alexkroman1/aai`, next to
|
|
@@ -49,35 +49,33 @@ export default agent({
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
- `voice` — the agent's voice. Unset uses the service default.
|
|
52
|
-
- `languages` — **leave it unset for multilingual calls**: unset means
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(Vercel AI SDK) with your chosen STT, LLM, and TTS. You want explicit
|
|
66
|
-
providers when:
|
|
52
|
+
- `languages` — **leave it unset for multilingual calls**: unset means "detect
|
|
53
|
+
per turn", so pinning `["en"]` on a line that takes other languages disables
|
|
54
|
+
detection for every caller. Pin it when the line really is monolingual — on a
|
|
55
|
+
benchmark run that plus a transcription prompt took a caller's spelled first
|
|
56
|
+
name from 1 of 6 attempts correct to 6 of 6.
|
|
57
|
+
- `keyterms` — product names and proper nouns to bias transcription toward. Use
|
|
58
|
+
`sttPrompt` (above, and honoured in **both** modes) for prose guidance and
|
|
59
|
+
`keyterms` for a term list.
|
|
60
|
+
|
|
61
|
+
**Prefer pipeline mode** — the default — unless the user specifically asks for
|
|
62
|
+
the speech-to-speech API. Nearly every template ships this way, and it is what
|
|
63
|
+
AssemblyAI Build defaults to. The host runs the LLM loop locally (Vercel AI SDK)
|
|
64
|
+
with your chosen STT, LLM, and TTS. You want explicit providers when:
|
|
67
65
|
|
|
68
66
|
- you want a specific LLM (Anthropic, OpenAI, Gemini, Mistral, xAI, Groq,
|
|
69
|
-
hundreds of models via OpenRouter, or 25+ models via the AssemblyAI
|
|
70
|
-
|
|
71
|
-
- you want a specific STT model, a non-AssemblyAI TTS provider, or another
|
|
72
|
-
|
|
67
|
+
hundreds of models via OpenRouter, or 25+ models via the AssemblyAI LLM
|
|
68
|
+
Gateway)
|
|
69
|
+
- you want a specific STT model, a non-AssemblyAI TTS provider, or another voice
|
|
70
|
+
(`tts: assemblyAITts({ voice })`)
|
|
73
71
|
- you need to swap providers without changing agent code
|
|
74
72
|
|
|
75
|
-
**The rule:** declare only the stages you're changing — any subset of
|
|
76
|
-
`
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
**The rule:** declare only the stages you're changing — any subset of `stt`,
|
|
74
|
+
`llm`, `tts`; each unset stage runs on the AssemblyAI default. Combining `s2s`
|
|
75
|
+
with any pipeline provider or pipeline-only tuning field is a compile error
|
|
76
|
+
naming the rule; a voice has one place to live, the TTS descriptor (there is no
|
|
77
|
+
agent-level `voice`). A raw config that skips `agent()` is still checked at
|
|
78
|
+
parse time.
|
|
81
79
|
|
|
82
80
|
```ts
|
|
83
81
|
import { agent } from "@alexkroman1/aai";
|
|
@@ -93,8 +91,8 @@ export default agent({
|
|
|
93
91
|
});
|
|
94
92
|
```
|
|
95
93
|
|
|
96
|
-
Tools, the database, `ctx`, and the UI all behave identically across modes.
|
|
97
|
-
|
|
94
|
+
Tools, the database, `ctx`, and the UI all behave identically across modes. Only
|
|
95
|
+
the audio + LLM transport differs.
|
|
98
96
|
|
|
99
97
|
**Four modes, one field on `agent()`: `mode`.** Omit it for PIPELINE (voice,
|
|
100
98
|
cascaded STT → LLM → TTS) — the default, and the mode this guide assumes.
|
|
@@ -132,9 +130,9 @@ mu-law is transcoded both ways, so a call is a transport, not a mode.
|
|
|
132
130
|
`createAgentServer({ telephony })` overrides one deployment; embedding:
|
|
133
131
|
`createTelephonyBridge`, `startTelephonySession`.
|
|
134
132
|
|
|
135
|
-
**A call your app places** (below): the session starts on the carrier's
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
**A call your app places** (below): the session starts on the carrier's `start`
|
|
134
|
+
frame, so `sessionContext`/`onSessionEnd` get `call` —
|
|
135
|
+
`{ carrier, callId?, parameters }` — and a tool reads `sessionCall(ctx)`.
|
|
138
136
|
`/phone` is unauthenticated: check a parameter you issued and answer
|
|
139
137
|
`{ refuse: "why" }` otherwise (hung up before the greeting or any model call; a
|
|
140
138
|
WebSocket gets 1008). A tool hangs up with `endSession(ctx)` once the reply has
|
|
@@ -159,14 +157,13 @@ been spoken (`{ afterReply: false }` cuts it); a spec reads
|
|
|
159
157
|
- `turnTaking` — `minSilenceMs`/`maxSilenceMs` are how long a pause ends a turn
|
|
160
158
|
(lowered onto the default `assemblyAIStt()`; with an explicit `stt` set them
|
|
161
159
|
on the descriptor, e.g. `deepgramStt({ endpointing })`). `userTurnLimit`
|
|
162
|
-
(`{ maxWords }`, `{ maxDurationMs }` or both; `{}` refused) ends ONE turn as
|
|
163
|
-
|
|
160
|
+
(`{ maxWords }`, `{ maxDurationMs }` or both; `{}` refused) ends ONE turn as a
|
|
161
|
+
pause would, emitting `userTurn.exceeded`. `detection: "manual"` is
|
|
164
162
|
PUSH-TO-TALK (`usePushToTalk()` in `aai-ui`): the mic is heard only while
|
|
165
|
-
held, all of it is ONE turn answered on release, and pressing is the
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
adopted.
|
|
163
|
+
held, all of it is ONE turn answered on release, and pressing is the barge-in.
|
|
164
|
+
`preemptiveGeneration` (default **`false`**) starts the reply from a confident
|
|
165
|
+
interim, adopted if the commit matches (measured **+8ms per turn**, 44% of
|
|
166
|
+
requests wasted); it never speaks or calls a tool until adopted.
|
|
170
167
|
|
|
171
168
|
### Placing a call
|
|
172
169
|
|
|
@@ -229,7 +226,7 @@ speaking on every one never stops. Speak from an event your line cannot produce
|
|
|
229
226
|
(`tool.called`, a timer), or check the event's `text` first.
|
|
230
227
|
|
|
231
228
|
`done` never rejects: `"played"` once playback ends, `"interrupted"`,
|
|
232
|
-
`"dropped"` (call ended, taken back, or an S2S agent). **Never await
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
229
|
+
`"dropped"` (call ended, taken back, or an S2S agent). **Never await `done`
|
|
230
|
+
inside the reply it waits behind** (a tool's `execute`). **A session id is not
|
|
231
|
+
authorization**: verify a webhook first. Specs: `createToolContext()` records
|
|
232
|
+
into `ctx.said`.
|