@alexkroman1/aai-cli 16.1.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/_console-audio.d.ts +17 -0
- package/dist/_console-session.d.ts +70 -0
- package/dist/_deno-target.d.ts +15 -14
- package/dist/_dev-env.d.ts +19 -13
- package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-Dtp4aAlo.mjs} +26 -18
- package/dist/_dev-server.d.ts +5 -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-DXadVNsL.mjs +135 -0
- package/dist/_templates.d.ts +11 -34
- 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 +40 -16
- package/dist/console-BsyE3DyB.mjs +422 -0
- package/dist/console.d.ts +37 -0
- package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
- package/dist/deploy.d.ts +9 -0
- package/dist/{dev-Du8pCWFq.mjs → dev-BGWU2zPP.mjs} +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
- package/dist/init-CbOhyNYe.mjs +559 -0
- package/dist/init.d.ts +43 -3
- package/dist/scaffold/CLAUDE.md +161 -166
- package/dist/scaffold/package.json +6 -6
- package/dist/scaffold/vite.config.ts +29 -1
- package/dist/start.d.ts +3 -3
- package/dist/{studio-It7SRfUN.mjs → studio-BRJsw7lr.mjs} +19 -9
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
- package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
- package/dist/templates/applicant-screening-agent/agent.ts +28 -0
- package/dist/templates/applicant-screening-agent/crews.ts +4 -4
- 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.test.ts +2 -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 +3 -2
- package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
- package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
- package/dist/templates/document-redline-workflow/agent.ts +2 -0
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
- 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 +9 -2
- 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.test.ts +35 -25
- package/dist/templates/executive-inbox-agent/agent.ts +1 -0
- package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
- package/dist/templates/executive-inbox-agent/meeting.ts +3 -3
- 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/front-desk-agent/agent.eval.test.ts +174 -0
- package/dist/templates/front-desk-agent/agent.test.ts +150 -0
- package/dist/templates/front-desk-agent/agent.ts +22 -0
- package/dist/templates/front-desk-agent/shared.ts +234 -0
- package/dist/templates/front-desk-agent/system-prompt.md +13 -0
- package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
- package/dist/templates/hotel-reception-agent/agent.test.ts +3 -3
- 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 +3 -3
- 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 +57 -4
- 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.eval.test.ts +68 -2
- package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
- package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
- package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
- package/dist/templates/push-to-talk-agent/agent.ts +22 -0
- package/dist/templates/push-to-talk-agent/client.tsx +124 -0
- package/dist/templates/push-to-talk-agent/shared.ts +34 -0
- package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +91 -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.eval.test.ts +1 -1
- package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
- 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.test.ts +26 -16
- 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.eval.test.ts +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 +124 -5
- package/dist/templates/roadside-assistance-agent/agent.test.ts +39 -7
- 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 +29 -23
- 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 +7 -6
- 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 +61 -36
- package/dist/templates/topic-briefing-agent/agent.ts +4 -1
- package/dist/templates/topic-briefing-agent/shared.ts +19 -18
- 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.eval.test.ts +9 -7
- package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
- 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.test.ts +3 -1
- 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/_templates-CuP74F8D.mjs +0 -291
- package/dist/init-CY4NAXAA.mjs +0 -183
- package/dist/test-PHHv0Vj6.mjs +0 -83
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The session's state, the slot, and what the browser is shown.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* (`ctx.vector` was removed — see the root guide), and a template that needed
|
|
8
|
-
* one would be a template nobody can run. So retrieval here is term overlap
|
|
9
|
-
* with an inverse-document-frequency weight, which is genuinely worse at
|
|
10
|
-
* meaning and genuinely fine at words.
|
|
11
|
-
*
|
|
12
|
-
* That makes the corrective loop MORE valuable rather than less, which is the
|
|
13
|
-
* point worth taking away: CRAG exists because retrieval is imperfect, and a
|
|
14
|
-
* weaker retriever is exactly the case its grader and its query rewriter were
|
|
15
|
-
* designed for. A caller saying "my internet keeps dying at night" retrieves
|
|
16
|
-
* nothing useful by words alone — the rewrite step is what turns it into
|
|
17
|
-
* "evening slowdown congestion peak time" and finds D10.
|
|
4
|
+
* The knowledge base and its retriever moved to `knowledge.ts` so that
|
|
5
|
+
* `client.tsx`, which imports this module for its view, does not take the
|
|
6
|
+
* articles with it.
|
|
18
7
|
*/
|
|
19
8
|
|
|
20
9
|
import {
|
|
@@ -23,141 +12,16 @@ import {
|
|
|
23
12
|
type StateProjection,
|
|
24
13
|
sessionSlot,
|
|
25
14
|
} from "@alexkroman1/aai";
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
export interface Doc {
|
|
29
|
-
id: string;
|
|
30
|
-
title: string;
|
|
31
|
-
topic: string;
|
|
32
|
-
text: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const PRODUCT: string = knowledge.product;
|
|
36
|
-
export const DOCS: Doc[] = knowledge.docs;
|
|
37
|
-
|
|
38
|
-
export const TOPICS: string[] = [...new Set(DOCS.map((doc) => doc.topic))].sort();
|
|
39
|
-
|
|
40
|
-
// ─── Retrieval ───────────────────────────────────────────────────────────────
|
|
41
|
-
|
|
42
|
-
/** Words that match everything and therefore rank nothing. */
|
|
43
|
-
const STOPWORDS = new Set([
|
|
44
|
-
"the",
|
|
45
|
-
"and",
|
|
46
|
-
"for",
|
|
47
|
-
"you",
|
|
48
|
-
"your",
|
|
49
|
-
"are",
|
|
50
|
-
"was",
|
|
51
|
-
"with",
|
|
52
|
-
"that",
|
|
53
|
-
"this",
|
|
54
|
-
"have",
|
|
55
|
-
"has",
|
|
56
|
-
"can",
|
|
57
|
-
"not",
|
|
58
|
-
"but",
|
|
59
|
-
"how",
|
|
60
|
-
"why",
|
|
61
|
-
"what",
|
|
62
|
-
"when",
|
|
63
|
-
"will",
|
|
64
|
-
"from",
|
|
65
|
-
"into",
|
|
66
|
-
"out",
|
|
67
|
-
"get",
|
|
68
|
-
"does",
|
|
69
|
-
"did",
|
|
70
|
-
"any",
|
|
71
|
-
"all",
|
|
72
|
-
"our",
|
|
73
|
-
"their",
|
|
74
|
-
"there",
|
|
75
|
-
"then",
|
|
76
|
-
"than",
|
|
77
|
-
"about",
|
|
78
|
-
"just",
|
|
79
|
-
"been",
|
|
80
|
-
"were",
|
|
81
|
-
"they",
|
|
82
|
-
"them",
|
|
83
|
-
"his",
|
|
84
|
-
"her",
|
|
85
|
-
"its",
|
|
86
|
-
"one",
|
|
87
|
-
"two",
|
|
88
|
-
"who",
|
|
89
|
-
"whom",
|
|
90
|
-
"some",
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
function tokenize(text: string): string[] {
|
|
94
|
-
return text
|
|
95
|
-
.toLowerCase()
|
|
96
|
-
.split(/[^a-z0-9]+/)
|
|
97
|
-
.filter((word) => word.length > 2 && !STOPWORDS.has(word));
|
|
98
|
-
}
|
|
15
|
+
import { product } from "./knowledge.json" with { type: "json" };
|
|
99
16
|
|
|
100
17
|
/**
|
|
101
|
-
*
|
|
102
|
-
* occurs. Both computed once at module load, in the one pass that has to visit
|
|
103
|
-
* every token anyway.
|
|
18
|
+
* The product this desk supports.
|
|
104
19
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
20
|
+
* A NAMED import off `knowledge.json`, not a property of the whole object: the
|
|
21
|
+
* browser imports this module and must not take `docs` with it. `knowledge.ts`
|
|
22
|
+
* holds the articles.
|
|
108
23
|
*/
|
|
109
|
-
const
|
|
110
|
-
const DOC_TERM_COUNTS = new Map<string, Map<string, number>>();
|
|
111
|
-
for (const doc of DOCS) {
|
|
112
|
-
const counts = new Map<string, number>();
|
|
113
|
-
for (const token of tokenize(`${doc.title} ${doc.topic} ${doc.text}`)) {
|
|
114
|
-
counts.set(token, (counts.get(token) ?? 0) + 1);
|
|
115
|
-
}
|
|
116
|
-
DOC_TERM_COUNTS.set(doc.id, counts);
|
|
117
|
-
for (const term of counts.keys()) {
|
|
118
|
-
DOC_FREQUENCY.set(term, (DOC_FREQUENCY.get(term) ?? 0) + 1);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** How many documents one retrieval returns before grading. */
|
|
123
|
-
export const RETRIEVE_K = 4;
|
|
124
|
-
|
|
125
|
-
export interface Retrieved {
|
|
126
|
-
doc: Doc;
|
|
127
|
-
score: number;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* The `retrieve` node: top-k by idf-weighted term overlap.
|
|
132
|
-
*
|
|
133
|
-
* A term in one document is worth much more than a term in eight — without the
|
|
134
|
-
* weight, "fibre" and "hub" (in nearly every document) drown the one word that
|
|
135
|
-
* actually distinguishes the caller's question.
|
|
136
|
-
*/
|
|
137
|
-
export function retrieve(query: string, k: number = RETRIEVE_K): Retrieved[] {
|
|
138
|
-
const terms = new Set(tokenize(query));
|
|
139
|
-
if (terms.size === 0) return [];
|
|
140
|
-
const scored: Retrieved[] = [];
|
|
141
|
-
for (const doc of DOCS) {
|
|
142
|
-
const counts = DOC_TERM_COUNTS.get(doc.id);
|
|
143
|
-
let score = 0;
|
|
144
|
-
for (const term of terms) {
|
|
145
|
-
const hits = counts?.get(term) ?? 0;
|
|
146
|
-
if (hits === 0) continue;
|
|
147
|
-
const frequency = DOC_FREQUENCY.get(term) ?? 1;
|
|
148
|
-
// Diminishing returns per repeat, so one long document cannot win on
|
|
149
|
-
// repetition alone.
|
|
150
|
-
score += Math.log(1 + hits) * Math.log(DOCS.length / frequency + 1);
|
|
151
|
-
}
|
|
152
|
-
if (score > 0) scored.push({ doc, score });
|
|
153
|
-
}
|
|
154
|
-
return scored.sort((a, b) => b.score - a.score).slice(0, k);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** One document as the answer prompt sees it. */
|
|
158
|
-
export function formatDoc(doc: Doc): string {
|
|
159
|
-
return `[${doc.id}] ${doc.title}\n${doc.text}`;
|
|
160
|
-
}
|
|
24
|
+
export const PRODUCT: string = product;
|
|
161
25
|
|
|
162
26
|
// ─── The trace ───────────────────────────────────────────────────────────────
|
|
163
27
|
// Their graph is watched by streaming node names to a notebook. A caller hears
|
|
@@ -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 },
|