@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
|
@@ -28,9 +28,20 @@
|
|
|
28
28
|
* the only thing that tells a live model that "grab the rope" means
|
|
29
29
|
* `game_state_take` — an eval run against the framework default prompt measures
|
|
30
30
|
* an agent nobody deployed.
|
|
31
|
+
*
|
|
32
|
+
* The prompt is a RESOLVER (see `agent.ts`), so what a live run puts in front
|
|
33
|
+
* of the narrator is the file plus the board as it stands on that turn. That is
|
|
34
|
+
* what the state assertions below are really riding on: the narrator is never
|
|
35
|
+
* asked to remember an inventory, so a wrong answer is a game bug rather than a
|
|
36
|
+
* model lapse.
|
|
31
37
|
*/
|
|
32
38
|
import agentDef from "virtual:aai/agent";
|
|
33
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
type EvalTurn,
|
|
41
|
+
lastToolResultIn,
|
|
42
|
+
toolCallsInTurns,
|
|
43
|
+
toolResultIn,
|
|
44
|
+
} from "@alexkroman1/aai-runtime/eval";
|
|
34
45
|
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
35
46
|
import { expect } from "vitest";
|
|
36
47
|
import { z } from "zod";
|
|
@@ -135,10 +146,24 @@ describeEval(agentDef, (test) => {
|
|
|
135
146
|
test(
|
|
136
147
|
"the rank the score earned is still the player's rank a turn later",
|
|
137
148
|
async ({ session }) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
// The chalice has to be IN HAND first. The prompt's scoring rule is that a
|
|
150
|
+
// treasure CARRIED BACK to the pedestal earns points, and
|
|
151
|
+
// `game_state_drop` refuses an item the player is not holding — so asked
|
|
152
|
+
// cold, "I set the chalice down" is a drop, which is what a live model
|
|
153
|
+
// reached for twice (`game_state_drop`, then no tool at all) while this
|
|
154
|
+
// case blamed the score tool.
|
|
155
|
+
const turns = await session.sayAll([
|
|
156
|
+
"I pick up the golden chalice.",
|
|
157
|
+
"I carry the chalice back to the Cave Mouth.",
|
|
158
|
+
"I set the chalice on the stone pedestal. Award me the points for returning it.",
|
|
159
|
+
]);
|
|
160
|
+
// `lastToolResultIn` rather than `answerOf`, which is `toolResultIn` and
|
|
161
|
+
// refuses a scope holding two calls. Across three turns the narrator may
|
|
162
|
+
// well award twice — settling the return on the carry and again on the
|
|
163
|
+
// request — and the SETTLED total is the one the player was told. Reading
|
|
164
|
+
// one turn instead was the workaround, and it made this case depend on
|
|
165
|
+
// which turn the narrator chose to score on.
|
|
166
|
+
const earned = lastToolResultIn(toolCallsInTurns(turns), "game_state_score", Scored);
|
|
142
167
|
// Whatever the model awarded — a live run picks its own number — the rank
|
|
143
168
|
// that came back is the one the ladder says that score earns. The tool
|
|
144
169
|
// computes it from `rankFor` because the slot's `after` hook has not run
|
|
@@ -148,12 +173,20 @@ describeEval(agentDef, (test) => {
|
|
|
148
173
|
|
|
149
174
|
// And the SECOND turn is the only place the hook's write can be seen: the
|
|
150
175
|
// field nothing assigns is read back off a later turn's state.
|
|
151
|
-
|
|
176
|
+
// "Check the game state", not "What is my score?" — the score is in the
|
|
177
|
+
// prompt now (see `statusBlock`), so a live narrator answers that one
|
|
178
|
+
// without a tool call, and this case is about the WRITE surviving the
|
|
179
|
+
// turn rather than about which question forces a read.
|
|
180
|
+
const later = answerOf(await session.say("Check the game state."), "game_state_get", Status);
|
|
152
181
|
expect(later.score).toBe(earned.score);
|
|
153
182
|
expect(later.rank).toBe(earned.rank);
|
|
154
183
|
},
|
|
155
184
|
{
|
|
156
185
|
stubReply: [
|
|
186
|
+
{ tool: "game_state_take", args: { value: "golden chalice" } },
|
|
187
|
+
"The golden chalice is cool and heavier than it looks.",
|
|
188
|
+
{ tool: "game_state_move", args: { value: "Cave Mouth" } },
|
|
189
|
+
"You retrace your steps to the cave mouth, chalice in hand.",
|
|
157
190
|
{ tool: "game_state_score", args: { value: 30 } },
|
|
158
191
|
"The chalice settles onto the pedestal with a satisfying weight.",
|
|
159
192
|
{ tool: "game_state_get" },
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
2
2
|
import agentDef from "virtual:aai/agent";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type AgentSessionContext,
|
|
5
|
+
createSeededRandom,
|
|
6
|
+
type RandomSource,
|
|
7
|
+
type SessionEventContext,
|
|
8
|
+
} from "@alexkroman1/aai";
|
|
4
9
|
import { createToolContext, parseToolInput, toolOf, toolRunner } from "@alexkroman1/aai/testing";
|
|
5
10
|
import { isToolFailure } from "@alexkroman1/aai/utils";
|
|
6
11
|
import { describe, expect, test } from "vitest";
|
|
@@ -13,6 +18,7 @@ import {
|
|
|
13
18
|
REPORTED_HISTORY,
|
|
14
19
|
rankFor,
|
|
15
20
|
SCAVENGER_FLAG,
|
|
21
|
+
statusBlock,
|
|
16
22
|
statusLine,
|
|
17
23
|
} from "./shared.ts";
|
|
18
24
|
|
|
@@ -373,3 +379,75 @@ describe("the game is per context", () => {
|
|
|
373
379
|
expect(DEFAULT_GAME_STATE.inventory).toEqual([]);
|
|
374
380
|
});
|
|
375
381
|
});
|
|
382
|
+
|
|
383
|
+
// ─── The prompt carries the board ────────────────────────────────────────────
|
|
384
|
+
//
|
|
385
|
+
// `systemPrompt` is a RESOLVER here, not a string: `system-prompt.md` supplies
|
|
386
|
+
// the world and the voice rules, and `statusBlock` appends the live board to
|
|
387
|
+
// them before every model request. What that replaced was six lines of prompt
|
|
388
|
+
// ordering the narrator to call `game_state_get` before answering any question
|
|
389
|
+
// about where the player is or what they hold — advice, enforced by nothing,
|
|
390
|
+
// and a model round trip on every turn it was obeyed on.
|
|
391
|
+
|
|
392
|
+
describe("the prompt the narrator is actually given", () => {
|
|
393
|
+
/** The def's resolver, which is what a request assembles the instructions from. */
|
|
394
|
+
const resolve = (ctx: AgentSessionContext): string => {
|
|
395
|
+
const prompt = agentDef.systemPrompt;
|
|
396
|
+
if (typeof prompt !== "function") throw new Error("systemPrompt is not a resolver");
|
|
397
|
+
return prompt(ctx);
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
test("it is a resolver, and the file's prose survives into it", () => {
|
|
401
|
+
// The build discovers `system-prompt.md` and hands it to `withSystemPrompt`,
|
|
402
|
+
// which leaves a resolver exactly as written — so the file has to reach the
|
|
403
|
+
// model through the resolver's own import, and this is what proves it does.
|
|
404
|
+
expect(typeof agentDef.systemPrompt).toBe("function");
|
|
405
|
+
expect(resolve(createToolContext())).toContain("CAVERN ADVENTURE");
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("a fresh session is told the opening board, before any tool has run", () => {
|
|
409
|
+
const opening = resolve(createToolContext());
|
|
410
|
+
expect(opening).toContain(`- Location: ${DEFAULT_GAME_STATE.currentRoom}`);
|
|
411
|
+
expect(opening).toContain("- Score: 0 (Beginner)");
|
|
412
|
+
expect(opening).toContain("- Turns taken: 0");
|
|
413
|
+
expect(opening).toContain("- Carrying: nothing");
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("every mutation is in the NEXT request's prompt, with no tool call in between", async () => {
|
|
417
|
+
const ctx = createToolContext();
|
|
418
|
+
await run("game_state_take", { value: "lantern" }, ctx);
|
|
419
|
+
await run("game_state_move", { value: "Echoing Hall" }, ctx);
|
|
420
|
+
await run("game_state_score", { value: 30 }, ctx);
|
|
421
|
+
say("go down to the hall", ctx);
|
|
422
|
+
|
|
423
|
+
const now = resolve(ctx);
|
|
424
|
+
expect(now).toContain("- Location: Echoing Hall");
|
|
425
|
+
expect(now).toContain("- Score: 30 (Amateur Adventurer)");
|
|
426
|
+
expect(now).toContain("- Turns taken: 1");
|
|
427
|
+
expect(now).toContain("- Carrying: lantern");
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test("the block is built from the same status line the CRT and the read tool get", async () => {
|
|
431
|
+
const ctx = createToolContext();
|
|
432
|
+
await run("game_state_move", { value: "Crystal Grotto" }, ctx);
|
|
433
|
+
await run("game_state_score", { value: 60 }, ctx);
|
|
434
|
+
|
|
435
|
+
// One helper, three readers: `syncState`, `game_state_get`, and the prompt.
|
|
436
|
+
// A fourth rendering of these four numbers is a fourth thing to drift.
|
|
437
|
+
expect(resolve(ctx).endsWith(statusBlock(gameSlot.get(ctx)))).toBe(true);
|
|
438
|
+
const bar = statusLine(gameSlot.get(ctx));
|
|
439
|
+
expect(resolve(ctx)).toContain(`- Score: ${bar.score} (${bar.rank})`);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
test("each session is told its OWN board", async () => {
|
|
443
|
+
// The resolver reads through `ctx.slots`, so it is per session for the same
|
|
444
|
+
// reason every tool is — a resolver that closed over a module-level game
|
|
445
|
+
// would put one player's inventory in another player's prompt.
|
|
446
|
+
const one = createToolContext();
|
|
447
|
+
const two = createToolContext();
|
|
448
|
+
await run("game_state_take", { value: "jade idol" }, one);
|
|
449
|
+
|
|
450
|
+
expect(resolve(one)).toContain("- Carrying: jade idol");
|
|
451
|
+
expect(resolve(two)).toContain("- Carrying: nothing");
|
|
452
|
+
});
|
|
453
|
+
});
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { agent } from "@alexkroman1/aai";
|
|
2
|
-
import { gameStatus, recordTurn } from "./shared.ts";
|
|
2
|
+
import { gameSlot, gameStatus, recordTurn, statusBlock } from "./shared.ts";
|
|
3
|
+
// The prose half of the prompt. `system-prompt.md` beside this file is
|
|
4
|
+
// discovered by the build either way — importing it is what lets the resolver
|
|
5
|
+
// below compose against it, and `withSystemPrompt` then leaves the resolver
|
|
6
|
+
// exactly as written.
|
|
7
|
+
import prompt from "./system-prompt.md?raw";
|
|
3
8
|
|
|
4
9
|
export default agent({
|
|
5
10
|
name: "Cavern Adventure",
|
|
11
|
+
// The listing line — a registry row, `aai list`, the studio's picker. Never
|
|
12
|
+
// the model: the world and the voice rules are `system-prompt.md`'s.
|
|
13
|
+
description: "Runs a spoken text adventure through an underground cave system",
|
|
6
14
|
// The world exists before the first command, so a resumed connection has
|
|
7
15
|
// something to project rather than an empty state object.
|
|
8
16
|
// A narrator wants a narrative voice; everything else stays on the
|
|
@@ -20,6 +28,27 @@ export default agent({
|
|
|
20
28
|
* one the narrator was told. `syncState` sends the game's own.
|
|
21
29
|
*/
|
|
22
30
|
syncState: gameStatus,
|
|
31
|
+
/**
|
|
32
|
+
* The world's rules, plus the board as it stands RIGHT NOW.
|
|
33
|
+
*
|
|
34
|
+
* A `systemPrompt` resolver is called once per model request, so the four
|
|
35
|
+
* facts of the status line and the player's inventory are in front of the
|
|
36
|
+
* narrator on every turn — which is what makes drift impossible rather than
|
|
37
|
+
* discouraged. The prompt used to carry a section demanding a
|
|
38
|
+
* `game_state_get` call before answering any question about the board, and
|
|
39
|
+
* "never from memory": advice that cost a round trip when it was obeyed and a
|
|
40
|
+
* desynced world when it was not. Four scalars and a list are cheaper to
|
|
41
|
+
* state than to ask for.
|
|
42
|
+
*
|
|
43
|
+
* `ctx` is an `AgentSessionContext` — the session id, the env and the slots,
|
|
44
|
+
* which is everything `gameSlot.get` needs and deliberately nothing that
|
|
45
|
+
* could speak. Synchronous by contract: the request is being assembled.
|
|
46
|
+
*
|
|
47
|
+
* `game_state_get` is NOT retired by this. It answers with the flags and the
|
|
48
|
+
* recent commands too, and it is still the tool for "check the game state".
|
|
49
|
+
* What went is the compulsory read-back.
|
|
50
|
+
*/
|
|
51
|
+
systemPrompt: (ctx) => `${prompt}\n\n${statusBlock(gameSlot.get(ctx))}`,
|
|
23
52
|
// The opening scene here must agree with DEFAULT_GAME_STATE.currentRoom
|
|
24
53
|
// (shared.ts) and the world map in system-prompt.md.
|
|
25
54
|
greeting:
|
|
@@ -146,6 +146,43 @@ export function statusLine(game: FrozenGameState): StatusLine {
|
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* The board as the NARRATOR is given it, before every reply.
|
|
151
|
+
*
|
|
152
|
+
* `agent.ts` appends this to the system prompt through a `systemPrompt`
|
|
153
|
+
* resolver, so the four facts of the status line plus the inventory are in
|
|
154
|
+
* front of the model on every request — never remembered, never guessed, and
|
|
155
|
+
* never a turn behind.
|
|
156
|
+
*
|
|
157
|
+
* **This is what retired a whole section of `system-prompt.md`.** The prompt
|
|
158
|
+
* used to spend six lines insisting that ANY question about what the player is
|
|
159
|
+
* carrying, where they are or what they have scored be answered by calling
|
|
160
|
+
* `game_state_get` FIRST and never from memory — advice, enforced by nothing,
|
|
161
|
+
* costing a model round trip on the turns the narrator remembered and a drifting
|
|
162
|
+
* world on the turns it did not. State the model must not invent belongs in the
|
|
163
|
+
* prompt, not in a rule telling it to go and look.
|
|
164
|
+
*
|
|
165
|
+
* Prose rather than the JSON `game_state_get` answers with, because this is
|
|
166
|
+
* read as instructions rather than as a tool result — and built from
|
|
167
|
+
* {@link statusLine}, so the narrator, the CRT's top bar and the read tool
|
|
168
|
+
* cannot disagree about the four numbers. `game_state_get` stays for the rest of
|
|
169
|
+
* the board (the flags and the recent commands) and for the turn the narrator
|
|
170
|
+
* wants everything at once.
|
|
171
|
+
*/
|
|
172
|
+
export function statusBlock(game: FrozenGameState): string {
|
|
173
|
+
const { currentRoom, score, rank, moves } = statusLine(game);
|
|
174
|
+
const carrying = game.inventory.length > 0 ? game.inventory.join(", ") : "nothing";
|
|
175
|
+
return [
|
|
176
|
+
"CURRENT GAME STATE (the game's own record, refreshed before every reply —",
|
|
177
|
+
"it is ground truth and it is never out of date, so answer from it rather",
|
|
178
|
+
"than from memory, and never contradict it):",
|
|
179
|
+
`- Location: ${currentRoom}`,
|
|
180
|
+
`- Score: ${score} (${rank})`,
|
|
181
|
+
`- Turns taken: ${moves}`,
|
|
182
|
+
`- Carrying: ${carrying}`,
|
|
183
|
+
].join("\n");
|
|
184
|
+
}
|
|
185
|
+
|
|
149
186
|
/**
|
|
150
187
|
* The projection BOTH ends use: `syncState` on the agent, `useAgentState` in
|
|
151
188
|
* the client.
|
|
@@ -29,11 +29,18 @@ COMMAND INTERPRETATION:
|
|
|
29
29
|
- "what do I have" / "check my stuff" / "inventory" = inventory
|
|
30
30
|
- "where am I" / "look around" / "describe the room" = look
|
|
31
31
|
- "hit the troll" / "fight the troll" / "attack troll" = attack troll with pick
|
|
32
|
-
- "what's my score" =
|
|
32
|
+
- "what's my score" / "how am I doing" = answer from the CURRENT GAME STATE block, never game_state_score — that one AWARDS points
|
|
33
|
+
- "check the game state" / "full status" = game_state_get, which adds the game
|
|
34
|
+
flags and the last few commands to what you already have
|
|
33
35
|
- "start over" / "new game" / "restart" = restart
|
|
34
36
|
- Accept natural conversational commands and map them to game actions
|
|
37
|
+
- EARNING points is not a question and is never game_state_get. A treasure
|
|
38
|
+
carried back to the pedestal is game_state_score, which adds them; reach for
|
|
39
|
+
it whenever the player has just done something the score should move for
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
The CURRENT GAME STATE block at the end of these instructions is the game's own record, refreshed before every reply: where the player is, their score and rank, the turn count, and what they are carrying. It is never out of date. Answer from it, never say anything that contradicts it, and never spend a turn asking a tool for what it already tells you.
|
|
42
|
+
|
|
43
|
+
The tools are how you CHANGE the world: game_state_move to change rooms, game_state_take to pick up items, game_state_drop to drop items — it refuses an item the player is not carrying, and answers whether the scavenger made off with the one they dropped — game_state_score to add points, which answers with the new total and the player's rank, and game_state_flag to set game flags. Always call one when the player takes an item, moves rooms, or triggers an event. game_state_get is the one read left, and it is for the rest of the board — the game flags and the last few commands. You do not log commands or count moves — the game does that for you on every turn. When the player asks to restart, quit, or start a new game, call game_state_restart, then narrate the opening scene again.
|
|
37
44
|
|
|
38
45
|
ATMOSPHERE:
|
|
39
46
|
- Underground areas should feel dark and foreboding with the lantern lit, and terrifying in pitch blackness
|
|
@@ -86,11 +86,14 @@ const EmptyRecap = z.object({
|
|
|
86
86
|
|
|
87
87
|
/** What `verify_claim` answers with. */
|
|
88
88
|
// `verdict` is the parsed WORD now, so the eval can pin the enum rather than
|
|
89
|
-
// asserting a sentence is non-empty. `null` is the unaccepted case
|
|
89
|
+
// asserting a sentence is non-empty. `null` is the unaccepted case, and it
|
|
90
|
+
// arrives WITH `unusable` — the tool's own name for a checker that never
|
|
91
|
+
// returned its schema.
|
|
90
92
|
const Verdict = z.object({
|
|
91
93
|
claim: z.string(),
|
|
92
94
|
verdict: z.enum(["confirmed", "contradicted", "unclear"]).nullable(),
|
|
93
95
|
detail: z.string(),
|
|
96
|
+
unusable: z.string().optional(),
|
|
94
97
|
});
|
|
95
98
|
|
|
96
99
|
describeEval(agentDef, (test) => {
|
|
@@ -174,9 +177,20 @@ describeEval(agentDef, (test) => {
|
|
|
174
177
|
expect(calls, describeTurn(turn)).toHaveLength(1);
|
|
175
178
|
const verdict = toolResultIn(turn.toolCalls, "verify_claim", Verdict);
|
|
176
179
|
expect(countWords(verdict.claim)).toBeGreaterThan(3);
|
|
177
|
-
// A word the desk can act on, not a sentence it must read one out of
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
// A word the desk can act on, not a sentence it must read one out of —
|
|
181
|
+
// or the honest unresolved path, which is the SAME contract seen from the
|
|
182
|
+
// other side. `factChecker` is a cheap model on `maxSteps: 2`, so a run
|
|
183
|
+
// that spends both steps searching returns no schema and the tool reports
|
|
184
|
+
// `unusable` rather than a verdict — which its own body argues is "not a
|
|
185
|
+
// failure". Demanding a verdict every time made this case a coin toss on
|
|
186
|
+
// that budget instead of a reading of whether the desk CHECKED rather
|
|
187
|
+
// than defended, which is what its name claims and what the `toHaveLength`
|
|
188
|
+
// above actually measures.
|
|
189
|
+
if (verdict.verdict === null) {
|
|
190
|
+
expect(verdict.unusable, describeTurn(turn)).toBeDefined();
|
|
191
|
+
} else {
|
|
192
|
+
expect(countWords(verdict.detail)).toBeGreaterThan(2);
|
|
193
|
+
}
|
|
180
194
|
expect(toolNames(turn.toolCalls).filter((name) => !DESK_TOOLS.includes(name))).toEqual([]);
|
|
181
195
|
},
|
|
182
196
|
{ live: true },
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type StubDelegateCall,
|
|
6
6
|
scriptedToolContext,
|
|
7
7
|
stubDelegate,
|
|
8
|
+
toolOf,
|
|
8
9
|
toolRunner,
|
|
9
10
|
} from "@alexkroman1/aai/testing";
|
|
10
11
|
import { installStubStepFetch } from "@alexkroman1/aai/testing/vitest";
|
|
@@ -88,12 +89,12 @@ describe("the desk itself", () => {
|
|
|
88
89
|
expect(factChecker.maxSteps).toBeLessThan(MAX_RESEARCH_STEPS);
|
|
89
90
|
});
|
|
90
91
|
|
|
91
|
-
test("runs the three NARROW
|
|
92
|
+
test("runs the three NARROW subagents somewhere cheaper, and the researcher on the default", () => {
|
|
92
93
|
// The other half of the budget split, and the reason `CHEAP_MODEL` is one
|
|
93
|
-
// constant: three
|
|
94
|
+
// constant: three subagents that were each meant to be cheap, one of
|
|
94
95
|
// which quietly is not, is a bill nobody can read.
|
|
95
|
-
for (const
|
|
96
|
-
expect(
|
|
96
|
+
for (const one of [factChecker, explainer, counterpoint]) {
|
|
97
|
+
expect(one.llm, one.name).toMatchObject({ options: { model: CHEAP_MODEL } });
|
|
97
98
|
}
|
|
98
99
|
// The researcher reads whole pages and stays on the agent's own model.
|
|
99
100
|
expect(researcher.llm).toBeUndefined();
|
|
@@ -104,25 +105,25 @@ describe("the desk itself", () => {
|
|
|
104
105
|
// rather than a paragraph somebody remembered to write: the desk reads the
|
|
105
106
|
// final message and nothing else. A subagent added here without one is the
|
|
106
107
|
// regression this catches.
|
|
107
|
-
for (const
|
|
108
|
-
expect(
|
|
108
|
+
for (const one of [researcher, factChecker, explainer, counterpoint]) {
|
|
109
|
+
expect(one.expectedOutput, one.name).toBeTruthy();
|
|
109
110
|
}
|
|
110
111
|
expect(researcher.expectedOutput).toMatch(/only this/);
|
|
111
112
|
});
|
|
112
113
|
|
|
113
|
-
test("puts on the roster exactly the
|
|
114
|
+
test("puts on the roster exactly the subagents chosen by what the caller ASKED", () => {
|
|
114
115
|
// The two tools name their own subagent, so those two must NOT be on the
|
|
115
|
-
// roster: a
|
|
116
|
+
// roster: a subagent reachable both ways gives the model a second, worse
|
|
116
117
|
// route to a tool that does real work around the delegation.
|
|
117
118
|
expect(authoredAgent.subagents?.map((one) => one.name)).toEqual(["explainer", "counterpoint"]);
|
|
118
|
-
for (const
|
|
119
|
+
for (const one of authoredAgent.subagents ?? []) {
|
|
119
120
|
// The only thing the router reads. `agent()` refuses a roster without it;
|
|
120
121
|
// asserted here too because the template is what an author copies.
|
|
121
|
-
expect(
|
|
122
|
+
expect(one.description, one.name).toBeTruthy();
|
|
122
123
|
}
|
|
123
124
|
});
|
|
124
125
|
|
|
125
|
-
test("publishes the roster as one delegate tool listing both
|
|
126
|
+
test("publishes the roster as one delegate tool listing both subagents", () => {
|
|
126
127
|
const delegate = deployed.tools[DELEGATE_TOOL_NAME];
|
|
127
128
|
expect(delegate).toBeDefined();
|
|
128
129
|
expect(delegate?.description).toContain("explainer:");
|
|
@@ -622,6 +623,17 @@ describe("send_briefing", () => {
|
|
|
622
623
|
expect(posted.calls).toEqual([]);
|
|
623
624
|
});
|
|
624
625
|
|
|
626
|
+
test("declares onError, so a missing webhook is FATAL rather than something to retry", () => {
|
|
627
|
+
// Without it the runtime hands every throw to the model as this call's
|
|
628
|
+
// result, and the desk re-calls `send_briefing` against a variable that is
|
|
629
|
+
// still unset — burning the reply's step budget on a deploy fault. The
|
|
630
|
+
// handler re-throws, which is how a tool says "stop, this cannot work".
|
|
631
|
+
const sender = toolOf(deployed, "send_briefing");
|
|
632
|
+
expect(sender.onError).toBeDefined();
|
|
633
|
+
const cause = new Error(`Missing required environment variable: ${DESTINATION_ENV}`);
|
|
634
|
+
expect(() => sender.onError?.(cause, createToolContext())).toThrow(cause);
|
|
635
|
+
});
|
|
636
|
+
|
|
625
637
|
test("refuses a configured destination that is not Slack, without posting", async () => {
|
|
626
638
|
const posted = installStubStepFetch(() => ({ body: "ok" }));
|
|
627
639
|
const ctx = deskWithBoard({ [DESTINATION_ENV]: "https://example.test/collect" });
|
|
@@ -26,7 +26,7 @@ import { roster } from "./shared.ts";
|
|
|
26
26
|
* is for the case where the choice is the caller's — "what does curtailment
|
|
27
27
|
* mean" wants the explainer and "who says otherwise" wants the counterpoint,
|
|
28
28
|
* and nothing but the question tells them apart. It reaches the model as one
|
|
29
|
-
* `delegate` tool listing both, so a third
|
|
29
|
+
* `delegate` tool listing both, so a third subagent is a line here rather
|
|
30
30
|
* than a fourth file in `tools/` whose body is one `ctx.delegate` call.
|
|
31
31
|
*
|
|
32
32
|
* Compare `web-research-agent`, which gives the search builtins to the agent
|
|
@@ -35,6 +35,9 @@ import { roster } from "./shared.ts";
|
|
|
35
35
|
*/
|
|
36
36
|
export default agent({
|
|
37
37
|
name: "Briefing Desk",
|
|
38
|
+
// The listing line — a registry row, the studio's picker. "At once" is the
|
|
39
|
+
// part worth a reader's attention: it is what the subagents below buy.
|
|
40
|
+
description: "Researches a subject from several angles at once and reads back what was found",
|
|
38
41
|
greeting:
|
|
39
42
|
"Briefing desk. Tell me a subject and I'll put a few researchers on it — " +
|
|
40
43
|
"try something like, what's going on with home battery prices.",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
* a roster can express.
|
|
28
28
|
* - `explainer` and `counterpoint` are on the ROSTER (`agent({ subagents })`),
|
|
29
29
|
* because choosing between them IS reading what the caller asked: "what does
|
|
30
|
-
* curtailment mean" and "who says otherwise" want different
|
|
30
|
+
* curtailment mean" and "who says otherwise" want different subagents and
|
|
31
31
|
* nothing else about them differs. They reach the model as one `delegate`
|
|
32
|
-
* tool whose `
|
|
32
|
+
* tool whose `subagent` argument is the two names, described by their own
|
|
33
33
|
* {@link SubagentDef.description}s.
|
|
34
34
|
*
|
|
35
35
|
* The rule that follows: **name a subagent in code when the tool IS the choice;
|
|
@@ -56,18 +56,18 @@ import { type AssemblyAIGatewayModel, assemblyAILlm } from "@alexkroman1/aai/llm
|
|
|
56
56
|
import { z } from "zod";
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* The model the three NARROW
|
|
59
|
+
* The model the three NARROW subagents share.
|
|
60
60
|
*
|
|
61
61
|
* Named once because it is a fact about the DESK — checking one sentence,
|
|
62
62
|
* defining one word and finding one objection are not the job `researcher`
|
|
63
63
|
* does, so all three run somewhere cheaper — and each subagent still declares
|
|
64
|
-
* its own `llm`, because which model a
|
|
65
|
-
* declaring a
|
|
64
|
+
* its own `llm`, because which model a subagent runs on is part of what
|
|
65
|
+
* declaring a subagent means.
|
|
66
66
|
*
|
|
67
67
|
* Annotated as {@link AssemblyAIGatewayModel} rather than left as three string
|
|
68
68
|
* literals: `AssemblyAILlmOptions.model` widens to `string` so the gateway
|
|
69
69
|
* accepts a name it has never heard of, and a typo in one of three copies is a
|
|
70
|
-
* refusal from ONE
|
|
70
|
+
* refusal from ONE subagent while the other two answer — the hardest shape of
|
|
71
71
|
* failure to notice on a live call. Here it is a compile error.
|
|
72
72
|
*/
|
|
73
73
|
export const CHEAP_MODEL: AssemblyAIGatewayModel = "gemini-2.5-flash-lite";
|
|
@@ -171,7 +171,7 @@ export const factChecker: TypedSubagentDef<Verdict> = subagent({
|
|
|
171
171
|
});
|
|
172
172
|
|
|
173
173
|
/**
|
|
174
|
-
* The ROSTER's first
|
|
174
|
+
* The ROSTER's first subagent: what a word means.
|
|
175
175
|
*
|
|
176
176
|
* No tools at all, which is legal and is the point — a definition is a
|
|
177
177
|
* reasoning pass, and giving this one a search would let it wander off into
|
|
@@ -203,7 +203,7 @@ export const explainer = subagent({
|
|
|
203
203
|
* Searches, like the fact-checker, and is told to do a different job with the
|
|
204
204
|
* results — which is exactly the case a roster is for. Nothing about
|
|
205
205
|
* `counterpoint` differs from `explainer` except what the caller wanted, so a
|
|
206
|
-
* tool file per
|
|
206
|
+
* tool file per subagent would be two bodies differing in one identifier.
|
|
207
207
|
*/
|
|
208
208
|
export const counterpoint = subagent({
|
|
209
209
|
name: "counterpoint",
|
|
@@ -223,13 +223,13 @@ export const counterpoint = subagent({
|
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
/**
|
|
226
|
-
* The roster `agent({ subagents })` publishes — the
|
|
226
|
+
* The roster `agent({ subagents })` publishes — the subagents the MODEL picks
|
|
227
227
|
* between.
|
|
228
228
|
*
|
|
229
229
|
* Declared here rather than inline in `agent.ts` so that membership sits beside
|
|
230
230
|
* the definitions, which is where the question "should this one be routable?"
|
|
231
231
|
* gets answered. `researcher` and `factChecker` are deliberately absent: each is
|
|
232
|
-
* reached by a tool that does real work around the delegation, and a
|
|
232
|
+
* reached by a tool that does real work around the delegation, and a subagent
|
|
233
233
|
* reachable both ways gives the model a second, worse route to it.
|
|
234
234
|
*/
|
|
235
235
|
export const roster: SubagentRoster = [explainer, counterpoint];
|
|
@@ -5,7 +5,7 @@ and you have a small team of researchers you can put on it.
|
|
|
5
5
|
|
|
6
6
|
- You have no way to look anything up yourself. Everything you know about the
|
|
7
7
|
outside world comes back from `research_topic`, `verify_claim` or `delegate`.
|
|
8
|
-
- `delegate` hands one question to a
|
|
8
|
+
- `delegate` hands one question to a subagent: the explainer for "what does
|
|
9
9
|
that word mean", the counterpoint for "who says otherwise". Use it for a
|
|
10
10
|
question that stands on its own — a subject worth several angles is
|
|
11
11
|
`research_topic`, and a fact to check is `verify_claim`.
|
|
@@ -16,13 +16,16 @@ and you have a small team of researchers you can put on it.
|
|
|
16
16
|
- Each angle must stand on its own. A researcher has not heard this call and
|
|
17
17
|
cannot see the others' work, so "the same but for Europe" is not an angle;
|
|
18
18
|
"how European home battery prices moved in 2025" is.
|
|
19
|
-
-
|
|
20
|
-
|
|
19
|
+
- Call the tool BEFORE you say anything about it. Speaking ends your turn, so
|
|
20
|
+
"let me look that up" with no result behind it is a promise you never keep —
|
|
21
|
+
the caller hears it, the researchers never run, and the next thing they say
|
|
22
|
+
has to prompt you all over again. Report what came back, never what you are
|
|
23
|
+
about to do.
|
|
21
24
|
- `send_briefing` posts what is on the board to the team's channel. Offer it
|
|
22
25
|
when the caller wants the briefing in writing or wants it passed on to
|
|
23
|
-
someone who was not on the call, and
|
|
24
|
-
it
|
|
25
|
-
|
|
26
|
+
someone who was not on the call, and call it before you say it has gone. If
|
|
27
|
+
it comes back refusing, say plainly that it has not sent — never let them
|
|
28
|
+
hang up believing it did.
|
|
26
29
|
|
|
27
30
|
## How you talk
|
|
28
31
|
|
|
@@ -37,8 +40,10 @@ and you have a small team of researchers you can put on it.
|
|
|
37
40
|
- If the caller pushes back on a fact, check it with `verify_claim` rather than
|
|
38
41
|
defending it. If it comes back contradicted, correct yourself plainly. If it
|
|
39
42
|
comes back `unusable`, say it is unresolved — do not round it up to confirmed.
|
|
40
|
-
- `briefing_so_far` is for a recap. It costs nothing, so
|
|
41
|
-
|
|
43
|
+
- `briefing_so_far` is for a recap. It costs nothing, so ALWAYS call it when
|
|
44
|
+
the caller asks what you have — including when you believe the board is
|
|
45
|
+
empty. Reciting "nothing yet" from memory is the same mistake as reciting a
|
|
46
|
+
finding from memory: the board is the record, not your recollection of it.
|
|
42
47
|
|
|
43
48
|
## What not to do
|
|
44
49
|
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
errorMessage,
|
|
3
|
+
isToolFailure,
|
|
4
|
+
requireEnv,
|
|
5
|
+
type ToolErrorHandler,
|
|
6
|
+
toolFailure,
|
|
7
|
+
} from "@alexkroman1/aai";
|
|
2
8
|
import { ChannelDeliveryError, sendToChannel } from "@alexkroman1/aai/channels";
|
|
3
9
|
import { z } from "zod";
|
|
4
10
|
import { briefingSlot } from "../shared.ts";
|
|
5
11
|
import { briefingChannel, briefingMessage, DESTINATION_ENV } from "../slack.ts";
|
|
6
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Anything that reaches here is a deploy nobody finished or a bug in this file
|
|
15
|
+
* — see the note on the tool below — and neither is fixed by asking the model
|
|
16
|
+
* to try again, so it goes back up as a fatal failure.
|
|
17
|
+
*
|
|
18
|
+
* Named, with its type spelled, because the type is what says what the two
|
|
19
|
+
* outcomes are: RETURN a `ToolFailure` (or a string) and the model reads it and
|
|
20
|
+
* carries on; THROW and the call ends without an answer.
|
|
21
|
+
*/
|
|
22
|
+
const unfinishedDeployIsFatal: ToolErrorHandler = (err) => {
|
|
23
|
+
throw err;
|
|
24
|
+
};
|
|
25
|
+
|
|
7
26
|
/**
|
|
8
27
|
* Post the board to the desk's Slack channel, so the briefing outlives the
|
|
9
28
|
* call.
|
|
@@ -24,10 +43,24 @@ import { briefingChannel, briefingMessage, DESTINATION_ENV } from "../slack.ts";
|
|
|
24
43
|
* the one deliberate throw in this template. A missing key is not a refusal the
|
|
25
44
|
* desk can talk its way around and not something the caller did — it is a
|
|
26
45
|
* deploy nobody finished — so the SDK's own message names the variable and how
|
|
27
|
-
* to set it
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
46
|
+
* to set it. Everything a call CAN recover from is a `ToolFailure` below.
|
|
47
|
+
*
|
|
48
|
+
* **And `onError` is what makes that throw mean something.** Without it the
|
|
49
|
+
* runtime hands every exception to the model as this call's result, so a
|
|
50
|
+
* webhook nobody configured reads as an ordinary hiccup: the desk apologises,
|
|
51
|
+
* calls `send_briefing` again, gets the same sentence, and spends the reply's
|
|
52
|
+
* whole `maxSteps` budget on a variable that will still be unset on the next
|
|
53
|
+
* attempt. Re-throwing declares the failure FATAL — the call rejects, the model
|
|
54
|
+
* is handed nothing to retry against, and the runtime reports it as a `tool`
|
|
55
|
+
* session error where whoever deployed this can see it.
|
|
56
|
+
*
|
|
57
|
+
* **Blanket, and only because of the shape of this body.** Every failure the
|
|
58
|
+
* desk can talk about is RETURNED above and below — the empty board, a
|
|
59
|
+
* destination that is not Slack, both halves of a `ChannelDeliveryError` — so
|
|
60
|
+
* anything that reaches `onError` here is a deploy that is not finished or a
|
|
61
|
+
* bug in this file, and neither is fixed by asking the model to try again. A
|
|
62
|
+
* tool whose body can throw for a transient reason should classify instead:
|
|
63
|
+
* return a `ToolFailure` for the recoverable throws and re-throw only the rest.
|
|
31
64
|
*/
|
|
32
65
|
export default briefingSlot.tool({
|
|
33
66
|
description:
|
|
@@ -74,4 +107,9 @@ export default briefingSlot.tool({
|
|
|
74
107
|
"the briefing back out — they have it in writing now.",
|
|
75
108
|
};
|
|
76
109
|
},
|
|
110
|
+
// See the note above: the only throw this body has is `requireEnv`'s, and a
|
|
111
|
+
// missing webhook is unfixable from inside the call. Re-throwing keeps the
|
|
112
|
+
// SDK's own message — which names the variable and how to set it — as the
|
|
113
|
+
// fatal error's `cause`.
|
|
114
|
+
onError: unfinishedDeployIsFatal,
|
|
77
115
|
});
|
|
@@ -178,6 +178,9 @@ export const transcribeBatch = workflow({
|
|
|
178
178
|
|
|
179
179
|
export default workflowApp({
|
|
180
180
|
name: "Transcription Desk",
|
|
181
|
+
// The listing line. It names all THREE routes because choosing between them
|
|
182
|
+
// is the product.
|
|
183
|
+
description: "Transcribes a recording three ways: chunked, streaming while it uploads, or batch",
|
|
181
184
|
workflows: { transcribe, transcribeStream, transcribeBatch },
|
|
182
185
|
// Checked at deploy time, so a missing key is a warning naming it rather than
|
|
183
186
|
// a run that fails on its second step.
|
|
@@ -29,6 +29,10 @@ import { gateFlow, tripProjection } from "./shared.ts";
|
|
|
29
29
|
*/
|
|
30
30
|
export default agent({
|
|
31
31
|
name: "Swiss Air Concierge",
|
|
32
|
+
// What the desk does, for whoever is reading a list of agents. It names the
|
|
33
|
+
// four specialists as the four things a caller can ask for, which is how a
|
|
34
|
+
// caller would say it and how the dialog stack is organised.
|
|
35
|
+
description: "Changes flights, hotels, car rentals and excursions for a booked traveller",
|
|
32
36
|
// The stack, the ticket and the itinerary exist before the first tool call,
|
|
33
37
|
// so a resumed connection has something to project.
|
|
34
38
|
// One projection replaces a `ctx.send` in each of eleven tools — and is the
|