@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
|
@@ -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,
|
|
@@ -126,10 +127,9 @@ describe("medication-safety-agent template", () => {
|
|
|
126
127
|
const builtins = expectDeployable(agentDef).builtinTools ?? [];
|
|
127
128
|
|
|
128
129
|
// Asserted on the CONFIG rather than the def because that is what a deploy
|
|
129
|
-
// ships, and because `
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
// with a prompt rule addressed to nothing. Adding builtins beside these
|
|
130
|
+
// ships, and because setting `builtinTools` REPLACES the default: nothing
|
|
131
|
+
// but `think` comes back on its own. So a dropped entry is not a quieter
|
|
132
|
+
// Dr. Sage — it is the same one with a prompt rule addressed to nothing. Adding builtins beside these
|
|
133
133
|
// three is an ordinary edit; losing one is the regression.
|
|
134
134
|
//
|
|
135
135
|
// `run_code` is the arithmetic rule's only mechanism (a BMI or a
|
|
@@ -297,3 +297,56 @@ describe("fda.ts helpers", () => {
|
|
|
297
297
|
expect(excerptAround("warfarin", "warfarin")).toBe("warfarin");
|
|
298
298
|
});
|
|
299
299
|
});
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The output guardrail, driven the way the runtime drives it.
|
|
303
|
+
*
|
|
304
|
+
* It is a plain function of the reply text, so a spec can run it with no model,
|
|
305
|
+
* no session and no network — which is most of the reason to write this rule as
|
|
306
|
+
* a declaration rather than as another line in `system-prompt.md`. A prompt rule
|
|
307
|
+
* can only be tested by asking a model and hoping; this one has an answer.
|
|
308
|
+
*
|
|
309
|
+
* `createToolContext()` stands in for the `AgentSessionContext` the runtime
|
|
310
|
+
* passes second. This check reads only the text, but a guardrail that counted
|
|
311
|
+
* strikes in `ctx.slots` would be driven exactly the same way.
|
|
312
|
+
*
|
|
313
|
+
* Asserted on the DEF and not on `expectDeployable`'s config: a guardrail is a
|
|
314
|
+
* function, so nothing about it goes on the wire.
|
|
315
|
+
*/
|
|
316
|
+
describe("the dose guardrail", () => {
|
|
317
|
+
const judge = async (text: string) => {
|
|
318
|
+
const [check] = agentDef.outputGuardrails ?? [];
|
|
319
|
+
// Not a fallback to `true`: a spec whose subject is that a check EXISTS has
|
|
320
|
+
// to fail when it has gone, rather than pass by default.
|
|
321
|
+
if (!check) throw new Error("Dr. Sage declares no output guardrail.");
|
|
322
|
+
return await check(text, createToolContext());
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
test("a reply carrying a dose is never spoken — the caller hears the refusal instead", async () => {
|
|
326
|
+
// A string verdict IS what is said, in place of the reply; there is no
|
|
327
|
+
// rewrite and no second turn. So the claim is about the sentence a caller
|
|
328
|
+
// hears, not about a flag.
|
|
329
|
+
expect(await judge("Take 200 mg of ibuprofen every six hours.")).toContain("pharmacist");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("an answer with no amount in it passes through untouched", async () => {
|
|
333
|
+
expect(await judge("Ibuprofen can upset your stomach — take it with food.")).toBe(true);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("a label QUOTE is refused too, which is the over-block this agent accepts", async () => {
|
|
337
|
+
// `medication_lookup` hands back label text verbatim and label text is full
|
|
338
|
+
// of "200 mg tablets", so this is not a corner case — it is the common one.
|
|
339
|
+
// Over-blocking is the safe direction here: the caller is told to ask a
|
|
340
|
+
// pharmacist, which is the answer the brief wanted anyway.
|
|
341
|
+
expect(await judge("The label says it comes in 200 mg tablets.")).toContain("pharmacist");
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("every unit an openFDA label writes doses in is covered", async () => {
|
|
345
|
+
// The pattern is not a dose parser and does not try to be. What it owes is
|
|
346
|
+
// the units that actually appear on a label — a gap here is a dose spoken
|
|
347
|
+
// out loud, which is the one thing this agent must not do.
|
|
348
|
+
const doses = ["500mg", "1.5 mL", "50 mcg", "2 g", "400 IU", "10 units"];
|
|
349
|
+
const verdicts = await Promise.all(doses.map((dose) => judge(`Take ${dose}.`)));
|
|
350
|
+
expect(verdicts.map((verdict) => verdict === true)).toEqual(doses.map(() => false));
|
|
351
|
+
});
|
|
352
|
+
});
|
|
@@ -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.",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
2
2
|
import agentDef from "virtual:aai/agent";
|
|
3
|
-
import type { SessionEvent } from "@alexkroman1/aai
|
|
3
|
+
import type { SessionEvent } from "@alexkroman1/aai";
|
|
4
4
|
// An EVAL: does the order-taker actually take the order?
|
|
5
5
|
//
|
|
6
6
|
// `agent.test.ts` drives the six tools directly, which settles what each one
|
|
@@ -13,7 +13,14 @@ import type { SessionEvent } from "@alexkroman1/aai/protocol";
|
|
|
13
13
|
// SCRIPTED model (its `stubReply`), which still boots this agent, still
|
|
14
14
|
// resolves `tools/`, and still executes the tool a script names — so a stub run
|
|
15
15
|
// proves the wiring and proves nothing about what the agent chose.
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
lastStateIn,
|
|
18
|
+
lastToolResultIn,
|
|
19
|
+
statesIn,
|
|
20
|
+
toolNames,
|
|
21
|
+
toolResultIn,
|
|
22
|
+
} from "@alexkroman1/aai-runtime/eval";
|
|
23
|
+
import { evalSimulation } from "@alexkroman1/aai-runtime/eval/simulate";
|
|
17
24
|
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
18
25
|
import { expect } from "vitest";
|
|
19
26
|
import { z } from "zod";
|
|
@@ -158,4 +165,63 @@ describeEval(agentDef, (test) => {
|
|
|
158
165
|
},
|
|
159
166
|
{ stubReply: [{ tool: "place_order" }, "There's nothing in your order yet."] },
|
|
160
167
|
);
|
|
168
|
+
|
|
169
|
+
test(
|
|
170
|
+
"a simulated caller orders a pizza and gets it placed",
|
|
171
|
+
async ({ session, mode }) => {
|
|
172
|
+
// Every case above is one line the test author wrote. A real order is a
|
|
173
|
+
// few turns the CALLER steers: they name the pizza, maybe forget the
|
|
174
|
+
// crust, and say when they are done. A second model plays that caller,
|
|
175
|
+
// so what is under test is whether the order survives a conversation
|
|
176
|
+
// nobody scripted — the cart in the slot, across however many turns it
|
|
177
|
+
// took. Keyless, the caller and the judge are scripted too, and the case
|
|
178
|
+
// proves the loop is wired and nothing else.
|
|
179
|
+
const { simulate, judge } = evalSimulation({
|
|
180
|
+
agent: agentDef,
|
|
181
|
+
mode,
|
|
182
|
+
target: session,
|
|
183
|
+
stubCaller: [
|
|
184
|
+
"Hi, can I get a large pepperoni pizza, regular crust?",
|
|
185
|
+
"That's everything, please place the order.",
|
|
186
|
+
{ tool: "end_call", args: { reason: "order placed" } },
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
const call = await simulate({
|
|
190
|
+
persona: "a hungry customer calling a pizza shop, who answers in short sentences",
|
|
191
|
+
goal:
|
|
192
|
+
"order exactly one large pepperoni pizza on regular crust, then have the order " +
|
|
193
|
+
"placed and hear the order number",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(call.endedBy, call.transcript()).toBe("caller");
|
|
197
|
+
// Deterministic first: the pizza the caller wanted went into the cart,
|
|
198
|
+
// and the order that was placed had it in it. `place_order` resets the
|
|
199
|
+
// cart it read, so its RESULT is where the placed order is on record.
|
|
200
|
+
const calls = call.metrics.toolCalls;
|
|
201
|
+
const added = calls.filter((c) => c.name === "add_pizza");
|
|
202
|
+
expect(added.length, call.transcript()).toBeGreaterThan(0);
|
|
203
|
+
expect(added.at(-1)?.args).toMatchObject({ size: "large" });
|
|
204
|
+
const placed = z.object({ orderNumber: z.number(), pizzas: z.number(), total: z.string() });
|
|
205
|
+
expect(lastToolResultIn(calls, "place_order", placed).pizzas).toBe(1);
|
|
206
|
+
|
|
207
|
+
// What the tool results cannot show is what the caller HEARD. The prompt
|
|
208
|
+
// says every price comes from a tool and every change is confirmed.
|
|
209
|
+
const verdict = await judge(call, [
|
|
210
|
+
"The agent confirmed the pizza it added (size and toppings) back to the caller.",
|
|
211
|
+
"After placing the order, the agent told the caller an order number.",
|
|
212
|
+
]);
|
|
213
|
+
expect(verdict.pass, verdict.explain()).toBe(true);
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
stubReply: [
|
|
217
|
+
{
|
|
218
|
+
tool: "add_pizza",
|
|
219
|
+
args: { size: "large", crust: "regular", toppings: ["pepperoni"], quantity: 1 },
|
|
220
|
+
},
|
|
221
|
+
"Added a large pepperoni on regular crust. Anything else?",
|
|
222
|
+
{ tool: "place_order" },
|
|
223
|
+
"Your order is placed. It should be ready in about twenty minutes.",
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
);
|
|
161
227
|
});
|
|
@@ -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
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// An EVAL: does Field Notes write down what was dictated — once, in the
|
|
2
|
+
// caller's words — and read it back when asked? Run it with `aai eval`.
|
|
3
|
+
//
|
|
4
|
+
// `agent.test.ts` settles what the two tools do with the arguments they are
|
|
5
|
+
// handed. What only a model can settle is whether a held turn becomes ONE
|
|
6
|
+
// `save_note` call carrying the whole note, rather than a reply to its first
|
|
7
|
+
// half. Each `session.say()` here is one press of the button: the harness
|
|
8
|
+
// frames it with the same `user_turn_start` / `user_turn_commit` pair the
|
|
9
|
+
// page's `usePushToTalk()` sends, because a `turnDetection: "manual"` agent
|
|
10
|
+
// answers nothing that was not released.
|
|
11
|
+
//
|
|
12
|
+
// Without a provider key every case runs against a SCRIPTED model (its
|
|
13
|
+
// `stubReply`): the real session, the real slot, the real tools, a fake reply.
|
|
14
|
+
// That proves the wiring and nothing about the choice.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The def a DEPLOYED agent runs: authored, plus `tools/` and `system-prompt.md`
|
|
18
|
+
* — the prompt is resolved by the build, so an eval driving `agent.ts` alone
|
|
19
|
+
* would measure an agent on the framework default prompt.
|
|
20
|
+
*/
|
|
21
|
+
import agentDef from "virtual:aai/agent";
|
|
22
|
+
import { expectCalled, lastStateIn, toolNames } from "@alexkroman1/aai-runtime/eval";
|
|
23
|
+
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
24
|
+
import { expect } from "vitest";
|
|
25
|
+
import { z } from "zod";
|
|
26
|
+
|
|
27
|
+
/** The notebook as the PAGE has it: the last `syncState` frame pushed. */
|
|
28
|
+
const Projected = z.object({ notes: z.array(z.object({ id: z.number(), text: z.string() })) });
|
|
29
|
+
|
|
30
|
+
describeEval(agentDef, (test) => {
|
|
31
|
+
test(
|
|
32
|
+
"a dictated note is saved once, in the caller's words",
|
|
33
|
+
async ({ session }) => {
|
|
34
|
+
const turn = await session.say(
|
|
35
|
+
"Unit four, the window seal in the kitchen is cracked and needs replacing before winter.",
|
|
36
|
+
);
|
|
37
|
+
expectCalled(turn, "save_note");
|
|
38
|
+
// One note, one call: the whole press is one thought.
|
|
39
|
+
expect(toolNames(turn.toolCalls).filter((name) => name === "save_note")).toHaveLength(1);
|
|
40
|
+
const notes = lastStateIn(turn.events, Projected)?.notes ?? [];
|
|
41
|
+
expect(notes).toHaveLength(1);
|
|
42
|
+
expect(notes[0]?.text.toLowerCase()).toContain("window seal");
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
stubReply: [
|
|
46
|
+
{
|
|
47
|
+
tool: "save_note",
|
|
48
|
+
args: {
|
|
49
|
+
text: "Unit four, the window seal in the kitchen is cracked and needs replacing before winter.",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
"Got it, note one.",
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
test(
|
|
58
|
+
"notes survive to the next press and are read back on request",
|
|
59
|
+
async ({ session }) => {
|
|
60
|
+
await session.say("Boiler in the basement reads one point two bar.");
|
|
61
|
+
const turn = await session.say("What have I got so far?");
|
|
62
|
+
expectCalled(turn, "list_notes");
|
|
63
|
+
expect(turn.text.toLowerCase()).toContain("boiler");
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
stubReply: [
|
|
67
|
+
{ tool: "save_note", args: { text: "Boiler in the basement reads one point two bar." } },
|
|
68
|
+
"Saved.",
|
|
69
|
+
{ tool: "list_notes", args: {} },
|
|
70
|
+
"One note: the boiler in the basement reads one point two bar.",
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
2
|
+
import agentDef from "virtual:aai/agent";
|
|
3
|
+
import { createToolContext, expectDeployable, toolRunner } from "@alexkroman1/aai/testing";
|
|
4
|
+
import { describe, expect, test } from "vitest";
|
|
5
|
+
import { MAX_NOTES, notebookProjection, notebookSlot } from "./shared.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What this starter's spec may assert: properties that survive the edits the
|
|
9
|
+
* template invites — renaming it, swapping a stage, rewording the prompt — on
|
|
10
|
+
* the RESOLVED config, since `aai build` runs these before it bundles.
|
|
11
|
+
*
|
|
12
|
+
* The one thing it pins is the one thing the template is FOR: that the config
|
|
13
|
+
* a deploy ships says `turnDetection: "manual"`. Dropping that line leaves a
|
|
14
|
+
* page whose button sends commands the agent ignores, while the transcriber
|
|
15
|
+
* answers every pause — which looks like a working agent in a quiet room.
|
|
16
|
+
*/
|
|
17
|
+
const run = toolRunner(agentDef);
|
|
18
|
+
|
|
19
|
+
describe("push-to-talk-agent template", () => {
|
|
20
|
+
test("is deployable: validates, is nameable, and every stage its mode needs is filled", () => {
|
|
21
|
+
expect(() => expectDeployable(agentDef)).not.toThrow();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("the caller ends each turn, not the transcriber", () => {
|
|
25
|
+
expect(expectDeployable(agentDef).turnDetection).toBe("manual");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("both notebook tools are discovered from tools/", () => {
|
|
29
|
+
// `toContain`, not an exact list: adding a file in `tools/` is the edit
|
|
30
|
+
// this template most invites.
|
|
31
|
+
expect(Object.keys(agentDef.tools ?? {})).toEqual(
|
|
32
|
+
expect.arrayContaining(["save_note", "list_notes"]),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("save_note appends in order, and list_notes reads the same notebook back", async () => {
|
|
37
|
+
// One context is one session: the two calls share a notebook.
|
|
38
|
+
const ctx = createToolContext();
|
|
39
|
+
await run("save_note", { text: "Unit four: window seal cracked." }, ctx);
|
|
40
|
+
await run("save_note", { text: " Boiler pressure reads one point two. " }, ctx);
|
|
41
|
+
const listed = await run("list_notes", {}, ctx);
|
|
42
|
+
expect(listed).toEqual({
|
|
43
|
+
notes: [
|
|
44
|
+
{ id: 1, text: "Unit four: window seal cracked." },
|
|
45
|
+
// Trimmed — a note is the caller's words, not the transcriber's padding.
|
|
46
|
+
{ id: 2, text: "Boiler pressure reads one point two." },
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
// The page reads the same notebook, newest first.
|
|
50
|
+
expect(notebookProjection(notebookSlot.get(ctx)).notes.map((note) => note.id)).toEqual([2, 1]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("a full notebook keeps the newest notes and never reuses an id", async () => {
|
|
54
|
+
const ctx = createToolContext();
|
|
55
|
+
for (let i = 1; i <= MAX_NOTES + 3; i++) await run("save_note", { text: `note ${i}` }, ctx);
|
|
56
|
+
const { notes } = notebookSlot.get(ctx);
|
|
57
|
+
expect(notes).toHaveLength(MAX_NOTES);
|
|
58
|
+
expect(notes[0]?.id).toBe(4);
|
|
59
|
+
expect(notes.at(-1)?.id).toBe(MAX_NOTES + 3);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { agent } from "@alexkroman1/aai";
|
|
2
|
+
import { notebookProjection } from "./shared.ts";
|
|
3
|
+
|
|
4
|
+
// A hold-to-talk notebook. The one line that makes it push-to-talk is
|
|
5
|
+
// `turnDetection: "manual"`: the CALLER ends each turn by letting go of the
|
|
6
|
+
// button (or the space bar), not the transcriber by hearing a pause. So a note
|
|
7
|
+
// can be dictated slowly, with as many pauses as thinking takes, and the agent
|
|
8
|
+
// neither cuts in nor answers half of it — and nothing said while the button
|
|
9
|
+
// is up reaches the transcriber at all, which is what a noisy site needs.
|
|
10
|
+
//
|
|
11
|
+
// `client.tsx` is the other half: `usePushToTalk()` from `@alexkroman1/aai-ui`
|
|
12
|
+
// turns a button into the three commands the runtime listens for.
|
|
13
|
+
export default agent({
|
|
14
|
+
name: "Field Notes",
|
|
15
|
+
description: "A hold-to-talk notebook: dictate across pauses, answered only when you let go",
|
|
16
|
+
greeting:
|
|
17
|
+
"Hold the button, or the space bar, and tell me what to write down. Take your time, I won't jump in until you let go.",
|
|
18
|
+
turnDetection: "manual",
|
|
19
|
+
// The notebook, pushed to the page after every tool call. The panel renders
|
|
20
|
+
// `useAgentState(notebookProjection)` and keeps no copy of its own.
|
|
21
|
+
syncState: notebookProjection,
|
|
22
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hold-to-talk page. Three things arrive from the agent and one goes back.
|
|
3
|
+
*
|
|
4
|
+
* The notebook is STATE: the agent owns it in a `sessionSlot`, `syncState`
|
|
5
|
+
* projects it, `useAgentState(notebookProjection)` reads it — so a reload
|
|
6
|
+
* resumes with every note on the page.
|
|
7
|
+
*
|
|
8
|
+
* The conversation is the stock `<MessageList>`, and the Start / Pause / End
|
|
9
|
+
* row is the stock `<SessionControls>`.
|
|
10
|
+
*
|
|
11
|
+
* What goes BACK is the button. `usePushToTalk()` is the whole contract: spread
|
|
12
|
+
* `buttonProps` onto any `<button>` and it sends the three push-to-talk
|
|
13
|
+
* commands an agent declaring `turnDetection: "manual"` listens for — open a
|
|
14
|
+
* turn on press (which also stops the agent if it is talking), answer it on
|
|
15
|
+
* release, throw it away if the press is cancelled. It also holds the four
|
|
16
|
+
* cases a hand-written `onMouseDown`/`onMouseUp` pair gets wrong, each of
|
|
17
|
+
* which would leave the microphone open on a turn nothing answers: a release
|
|
18
|
+
* off the button, a held key's auto-repeat, the window losing focus mid-hold,
|
|
19
|
+
* and the page unmounting mid-hold. The space bar works page-wide by default.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import "@alexkroman1/aai-ui/styles.css";
|
|
23
|
+
import {
|
|
24
|
+
MessageList,
|
|
25
|
+
mountClient,
|
|
26
|
+
SessionControls,
|
|
27
|
+
SessionErrorBanner,
|
|
28
|
+
useAgentState,
|
|
29
|
+
usePushToTalk,
|
|
30
|
+
useSessionControls,
|
|
31
|
+
useUserTranscript,
|
|
32
|
+
} from "@alexkroman1/aai-ui";
|
|
33
|
+
import { notebookProjection } from "./shared.ts";
|
|
34
|
+
|
|
35
|
+
function TalkButton() {
|
|
36
|
+
const { talking, ready, buttonProps } = usePushToTalk();
|
|
37
|
+
// What the caller is saying RIGHT NOW. Under push-to-talk the runtime
|
|
38
|
+
// captions the whole held turn — every pause included — so this reads back
|
|
39
|
+
// the note as it is being dictated, not just its last phrase.
|
|
40
|
+
const { speaking, text } = useUserTranscript();
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="flex flex-col items-center gap-3 px-4 py-5 border-t border-aai-border">
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
{...buttonProps}
|
|
47
|
+
className={`w-28 h-28 rounded-full text-sm font-semibold select-none touch-none transition-transform ${
|
|
48
|
+
talking
|
|
49
|
+
? "scale-95 bg-aai-primary text-aai-bg"
|
|
50
|
+
: "bg-aai-surface text-aai-text border border-aai-border"
|
|
51
|
+
} disabled:opacity-40`}
|
|
52
|
+
>
|
|
53
|
+
{talking ? "Listening…" : "Hold to talk"}
|
|
54
|
+
</button>
|
|
55
|
+
<p className="text-xs opacity-60 text-center min-h-4">
|
|
56
|
+
{!ready
|
|
57
|
+
? "Press Start to begin."
|
|
58
|
+
: talking
|
|
59
|
+
? speaking
|
|
60
|
+
? text
|
|
61
|
+
: "Go ahead — pause as long as you like."
|
|
62
|
+
: "Hold the button or the space bar. Let go to send."}
|
|
63
|
+
</p>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function Notebook() {
|
|
69
|
+
const { notes } = useAgentState(notebookProjection);
|
|
70
|
+
return (
|
|
71
|
+
<div className="flex flex-col h-full text-sm bg-aai-bg text-aai-text">
|
|
72
|
+
<div className="px-4 py-3 border-b border-aai-border shrink-0">
|
|
73
|
+
<h2 className="text-xs font-bold uppercase tracking-wide opacity-60">Notebook</h2>
|
|
74
|
+
</div>
|
|
75
|
+
<div className="aai-scroll flex-1 overflow-y-auto px-3 py-2">
|
|
76
|
+
{notes.length === 0 && (
|
|
77
|
+
<p className="text-xs text-center py-8 opacity-40">Dictated notes land here.</p>
|
|
78
|
+
)}
|
|
79
|
+
{notes.map((note) => (
|
|
80
|
+
<div
|
|
81
|
+
key={note.id}
|
|
82
|
+
className="mb-2 p-2.5 rounded-lg border border-aai-border bg-aai-surface"
|
|
83
|
+
>
|
|
84
|
+
<p className="text-[11px] font-semibold text-aai-primary mb-1">Note {note.id}</p>
|
|
85
|
+
<p className="text-xs leading-relaxed">{note.text}</p>
|
|
86
|
+
</div>
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function App() {
|
|
94
|
+
// Only the Start/End hinge is read here, so this frame re-renders when the
|
|
95
|
+
// call starts or ends and not at transcript rate.
|
|
96
|
+
const { started } = useSessionControls();
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex flex-col h-screen bg-aai-bg text-aai-text">
|
|
99
|
+
<header className="px-4 py-3 border-b border-aai-border shrink-0">
|
|
100
|
+
<h1 className="text-sm font-bold">📝 Field Notes</h1>
|
|
101
|
+
</header>
|
|
102
|
+
<MessageList className="flex-1 min-h-0" />
|
|
103
|
+
<SessionErrorBanner />
|
|
104
|
+
{started && <TalkButton />}
|
|
105
|
+
<SessionControls className="px-4 py-3 border-t border-aai-border" />
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
mountClient({
|
|
111
|
+
component: App,
|
|
112
|
+
sidebar: Notebook,
|
|
113
|
+
theme: {
|
|
114
|
+
bg: "#101412",
|
|
115
|
+
primary: "#f5b942",
|
|
116
|
+
text: "#e9ece8",
|
|
117
|
+
surface: "#1a201c",
|
|
118
|
+
border: "#2a332d",
|
|
119
|
+
},
|
|
120
|
+
tools: {
|
|
121
|
+
save_note: { icon: "\u{1F4DD}", label: "Saving the note" },
|
|
122
|
+
list_notes: { icon: "\u{1F4D6}", label: "Reading the notebook" },
|
|
123
|
+
},
|
|
124
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { sessionSlot } from "@alexkroman1/aai";
|
|
2
|
+
|
|
3
|
+
/** One dictated note, as the notebook panel renders it. */
|
|
4
|
+
export type Note = { id: number; text: string };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The most notes one session keeps.
|
|
8
|
+
*
|
|
9
|
+
* The notebook rides every `syncState` frame, so an unbounded list is a frame
|
|
10
|
+
* that grows for as long as the call lasts. Fifty is a long walk-through of a
|
|
11
|
+
* site; older than that belongs in a real document.
|
|
12
|
+
*/
|
|
13
|
+
export const MAX_NOTES = 50;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The session's notebook — the agent's own state, so a reload resumes with
|
|
17
|
+
* every note still there.
|
|
18
|
+
*
|
|
19
|
+
* `nextId` rather than `notes.length + 1`: `caps` trims the FRONT of the list
|
|
20
|
+
* once it is full, and a length-derived id would then hand out a number a
|
|
21
|
+
* surviving note already has.
|
|
22
|
+
*/
|
|
23
|
+
export const notebookSlot = sessionSlot("notebook", () => ({ notes: [] as Note[], nextId: 1 }), {
|
|
24
|
+
caps: { notes: MAX_NOTES },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What the browser sees — the projection BOTH ends use (`syncState` in
|
|
29
|
+
* `agent.ts`, `useAgentState` in `client.tsx`), newest first because that is
|
|
30
|
+
* how the panel reads best. The slot itself stays chronological.
|
|
31
|
+
*/
|
|
32
|
+
export const notebookProjection = notebookSlot.projection((notebook) => ({
|
|
33
|
+
notes: [...notebook.notes].reverse(),
|
|
34
|
+
}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
You are Field Notes, a hold-to-talk notebook for someone working on site: an inspector, a technician, a researcher with their hands full.
|
|
2
|
+
|
|
3
|
+
The caller holds a button while they talk and lets go when they are done. Everything they said while holding it reaches you as ONE message, however many times they paused. Treat each message as a complete thought — never ask them to finish a sentence.
|
|
4
|
+
|
|
5
|
+
What to do with each message:
|
|
6
|
+
- If they dictated something to remember, call save_note once with the note as they said it, tidied only for punctuation. Then confirm in a few words, for example "Got it, note three." Do not read the note back unless they ask.
|
|
7
|
+
- If they dictated several separate items in one message, call save_note once per item.
|
|
8
|
+
- If they ask to hear their notes, or ask what they said about something, call list_notes and read back only what they asked for.
|
|
9
|
+
- If they are just talking to you, answer briefly. Your replies are spoken aloud to someone who is busy: one or two short sentences.
|
|
10
|
+
|
|
11
|
+
Never invent a note, and never change what a note says.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { notebookSlot } from "../shared.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read the notebook back. `notebookSlot.tool` rather than `updateTool`: this
|
|
5
|
+
* writes nothing, and what a read is handed is frozen, so the declaration is
|
|
6
|
+
* what says so.
|
|
7
|
+
*
|
|
8
|
+
* The notebook outlives the transcript the model is holding — a long session
|
|
9
|
+
* trims early turns from the context window while the slot keeps every note —
|
|
10
|
+
* so "what did I say about unit four?" is a lookup, not a memory.
|
|
11
|
+
*/
|
|
12
|
+
export default notebookSlot.tool({
|
|
13
|
+
description: "List every note saved so far, oldest first, when the caller asks to hear them.",
|
|
14
|
+
execute: (_args, notebook) => ({ notes: notebook.notes }),
|
|
15
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { notebookSlot } from "../shared.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Write one note. `updateTool`, because it writes: the body gets a mutable
|
|
6
|
+
* draft of the notebook and whatever it leaves is stored when it returns.
|
|
7
|
+
*
|
|
8
|
+
* The note is the caller's WHOLE held turn. Under `turnDetection: "manual"`
|
|
9
|
+
* the transcript the model is handed spans every pause inside one press, so a
|
|
10
|
+
* note dictated as "Unit four… (pause) …the window seal is cracked… (pause)
|
|
11
|
+
* …needs replacing before winter" arrives as one sentence rather than three
|
|
12
|
+
* turns the agent tried to answer one at a time.
|
|
13
|
+
*/
|
|
14
|
+
export default notebookSlot.updateTool({
|
|
15
|
+
description:
|
|
16
|
+
"Save a note the caller dictated. Call it once per note, with the note as they said it, tidied only for punctuation.",
|
|
17
|
+
inputSchema: z.object({
|
|
18
|
+
text: z.string().min(1).describe("The note, in the caller's own words."),
|
|
19
|
+
}),
|
|
20
|
+
execute: ({ text }, notebook) => {
|
|
21
|
+
const note = { id: notebook.nextId, text: text.trim() };
|
|
22
|
+
notebook.nextId += 1;
|
|
23
|
+
notebook.notes.push(note);
|
|
24
|
+
return { saved: note.id, total: notebook.notes.length };
|
|
25
|
+
},
|
|
26
|
+
});
|