@alexkroman1/aai-cli 16.1.0 → 17.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.
- package/README.md +2 -1
- package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
- package/dist/_build-target.d.ts +98 -19
- package/dist/_deno-target.d.ts +15 -14
- package/dist/_dev-env.d.ts +19 -13
- package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-CLU9xjH5.mjs} +25 -17
- package/dist/_dev-server.d.ts +4 -3
- package/dist/_init.d.ts +39 -0
- package/dist/_modal-target.d.ts +11 -6
- package/dist/_preflight-CnW9QiE7.mjs +116 -0
- package/dist/_preflight.d.ts +110 -5
- package/dist/_target-bundle.d.ts +112 -0
- package/dist/_target-entry.d.ts +81 -0
- package/dist/{_templates-CuP74F8D.mjs → _templates-IMeKMVIj.mjs} +1 -1
- package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
- package/dist/_vitest-runner.d.ts +35 -23
- package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
- package/dist/build.d.ts +34 -4
- package/dist/cli.mjs +20 -16
- package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
- package/dist/deploy.d.ts +9 -0
- package/dist/{dev-Du8pCWFq.mjs → dev-ChsrNHpK.mjs} +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
- package/dist/init-W-4k-lCF.mjs +559 -0
- package/dist/init.d.ts +43 -3
- package/dist/scaffold/CLAUDE.md +51 -64
- package/dist/scaffold/package.json +6 -6
- package/dist/scaffold/vite.config.ts +29 -1
- package/dist/{studio-It7SRfUN.mjs → studio-DEAJGBXa.mjs} +19 -9
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
- package/dist/templates/applicant-screening-agent/agent.ts +28 -0
- package/dist/templates/applicant-screening-agent/shared.ts +11 -11
- package/dist/templates/call-audit-workflow/agent.ts +2 -0
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
- package/dist/templates/code-interpreter-agent/agent.ts +1 -0
- package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
- package/dist/templates/coding-agent/agent.test.ts +109 -0
- package/dist/templates/coding-agent/agent.ts +45 -0
- package/dist/templates/coding-agent/chat.ts +63 -0
- package/dist/templates/coding-agent/shared.ts +46 -0
- package/dist/templates/coding-agent/system-prompt.md +32 -0
- package/dist/templates/coding-agent/tools/bash.ts +6 -0
- package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
- package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
- package/dist/templates/coding-agent/tools/glob.ts +6 -0
- package/dist/templates/coding-agent/tools/grep.ts +6 -0
- package/dist/templates/coding-agent/tools/list_files.ts +6 -0
- package/dist/templates/coding-agent/tools/read_file.ts +6 -0
- package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
- package/dist/templates/coding-agent/tools/write_file.ts +6 -0
- package/dist/templates/custom-pipeline-agent/agent.ts +1 -0
- package/dist/templates/document-redline-workflow/agent.ts +2 -0
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
- package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
- package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
- package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +8 -1
- package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
- package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
- package/dist/templates/executive-inbox-agent/agent.ts +1 -0
- package/dist/templates/executive-inbox-agent/meeting.ts +1 -1
- package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
- package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
- package/dist/templates/hotel-reception-agent/agent.test.ts +2 -1
- package/dist/templates/hotel-reception-agent/agent.ts +6 -3
- package/dist/templates/hotel-reception-agent/client.tsx +14 -2
- package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +2 -1
- package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
- package/dist/templates/hotel-reception-agent/events.ts +2 -1
- package/dist/templates/hotel-reception-agent/session.ts +56 -0
- package/dist/templates/hotel-reception-agent/shared.ts +20 -21
- package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
- package/dist/templates/link-digest-workflow/agent.ts +5 -0
- package/dist/templates/medication-safety-agent/agent.test.ts +54 -0
- package/dist/templates/medication-safety-agent/agent.ts +48 -1
- package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
- package/dist/templates/meeting-recap-agent/agent.ts +4 -0
- package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
- package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +39 -3
- package/dist/templates/quickstart-agent/agent.test.ts +22 -0
- package/dist/templates/quickstart-agent/agent.ts +18 -2
- package/dist/templates/quickstart-agent/system-prompt.md +8 -0
- package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
- package/dist/templates/research-handoff-agent/agent.ts +4 -0
- package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
- package/dist/templates/research-planner-agent/agent.ts +3 -0
- package/dist/templates/research-planner-agent/system-prompt.md +1 -1
- package/dist/templates/retail-orders-agent/agent.ts +32 -3
- package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
- package/dist/templates/retail-orders-agent/resolve.ts +18 -3
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +37 -5
- package/dist/templates/roadside-assistance-agent/agent.test.ts +38 -6
- package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
- package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
- package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
- package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
- package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
- package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
- package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
- package/dist/templates/technical-support-agent/agent.test.ts +3 -3
- package/dist/templates/technical-support-agent/agent.ts +5 -1
- package/dist/templates/technical-support-agent/knowledge.ts +165 -0
- package/dist/templates/technical-support-agent/nodes.ts +3 -2
- package/dist/templates/technical-support-agent/procedure.ts +4 -3
- package/dist/templates/technical-support-agent/shared.ts +10 -146
- package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
- package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
- package/dist/templates/text-adventure-agent/agent.ts +30 -1
- package/dist/templates/text-adventure-agent/shared.ts +37 -0
- package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
- package/dist/templates/topic-briefing-agent/agent.test.ts +23 -11
- package/dist/templates/topic-briefing-agent/agent.ts +4 -1
- package/dist/templates/topic-briefing-agent/shared.ts +10 -10
- package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
- package/dist/templates/transcription-workflow/agent.ts +3 -0
- package/dist/templates/travel-concierge-agent/agent.ts +4 -0
- package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
- package/dist/templates/web-research-agent/agent.test.ts +16 -0
- package/dist/templates/web-research-agent/agent.ts +30 -0
- package/dist/templates/web-research-agent/system-prompt.md +8 -2
- package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
- package/dist/templates/word-game-agent/agent.ts +20 -0
- package/dist/test-CjKPQ9_B.mjs +102 -0
- package/dist/test.d.ts +37 -12
- package/package.json +5 -5
- package/dist/_init-Bp1CjRrU.mjs +0 -199
- package/dist/_preflight-CcAR577V.mjs +0 -46
- package/dist/init-CY4NAXAA.mjs +0 -183
- package/dist/test-PHHv0Vj6.mjs +0 -83
|
@@ -87,6 +87,11 @@ export const digest = workflow({
|
|
|
87
87
|
|
|
88
88
|
export default workflowApp({
|
|
89
89
|
name: "Link Digest",
|
|
90
|
+
// TWO descriptions, two readers, and they are deliberately not one sentence.
|
|
91
|
+
// This one says what the APP is, for a registry page or the studio's picker.
|
|
92
|
+
// The one on `digest` above says what a RUN does and is served as JSON Schema
|
|
93
|
+
// on `GET /workflows`, which is what lets a page render a form for it.
|
|
94
|
+
description: "Turns a pasted link into a headline and three points",
|
|
90
95
|
// The whole product. A workflow app is an agent whose work happens here.
|
|
91
96
|
workflows: { digest },
|
|
92
97
|
// Checked at deploy time. A workflow app declares no providers, so this is the
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type ToolFailure,
|
|
6
6
|
} from "@alexkroman1/aai";
|
|
7
7
|
import {
|
|
8
|
+
createToolContext,
|
|
8
9
|
expectDeployable,
|
|
9
10
|
expectPromptBuiltinsDeclared,
|
|
10
11
|
toolInputIssues,
|
|
@@ -297,3 +298,56 @@ describe("fda.ts helpers", () => {
|
|
|
297
298
|
expect(excerptAround("warfarin", "warfarin")).toBe("warfarin");
|
|
298
299
|
});
|
|
299
300
|
});
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The output guardrail, driven the way the runtime drives it.
|
|
304
|
+
*
|
|
305
|
+
* It is a plain function of the reply text, so a spec can run it with no model,
|
|
306
|
+
* no session and no network — which is most of the reason to write this rule as
|
|
307
|
+
* a declaration rather than as another line in `system-prompt.md`. A prompt rule
|
|
308
|
+
* can only be tested by asking a model and hoping; this one has an answer.
|
|
309
|
+
*
|
|
310
|
+
* `createToolContext()` stands in for the `AgentSessionContext` the runtime
|
|
311
|
+
* passes second. This check reads only the text, but a guardrail that counted
|
|
312
|
+
* strikes in `ctx.slots` would be driven exactly the same way.
|
|
313
|
+
*
|
|
314
|
+
* Asserted on the DEF and not on `expectDeployable`'s config: a guardrail is a
|
|
315
|
+
* function, so nothing about it goes on the wire.
|
|
316
|
+
*/
|
|
317
|
+
describe("the dose guardrail", () => {
|
|
318
|
+
const judge = async (text: string) => {
|
|
319
|
+
const [check] = agentDef.outputGuardrails ?? [];
|
|
320
|
+
// Not a fallback to `true`: a spec whose subject is that a check EXISTS has
|
|
321
|
+
// to fail when it has gone, rather than pass by default.
|
|
322
|
+
if (!check) throw new Error("Dr. Sage declares no output guardrail.");
|
|
323
|
+
return await check(text, createToolContext());
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
test("a reply carrying a dose is never spoken — the caller hears the refusal instead", async () => {
|
|
327
|
+
// A string verdict IS what is said, in place of the reply; there is no
|
|
328
|
+
// rewrite and no second turn. So the claim is about the sentence a caller
|
|
329
|
+
// hears, not about a flag.
|
|
330
|
+
expect(await judge("Take 200 mg of ibuprofen every six hours.")).toContain("pharmacist");
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test("an answer with no amount in it passes through untouched", async () => {
|
|
334
|
+
expect(await judge("Ibuprofen can upset your stomach — take it with food.")).toBe(true);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("a label QUOTE is refused too, which is the over-block this agent accepts", async () => {
|
|
338
|
+
// `medication_lookup` hands back label text verbatim and label text is full
|
|
339
|
+
// of "200 mg tablets", so this is not a corner case — it is the common one.
|
|
340
|
+
// Over-blocking is the safe direction here: the caller is told to ask a
|
|
341
|
+
// pharmacist, which is the answer the brief wanted anyway.
|
|
342
|
+
expect(await judge("The label says it comes in 200 mg tablets.")).toContain("pharmacist");
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("every unit an openFDA label writes doses in is covered", async () => {
|
|
346
|
+
// The pattern is not a dose parser and does not try to be. What it owes is
|
|
347
|
+
// the units that actually appear on a label — a gap here is a dose spoken
|
|
348
|
+
// out loud, which is the one thing this agent must not do.
|
|
349
|
+
const doses = ["500mg", "1.5 mL", "50 mcg", "2 g", "400 IU", "10 units"];
|
|
350
|
+
const verdicts = await Promise.all(doses.map((dose) => judge(`Take ${dose}.`)));
|
|
351
|
+
expect(verdicts.map((verdict) => verdict === true)).toEqual(doses.map(() => false));
|
|
352
|
+
});
|
|
353
|
+
});
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import { agent } from "@alexkroman1/aai";
|
|
1
|
+
import { type AgentGuardrail, agent } from "@alexkroman1/aai";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The check itself, named and typed rather than written inline.
|
|
5
|
+
*
|
|
6
|
+
* A guardrail is the one declaration in an `agent()` that can stop the agent
|
|
7
|
+
* saying something, so it is worth reading on its own — and `AgentGuardrail`
|
|
8
|
+
* is what types the pair it is handed (the text, and the session's context).
|
|
9
|
+
*/
|
|
10
|
+
const refuseDoses: AgentGuardrail = (text) =>
|
|
11
|
+
/\b\d+(?:\.\d+)?\s?(?:mg|mcg|ml|g|iu|units?)\b/i.test(text)
|
|
12
|
+
? "I can't give dosing information — the amount to take depends on things I don't know about you. Please check the label or ask your pharmacist, and I'm happy to help with side effects or interactions."
|
|
13
|
+
: true;
|
|
2
14
|
|
|
3
15
|
export default agent({
|
|
4
16
|
name: "Dr. Sage",
|
|
17
|
+
// Read by whoever is looking at a LIST of agents — a registry page, the
|
|
18
|
+
// studio's picker — and never by the model. The model's brief is
|
|
19
|
+
// `system-prompt.md`.
|
|
20
|
+
description: "Answers medication questions from openFDA labels, and never gives dosing advice",
|
|
5
21
|
greeting:
|
|
6
22
|
"Hey, I'm Dr. Sage. Try asking me something like, what are the side effects of ibuprofen, can I take aspirin and warfarin together, or calculate my BMI. Just remember, I'm not a real doctor, so always check with your healthcare provider.",
|
|
7
23
|
// Three builtins, and `fetch_json` is the one worth explaining: `fda.ts`
|
|
@@ -12,4 +28,35 @@ export default agent({
|
|
|
12
28
|
// compose, not a fixed tool's. `system-prompt.md` holds the endpoint and the
|
|
13
29
|
// caveat that a report count is not an incidence rate.
|
|
14
30
|
builtinTools: ["web_search", "run_code", "fetch_json"],
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The one rule in this agent's brief that must not depend on the model
|
|
34
|
+
* following it.
|
|
35
|
+
*
|
|
36
|
+
* `system-prompt.md` already says not to give a dose. A prompt is a request,
|
|
37
|
+
* and this agent reads out drug labels — every one of which contains dosing
|
|
38
|
+
* text the model is one summarization away from repeating. An output
|
|
39
|
+
* guardrail is the only place the sentence can be stopped, because it is the
|
|
40
|
+
* only thing that runs between the model finishing and the synthesizer
|
|
41
|
+
* starting (see `AgentGuardrails` — in S2S mode there is no such point, and
|
|
42
|
+
* declaring one there is refused rather than ignored).
|
|
43
|
+
*
|
|
44
|
+
* Two properties are worth copying into your own:
|
|
45
|
+
*
|
|
46
|
+
* - **The verdict is what the caller HEARS**, not a complaint sent back to
|
|
47
|
+
* the model. There is no rewrite: a second full turn is time a caller
|
|
48
|
+
* spends in silence, so the honest options are the fallback sentence or
|
|
49
|
+
* nothing.
|
|
50
|
+
* - **It costs the streaming.** A reply that must be judged whole cannot be
|
|
51
|
+
* spoken as it arrives, so this agent's answers begin when the model
|
|
52
|
+
* finishes rather than as it types. That is the price of a block that is
|
|
53
|
+
* real, and it is why the field is opt-in.
|
|
54
|
+
*
|
|
55
|
+
* The pattern deliberately does not try to be a dose PARSER. It matches a
|
|
56
|
+
* number next to a dose unit, which over-blocks (a label quote that mentions
|
|
57
|
+
* "200 mg tablets" is refused too) — and over-blocking is the safe direction
|
|
58
|
+
* for this agent: the caller is told to ask a pharmacist, which is the answer
|
|
59
|
+
* the brief wanted anyway.
|
|
60
|
+
*/
|
|
61
|
+
outputGuardrails: [refuseDoses],
|
|
15
62
|
});
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
* RECORDED and its `waitFor` answers out of `hooks`, so no wait it serves ever
|
|
38
38
|
* suspended. A wait now hands the body a promise that never settles, so a
|
|
39
39
|
* suspension cannot reach a `catch` at all and there is no branch left to test:
|
|
40
|
-
* `aai-runtime`'s `workflow
|
|
41
|
-
* `workflow
|
|
40
|
+
* `aai-runtime`'s `workflow/replay/suspend.ts` carries the mechanism and
|
|
41
|
+
* `workflow/replay.test.ts` the engine-level proof, for every template at once.
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
@@ -79,6 +79,10 @@ import { recap } from "./shared.ts";
|
|
|
79
79
|
|
|
80
80
|
export default agent({
|
|
81
81
|
name: "Recap Desk",
|
|
82
|
+
// The desk's job, for a registry page or the studio's picker. Not the same
|
|
83
|
+
// sentence as `recap`'s own `description` in `shared.ts`: that one describes a
|
|
84
|
+
// RUN and is read by whoever is choosing a workflow to start.
|
|
85
|
+
description: "Transcribes meeting recordings and reads the write-up back when it lands",
|
|
82
86
|
greeting: "Recap desk. Want me to write up a recording?",
|
|
83
87
|
systemPrompt: [
|
|
84
88
|
"You take recordings over the phone, hand them to a transcription run, and read back recaps.",
|
|
@@ -9,6 +9,9 @@ import systemPrompt from "./system-prompt.md?raw";
|
|
|
9
9
|
|
|
10
10
|
export default agent({
|
|
11
11
|
name: "Pizza Palace",
|
|
12
|
+
// What the shop DOES, for a reader of a list of agents — not for the model,
|
|
13
|
+
// which gets `system-prompt.md` and the generated menu below.
|
|
14
|
+
description: "Takes pizza orders over the phone, from first topping to checkout",
|
|
12
15
|
// `orderSlot.state` IS the `() => ({ [slot.key]: slot.create() })` factory,
|
|
13
16
|
// so the session's cart exists before the first tool call — which is what a
|
|
14
17
|
// resumed connection needs to have something to project.
|
|
@@ -131,6 +131,10 @@ export const dailyDigest: WorkflowDef<typeof digestInput, DailyDigestOutput> = w
|
|
|
131
131
|
|
|
132
132
|
export default workflowApp({
|
|
133
133
|
name: "Podcast Digest",
|
|
134
|
+
// The app's own line, for a reader of a list. `dailyDigest` above carries its
|
|
135
|
+
// own description for a different reader — the workflow listing a form is
|
|
136
|
+
// rendered from — and says the schedule, which is a fact about a run.
|
|
137
|
+
description: "Posts a recurring digest of new podcast episodes to Slack",
|
|
134
138
|
// The whole product. A workflow app is an agent whose work happens here.
|
|
135
139
|
workflows: { dailyDigest },
|
|
136
140
|
// Checked at deploy time. A workflow app declares no providers, so this is
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The def a DEPLOYED agent runs: authored, plus what `tools/` and
|
|
3
|
+
* `system-prompt.md` declare.
|
|
4
|
+
*
|
|
5
|
+
* `./agent.ts` would be the wrong import even for a template this small.
|
|
6
|
+
* Discovery happens where the bundle is assembled, so the authored export has
|
|
7
|
+
* NO tools and the framework-default prompt — an eval driving it measures a
|
|
8
|
+
* different agent than the one that deploys, and the tool-choice claim below
|
|
9
|
+
* would pass or fail for the wrong reason.
|
|
10
|
+
*/
|
|
11
|
+
import agentDef from "virtual:aai/agent";
|
|
1
12
|
// An EVAL: does the agent actually behave? Run it with `aai eval`.
|
|
2
13
|
//
|
|
3
14
|
// A test asserts about the config (see agent.test.ts — it never calls a model).
|
|
@@ -17,10 +28,9 @@
|
|
|
17
28
|
// What no eval here can see: anything below the audio boundary — where the
|
|
18
29
|
// agent decides you stopped talking, how it handles being interrupted, whether
|
|
19
30
|
// two sentences merged into one turn. Those need real paced audio.
|
|
20
|
-
import { errorsIn } from "@alexkroman1/aai-runtime/eval";
|
|
31
|
+
import { errorsIn, toolNames } from "@alexkroman1/aai-runtime/eval";
|
|
21
32
|
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
22
33
|
import { expect } from "vitest";
|
|
23
|
-
import agentDef from "./agent.ts";
|
|
24
34
|
|
|
25
35
|
describeEval(agentDef, (test) => {
|
|
26
36
|
test(
|
|
@@ -33,12 +43,38 @@ describeEval(agentDef, (test) => {
|
|
|
33
43
|
|
|
34
44
|
expect(turn.completed).toBe(true);
|
|
35
45
|
expect(turn.text).toMatch(/paris/i);
|
|
36
|
-
//
|
|
46
|
+
// The agent's one tool looks up WEATHER, so reaching for it here would
|
|
47
|
+
// be a real finding — not "this agent has no tools", which is what this
|
|
48
|
+
// line used to say and stopped being true the day it got one.
|
|
37
49
|
expect(turn.toolCalls).toEqual([]);
|
|
38
50
|
},
|
|
39
51
|
{ stubReply: "Paris is the capital of France." },
|
|
40
52
|
);
|
|
41
53
|
|
|
54
|
+
test(
|
|
55
|
+
"reaches for the tool that is only a FILE",
|
|
56
|
+
async ({ session }) => {
|
|
57
|
+
const turn = await session.say("What's the weather in Denver?");
|
|
58
|
+
|
|
59
|
+
// The claim the quickstart makes about this project: `get_weather` is a
|
|
60
|
+
// file in `tools/` that nothing imports and nothing registers, and this
|
|
61
|
+
// is the case that would notice if the directory went missing — a
|
|
62
|
+
// scripted run still boots the agent and still executes the tool a
|
|
63
|
+
// script names, so it checks the wiring even with no key set.
|
|
64
|
+
expect(toolNames(turn.toolCalls)).toEqual(["get_weather"]);
|
|
65
|
+
expect(turn.text).toMatch(/denver/i);
|
|
66
|
+
},
|
|
67
|
+
// The tool really runs, and really calls wttr.in. Nothing here asserts on
|
|
68
|
+
// what it answered: a service that is down returns the `{ error }` the
|
|
69
|
+
// tool is written to hand back, and the claim is about the CHOICE.
|
|
70
|
+
{
|
|
71
|
+
stubReply: [
|
|
72
|
+
{ tool: "get_weather", args: { city: "Denver" } },
|
|
73
|
+
"It's 54 degrees and clear in Denver.",
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
42
78
|
test(
|
|
43
79
|
"keeps the thread across two turns",
|
|
44
80
|
async ({ session }) => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** The def a DEPLOYED agent runs: authored, plus `tools/` and `system-prompt.md`. */
|
|
2
|
+
import deployedDef from "virtual:aai/agent";
|
|
1
3
|
import { agent, assemblyAIPipeline, DEFAULT_SYSTEM_PROMPT } from "@alexkroman1/aai";
|
|
2
4
|
import { expectDeployable } from "@alexkroman1/aai/testing";
|
|
3
5
|
import { describe, expect, test } from "vitest";
|
|
@@ -54,6 +56,26 @@ describe("quickstart-agent template", () => {
|
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
58
|
|
|
59
|
+
test("the two DISCOVERED halves are really discovered", () => {
|
|
60
|
+
// The template's central claim, and until it shipped these files there was
|
|
61
|
+
// nothing here to make it. `virtual:aai/agent` is the lowering a DEPLOYED
|
|
62
|
+
// agent gets — the authored def plus what `tools/` and `system-prompt.md`
|
|
63
|
+
// declare — so this asserts the thing the quickstart tells a reader to
|
|
64
|
+
// trust: the tool is registered by being a file, and the prompt is applied
|
|
65
|
+
// by sitting beside `agent.ts`.
|
|
66
|
+
//
|
|
67
|
+
// `deployedDef` rather than `agentDef` above: the raw export has no tools
|
|
68
|
+
// and the framework-default prompt, which is exactly what makes an
|
|
69
|
+
// assertion against it unable to see either half go missing.
|
|
70
|
+
expect(Object.keys(deployedDef.tools ?? {})).toEqual(["get_weather"]);
|
|
71
|
+
// Not "some prompt" but NOT the framework's — `system-prompt.md` is the
|
|
72
|
+
// one file an author edits first, and a prompt silently ignored produces
|
|
73
|
+
// an agent that behaves plausibly and wrongly rather than one that
|
|
74
|
+
// visibly cannot do something.
|
|
75
|
+
expect(deployedDef.systemPrompt).not.toBe(DEFAULT_SYSTEM_PROMPT);
|
|
76
|
+
expect(deployedDef.systemPrompt).toContain("get_weather");
|
|
77
|
+
});
|
|
78
|
+
|
|
57
79
|
test("write no prompt and you already have one: the SDK's voice core", () => {
|
|
58
80
|
// The other half of "declares nothing and still runs", and the one an
|
|
59
81
|
// author meets first. Built here rather than read off `agentDef`, so
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { agent } from "@alexkroman1/aai";
|
|
2
2
|
|
|
3
|
+
// The whole agent. Three files make it up and none of them imports another:
|
|
4
|
+
// this one, `system-prompt.md` beside it, and `tools/get_weather.ts` — each
|
|
5
|
+
// found by WHERE IT SITS. That is the idea the rest of the framework is built
|
|
6
|
+
// on, so it is worth seeing here before anywhere else.
|
|
7
|
+
//
|
|
3
8
|
// No providers declared: the agent runs the default all-AssemblyAI cascaded
|
|
4
|
-
// pipeline, billed to ASSEMBLYAI_API_KEY.
|
|
5
|
-
//
|
|
9
|
+
// pipeline, billed to ASSEMBLYAI_API_KEY. Declare any of stt/llm/tts to swap a
|
|
10
|
+
// single stage.
|
|
6
11
|
export default agent({
|
|
7
12
|
name: "Quickstart Assistant",
|
|
13
|
+
// One line for whoever is reading a LIST of agents — `aai list`, a registry
|
|
14
|
+
// page, the studio's picker. Never the model: what the model is told is
|
|
15
|
+
// `system-prompt.md`, beside this file.
|
|
16
|
+
description: "Looks up the current weather for any city",
|
|
17
|
+
// The first thing a caller hears. Without one the agent waits for them to
|
|
18
|
+
// speak, which on a phone call reads as a dead line.
|
|
19
|
+
greeting: "Hi — I can look up the weather anywhere. Which city?",
|
|
20
|
+
// Any name from `ASSEMBLYAI_TTS_VOICES`. It is sugar for a `tts` descriptor,
|
|
21
|
+
// so declaring `tts: assemblyAITts({ voice })` yourself is the same thing
|
|
22
|
+
// spelled out — and either one replaces only the speaking stage.
|
|
23
|
+
voice: "jane",
|
|
8
24
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
You are a friendly assistant on a voice call. Keep replies to one or two
|
|
2
|
+
sentences — a caller is listening, not reading.
|
|
3
|
+
|
|
4
|
+
Use the get_weather tool whenever someone asks what it is like somewhere, and
|
|
5
|
+
answer from what it returns rather than from memory. Round temperatures to
|
|
6
|
+
whole degrees and say the city back, so a mishearing is obvious.
|
|
7
|
+
|
|
8
|
+
If a lookup fails, say so plainly and offer to try another city.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { tool } from "@alexkroman1/aai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The two fields this tool reads out of wttr.in's JSON.
|
|
6
|
+
*
|
|
7
|
+
* Narrowed by hand rather than typed as the whole response: a tool's result is
|
|
8
|
+
* recorded in the conversation and sent to the model, so returning everything
|
|
9
|
+
* a third-party API happens to include spends context on fields nobody reads.
|
|
10
|
+
*/
|
|
11
|
+
type Wttr = {
|
|
12
|
+
current_condition?: [{ temp_F?: string; weatherDesc?: [{ value?: string }] }];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// This file IS the tool. It sits in `tools/`, so the model calls it
|
|
16
|
+
// `get_weather` — the filename and nothing else names it, and neither
|
|
17
|
+
// `agent.ts` nor any list mentions it. Adding an ability is adding a file
|
|
18
|
+
// here.
|
|
19
|
+
export default tool({
|
|
20
|
+
description: "Get the current weather for a city.",
|
|
21
|
+
inputSchema: z.object({ city: z.string().describe("City name, e.g. Denver") }),
|
|
22
|
+
// What the caller HEARS while this runs. A third-party lookup on a live call
|
|
23
|
+
// is the case the field exists for: without it the agent goes silent for as
|
|
24
|
+
// long as wttr.in takes, which sounds like a dropped call rather than like
|
|
25
|
+
// someone checking.
|
|
26
|
+
//
|
|
27
|
+
// Several entries at one moment are VARIANTS — one is drawn per call, so an
|
|
28
|
+
// agent asked about three cities does not say the same sentence three times.
|
|
29
|
+
// Different `afterMs` values are STAGES: the second line below is the one a
|
|
30
|
+
// caller hears only when the first was not enough.
|
|
31
|
+
//
|
|
32
|
+
// None of this is recorded. A hold line is heard, never written into the
|
|
33
|
+
// conversation, and never counts as the agent having spoken — so a caller
|
|
34
|
+
// who talks over one is not interrupting the reply being fetched behind it.
|
|
35
|
+
messages: {
|
|
36
|
+
start: ["Let me check that.", "One moment, checking the forecast."],
|
|
37
|
+
delayed: [{ afterMs: 4000, content: "Still waiting on the weather service." }],
|
|
38
|
+
// `role: "system"` hands the model a hint instead of a sentence: the
|
|
39
|
+
// failure is worth apologizing for in the agent's own voice, and only the
|
|
40
|
+
// model knows what the caller asked.
|
|
41
|
+
failed: [
|
|
42
|
+
{ role: "system", content: "The weather lookup failed. Apologize and offer to retry." },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
execute: async ({ city }, ctx) => {
|
|
46
|
+
// `ctx.signal` is the tool call's own deadline. Passing it means a slow
|
|
47
|
+
// service ends the FETCH rather than being waited out and then discarded,
|
|
48
|
+
// which on a live call is the difference between a short apology and a
|
|
49
|
+
// silence the caller hangs up on.
|
|
50
|
+
const res = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=j1`, {
|
|
51
|
+
signal: ctx.signal,
|
|
52
|
+
});
|
|
53
|
+
// Returned, not thrown: a tool failure the model can read is one it can
|
|
54
|
+
// apologize for out loud, which on a call beats silence.
|
|
55
|
+
if (!res.ok) return { error: `The weather service answered ${res.status}.` };
|
|
56
|
+
const now = ((await res.json()) as Wttr).current_condition?.[0];
|
|
57
|
+
return { city, tempF: now?.temp_F, conditions: now?.weatherDesc?.[0]?.value };
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -98,6 +98,10 @@ import { research } from "./shared.ts";
|
|
|
98
98
|
|
|
99
99
|
export default agent({
|
|
100
100
|
name: "Research Desk",
|
|
101
|
+
// For a reader of a LIST of agents, never for the model. It names the
|
|
102
|
+
// HANDOFF, because that is what a caller actually gets from this line: an
|
|
103
|
+
// answer later, not an answer now.
|
|
104
|
+
description: "Takes research requests over the phone and reports back when the run lands",
|
|
101
105
|
greeting: "Research desk. What would you like me to look into?",
|
|
102
106
|
systemPrompt: [
|
|
103
107
|
"You take research requests over the phone and read back results.",
|
|
@@ -69,6 +69,9 @@ const planState = (session: EvalSession) => lastStateIn(session.events(), Projec
|
|
|
69
69
|
* dialog envelope — it reads the position itself. */
|
|
70
70
|
const IdleStatus = z.object({ stage: z.string(), reads: z.string(), next: z.string() });
|
|
71
71
|
|
|
72
|
+
/** How many steps the plan has actually recorded as worked, so far this session. */
|
|
73
|
+
const workedSteps = (session: EvalSession): number => planState(session)?.done.length ?? 0;
|
|
74
|
+
|
|
72
75
|
describeEval(agentDef, (test) => {
|
|
73
76
|
test(
|
|
74
77
|
"the stage the desk reports is the flow's, not a guess at the plan",
|
|
@@ -133,6 +136,14 @@ describeEval(agentDef, (test) => {
|
|
|
133
136
|
await session.say(
|
|
134
137
|
"I want to work out whether it is cheaper to take the train or fly from London to Edinburgh next month.",
|
|
135
138
|
);
|
|
139
|
+
// One more utterance when the desk asked something instead of planning.
|
|
140
|
+
// Its brief allows a single clarifying question, so spending it is legal
|
|
141
|
+
// and the caller answering is what a real call does — without this the
|
|
142
|
+
// case failed on "called no tools" for a desk that was following its own
|
|
143
|
+
// instructions.
|
|
144
|
+
if (session.toolCalls().every((call) => call.name !== "start_plan")) {
|
|
145
|
+
await session.say("Just those two options, next month, cheapest total. Go ahead and plan.");
|
|
146
|
+
}
|
|
136
147
|
const started = session.toolCalls().find((call) => call.name === "start_plan");
|
|
137
148
|
// The whole SESSION's calls, not one turn's: the plan may be started on
|
|
138
149
|
// either utterance, and "expected undefined to be defined" says nothing
|
|
@@ -145,13 +156,24 @@ describeEval(agentDef, (test) => {
|
|
|
145
156
|
expect(planned?.objective, `start_plan answered: ${started?.result}`).toBeTruthy();
|
|
146
157
|
expect(planned?.plan.length ?? 0).toBeGreaterThan(0);
|
|
147
158
|
|
|
148
|
-
|
|
159
|
+
let worked = await session.say("Yes — work the first step now and tell me what it found.");
|
|
160
|
+
// ONE more turn when nothing landed, keyed on the OUTCOME rather than on
|
|
161
|
+
// the tool's message. A step whose `executeStep` throws is put back at the
|
|
162
|
+
// head of the plan by the tool itself, "where a retry will find it" — so a
|
|
163
|
+
// transient delegate failure is a designed-for outcome with a designed-for
|
|
164
|
+
// recovery, and on a real call the caller asking again IS the retry. Read
|
|
165
|
+
// off `done` because the two ways to get here need the same nudge: the
|
|
166
|
+
// step threw, or the desk never called it. Without this a gateway hiccup
|
|
167
|
+
// failed the case on "expected 0 to be greater than 0", naming neither.
|
|
168
|
+
if (workedSteps(session) === 0) worked = await session.say("Give that step another try.");
|
|
149
169
|
const calls = toolNames(worked.toolCalls).filter((name) => name === "work_next_step").length;
|
|
150
170
|
expect(calls, describeTurn(worked)).toBeGreaterThan(0);
|
|
151
171
|
|
|
152
172
|
const after = planState(session);
|
|
153
173
|
const done = after?.done ?? [];
|
|
154
|
-
|
|
174
|
+
// Named, because "expected 0 to be greater than 0" says nothing about WHY
|
|
175
|
+
// nothing landed — a step that threw answers here with its own sentence.
|
|
176
|
+
expect(done.length, describeToolCalls(session.toolCalls())).toBeGreaterThan(0);
|
|
155
177
|
// ONE STEP PER CALL: `work_next_step` is one execute-then-replan turn, not
|
|
156
178
|
// a loop. More steps recorded than calls made would mean the tool had run
|
|
157
179
|
// the plan to completion, leaving the caller on a silent line with no gap
|
|
@@ -15,6 +15,9 @@ import { planProjection } from "./shared.ts";
|
|
|
15
15
|
*/
|
|
16
16
|
export default agent({
|
|
17
17
|
name: "Planning Desk",
|
|
18
|
+
// For a reader of a list of agents. It says the LOOP rather than "research",
|
|
19
|
+
// because a caller who wants an answer in one turn is on the wrong line.
|
|
20
|
+
description: "Turns an objective into a plan and works it one step at a time with the caller",
|
|
18
21
|
// The plan exists before the first tool call, so a resumed connection has
|
|
19
22
|
// something to project.
|
|
20
23
|
// The plan, its progress and its revision trail, pushed after every tool call.
|
|
@@ -2,7 +2,7 @@ You are the planning desk. Someone calls with something they want to get done, a
|
|
|
2
2
|
|
|
3
3
|
How a call goes:
|
|
4
4
|
|
|
5
|
-
- Find out what they actually want first. One clarifying question is
|
|
5
|
+
- Find out what they actually want first, but only when you actually need to: if what they opened with is already clear enough to plan, call `start_plan` on it straight away. One clarifying question is the most you ever need — you are planning, not interviewing, and a question you did not have to ask costs the caller a whole turn before anything starts.
|
|
6
6
|
- Call `start_plan` with the objective, then read the steps back in one breath: "I'd do three things — check X, compare Y, then book Z. Want me to start?"
|
|
7
7
|
- Call `work_next_step` once per step, never in a loop. It does the step, searches the web where it needs to, and updates the plan from what it found.
|
|
8
8
|
- After each step, say what it found in a sentence and ask whether to carry on. That pause is the point: it is where the caller gets to change their mind.
|
|
@@ -4,10 +4,39 @@ import { callFlow, gateFor, record, retailSlot } from "./store.ts";
|
|
|
4
4
|
|
|
5
5
|
export default agent({
|
|
6
6
|
name: "Retail Support",
|
|
7
|
+
description: "Looks up orders, returns and store credit for an authenticated retail caller",
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A per-session ceiling on what the model may spend.
|
|
11
|
+
*
|
|
12
|
+
* This is the template where a budget earns its place: authentication, an
|
|
13
|
+
* order lookup and a staged change are three tool chains deep, the store's
|
|
14
|
+
* projection is large, and a caller who keeps re-asking can run a session for
|
|
15
|
+
* as long as they like. `maxSteps` bounds a REPLY and says nothing about a
|
|
16
|
+
* call — one step that sends a 100k-token context and one that sends a
|
|
17
|
+
* greeting are the same step.
|
|
18
|
+
*
|
|
19
|
+
* Tokens rather than money: a price is per-model and per-contract, and the
|
|
20
|
+
* SDK carries no table of them (see `UsageLimits`). The number here is a
|
|
21
|
+
* generous ceiling for a support call, not a target — pick yours from what
|
|
22
|
+
* `usage.updated` reports on a real conversation.
|
|
23
|
+
*
|
|
24
|
+
* Reaching it ends the session. An agent that wants a softer landing watches
|
|
25
|
+
* `usage.updated` through `agent({ events })` and says something first.
|
|
26
|
+
*
|
|
27
|
+
* **It was 200_000, and a real call reached 252,825 and ended mid-support.**
|
|
28
|
+
* This is the template with the deepest tool chains and the largest
|
|
29
|
+
* projection, so the old number was a ceiling a legitimate call could touch
|
|
30
|
+
* — and reaching it is not a soft landing, it ends the session. Raised with
|
|
31
|
+
* headroom rather than tuned: read `usage.updated` on a few real
|
|
32
|
+
* conversations and pick from that.
|
|
33
|
+
*
|
|
34
|
+
* The overshoot past whatever number is here is expected and bounded by the
|
|
35
|
+
* requests in flight: the cap is checked BEFORE each request, never
|
|
36
|
+
* mid-stream, because a limit enforced mid-sentence reads to the caller as a
|
|
37
|
+
* dropped call.
|
|
38
|
+
*/
|
|
39
|
+
usageLimits: { totalTokens: 2_000_000 },
|
|
11
40
|
|
|
12
41
|
// The store lives in one `sessionSlot` (`store.ts`), a pristine copy per
|
|
13
42
|
// session — callers must not see each other's cancellations. Nothing declares
|