@alexkroman1/aai-cli 17.0.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/dist/_console-audio.d.ts +17 -0
- package/dist/_console-session.d.ts +70 -0
- package/dist/{_dev-server-CLU9xjH5.mjs → _dev-server-Dtp4aAlo.mjs} +1 -1
- package/dist/_dev-server.d.ts +1 -0
- package/dist/_templates-DXadVNsL.mjs +135 -0
- package/dist/_templates.d.ts +11 -34
- package/dist/cli.mjs +27 -7
- package/dist/console-BsyE3DyB.mjs +422 -0
- package/dist/console.d.ts +37 -0
- package/dist/{dev-ChsrNHpK.mjs → dev-BGWU2zPP.mjs} +1 -1
- package/dist/{init-W-4k-lCF.mjs → init-CbOhyNYe.mjs} +1 -1
- package/dist/scaffold/CLAUDE.md +110 -102
- package/dist/scaffold/package.json +4 -4
- package/dist/start.d.ts +3 -3
- package/dist/{studio-DEAJGBXa.mjs → studio-BRJsw7lr.mjs} +1 -1
- package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
- package/dist/templates/applicant-screening-agent/crews.ts +4 -4
- package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
- package/dist/templates/coding-agent/agent.ts +1 -1
- package/dist/templates/custom-pipeline-agent/agent.ts +2 -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/emergency-dispatch-agent/agent.eval.test.ts +1 -1
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +1 -1
- package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
- package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
- package/dist/templates/executive-inbox-agent/meeting.ts +2 -2
- 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.test.ts +1 -2
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +1 -2
- package/dist/templates/medication-safety-agent/agent.test.ts +3 -4
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
- 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 +52 -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-planner-agent/agent.test.ts +26 -16
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +87 -0
- package/dist/templates/roadside-assistance-agent/agent.test.ts +1 -1
- package/dist/templates/technical-support-agent/agent.test.ts +26 -20
- package/dist/templates/technical-support-agent/procedure.ts +3 -3
- package/dist/templates/topic-briefing-agent/agent.test.ts +38 -25
- package/dist/templates/topic-briefing-agent/shared.ts +10 -9
- 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/word-game-agent/agent.test.ts +3 -1
- package/package.json +4 -4
- package/dist/_templates-IMeKMVIj.mjs +0 -291
|
@@ -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
|
+
});
|
|
@@ -29,6 +29,7 @@ import agentDef from "virtual:aai/agent";
|
|
|
29
29
|
// agent decides you stopped talking, how it handles being interrupted, whether
|
|
30
30
|
// two sentences merged into one turn. Those need real paced audio.
|
|
31
31
|
import { errorsIn, toolNames } from "@alexkroman1/aai-runtime/eval";
|
|
32
|
+
import { evalSimulation } from "@alexkroman1/aai-runtime/eval/simulate";
|
|
32
33
|
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
33
34
|
import { expect } from "vitest";
|
|
34
35
|
|
|
@@ -90,4 +91,55 @@ describeEval(agentDef, (test) => {
|
|
|
90
91
|
// answered the first would fail the case it is supposed to let run.
|
|
91
92
|
{ stubReply: ["Nice to meet you, Sam.", "You said your name was Sam."] },
|
|
92
93
|
);
|
|
94
|
+
|
|
95
|
+
test(
|
|
96
|
+
"a simulated caller gets a forecast, and a judge grades the call",
|
|
97
|
+
async ({ session, mode }) => {
|
|
98
|
+
// The caller and the judge come from `/eval/simulate`, built over this
|
|
99
|
+
// case's own session and mode. In a keyless run all three models are
|
|
100
|
+
// scripted: the agent's replies (`stubReply` below), the caller's lines
|
|
101
|
+
// (ending on `end_call`) and the judge's rulings. That checks the loop
|
|
102
|
+
// is wired; it grades nothing, and the verdict says so.
|
|
103
|
+
const { simulate, judge } = evalSimulation({
|
|
104
|
+
agent: agentDef,
|
|
105
|
+
mode,
|
|
106
|
+
target: session,
|
|
107
|
+
stubCaller: [
|
|
108
|
+
"Hi, do I need an umbrella in Seattle today?",
|
|
109
|
+
{ tool: "end_call", args: { reason: "got the forecast" } },
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// A SECOND model plays the caller: it is told who it is and what it
|
|
114
|
+
// wants, reads each reply, answers it, and hangs up with `end_call` once
|
|
115
|
+
// it has what it came for. Nobody scripted these lines — which is the
|
|
116
|
+
// point: the caller that gives its city only when asked is the one a
|
|
117
|
+
// scripted case never writes.
|
|
118
|
+
const call = await simulate({
|
|
119
|
+
persona: "a friendly commuter on a phone, who answers in short sentences",
|
|
120
|
+
goal: "find out whether to bring an umbrella in Seattle today",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// The call ending on the caller's terms is the first thing to know: a
|
|
124
|
+
// call that ran out of turns usually means the goal was never met.
|
|
125
|
+
expect(call.endedBy, call.transcript()).toBe("caller");
|
|
126
|
+
expect(call.metrics.toolCallCounts.get_weather ?? 0).toBeGreaterThan(0);
|
|
127
|
+
|
|
128
|
+
// What deterministic readers cannot see — whether the answer MEANT
|
|
129
|
+
// anything — goes to a model-graded judge, one ruling per criterion.
|
|
130
|
+
// A judge is a noisy instrument: run it under AAI_EVAL_REPEAT and read
|
|
131
|
+
// the spread before trusting one verdict.
|
|
132
|
+
const verdict = await judge(call, [
|
|
133
|
+
"The agent looked up the weather before answering.",
|
|
134
|
+
"The agent's answer says whether an umbrella is needed.",
|
|
135
|
+
]);
|
|
136
|
+
expect(verdict.pass, verdict.explain()).toBe(true);
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
stubReply: [
|
|
140
|
+
{ tool: "get_weather", args: { city: "Seattle" } },
|
|
141
|
+
"It's raining in Seattle, so bring an umbrella.",
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
);
|
|
93
145
|
});
|
|
@@ -142,7 +142,7 @@ function scriptSteps(options: { hold?: boolean } = {}): ScriptedSteps {
|
|
|
142
142
|
// resolves a provider client, so the seam a step reaches it through is the
|
|
143
143
|
// delegate slot. Unstubbed it THROWS, which is why a converted template's eval
|
|
144
144
|
// cannot silently keep passing over research that never ran.
|
|
145
|
-
installStubStepDelegate({ researcher: RESEARCH_FINDINGS });
|
|
145
|
+
installStubStepDelegate({ routes: { researcher: RESEARCH_FINDINGS } });
|
|
146
146
|
return { calls: stub.calls, release: () => gate.resolve() };
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -451,7 +451,9 @@ describe("the steps that research", () => {
|
|
|
451
451
|
});
|
|
452
452
|
|
|
453
453
|
test("investigate hands the angle to a subagent, with the brief as its context", async () => {
|
|
454
|
-
const desk = installStubStepDelegate({
|
|
454
|
+
const desk = installStubStepDelegate({
|
|
455
|
+
routes: { researcher: "Sea otters crack shellfish [1]." },
|
|
456
|
+
});
|
|
455
457
|
|
|
456
458
|
const note = await investigate(brief, "Tool use");
|
|
457
459
|
|
|
@@ -467,7 +469,7 @@ describe("the steps that research", () => {
|
|
|
467
469
|
test("the researcher is given the web builtins, the budget, and what to answer with", async () => {
|
|
468
470
|
// What this template still OWNS, now that the loop is the runtime's: which
|
|
469
471
|
// capabilities the angle is worth, and what a finding has to be.
|
|
470
|
-
const desk = installStubStepDelegate({ researcher: "found things" });
|
|
472
|
+
const desk = installStubStepDelegate({ routes: { researcher: "found things" } });
|
|
471
473
|
await investigate(brief, "Tool use");
|
|
472
474
|
|
|
473
475
|
const researcher = desk.calls[0]?.subagent;
|
|
@@ -479,15 +481,17 @@ describe("the steps that research", () => {
|
|
|
479
481
|
|
|
480
482
|
test("sources are what the researcher CITED", async () => {
|
|
481
483
|
const desk = installStubStepDelegate({
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
484
|
+
routes: {
|
|
485
|
+
// The runtime runs a subagent's tools; the stub does not, so the route
|
|
486
|
+
// calls `cite` the way a real run would. It is an ordinary `ToolDef`, which
|
|
487
|
+
// is what makes that possible at all.
|
|
488
|
+
researcher: (call: StubDelegateCall) => {
|
|
489
|
+
void call.subagent.tools?.cite?.execute(
|
|
490
|
+
{ title: "Otters", url: "https://otters.example/tools" },
|
|
491
|
+
createToolContext(),
|
|
492
|
+
);
|
|
493
|
+
return "Sea otters crack shellfish [1].";
|
|
494
|
+
},
|
|
491
495
|
},
|
|
492
496
|
});
|
|
493
497
|
|
|
@@ -501,13 +505,15 @@ describe("the steps that research", () => {
|
|
|
501
505
|
// The worse of the two failures is a note full of findings reporting no
|
|
502
506
|
// sources at all — the report stage cites from this list.
|
|
503
507
|
installStubStepDelegate({
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
508
|
+
routes: {
|
|
509
|
+
researcher: {
|
|
510
|
+
text: "Sea otters crack shellfish.",
|
|
511
|
+
toolCalls: [
|
|
512
|
+
{ name: "web_search", input: { query: "otter tool use" } },
|
|
513
|
+
{ name: "visit_webpage", input: { url: "https://otters.example/tools" } },
|
|
514
|
+
{ name: "visit_webpage", input: { url: "https://otters.example/tools" } },
|
|
515
|
+
],
|
|
516
|
+
},
|
|
511
517
|
},
|
|
512
518
|
});
|
|
513
519
|
|
|
@@ -521,13 +527,15 @@ describe("the steps that research", () => {
|
|
|
521
527
|
test("investigate reports what the angle cost, since the searches are not visible here", async () => {
|
|
522
528
|
const reported = installStubReporter();
|
|
523
529
|
installStubStepDelegate({
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
530
|
+
routes: {
|
|
531
|
+
researcher: {
|
|
532
|
+
text: "found things",
|
|
533
|
+
toolCalls: [
|
|
534
|
+
{ name: "web_search", input: { query: "a" } },
|
|
535
|
+
{ name: "web_search", input: { query: "b" } },
|
|
536
|
+
{ name: "visit_webpage", input: { url: "https://otters.example/tools" } },
|
|
537
|
+
],
|
|
538
|
+
},
|
|
531
539
|
},
|
|
532
540
|
});
|
|
533
541
|
|
|
@@ -846,7 +854,7 @@ describe("the run is DURABLE", () => {
|
|
|
846
854
|
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
847
855
|
// No `RESEARCH_SLACK_WEBHOOK_URL`, so the filing step posts nothing — which
|
|
848
856
|
// is why the gateway counts below are the run's model calls and only those.
|
|
849
|
-
installStubStepDelegate({ researcher: "Nothing was found on this angle." });
|
|
857
|
+
installStubStepDelegate({ routes: { researcher: "Nothing was found on this angle." } });
|
|
850
858
|
});
|
|
851
859
|
|
|
852
860
|
/** The step keys a run journaled — the same shape three cases assert on. */
|
|
@@ -92,11 +92,13 @@ function scriptedDesk(script: Script = {}): ScriptedToolContext {
|
|
|
92
92
|
|
|
93
93
|
return scriptedToolContext({
|
|
94
94
|
generate: {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
routes: {
|
|
96
|
+
[PLANNER_SYSTEM]: { object: { steps: script.steps ?? ["Only step"] } },
|
|
97
|
+
[REPLANNER_SYSTEM]: act,
|
|
98
|
+
[REVISE_SYSTEM]: act,
|
|
99
|
+
},
|
|
98
100
|
},
|
|
99
|
-
delegate: { executor: worksTheStep },
|
|
101
|
+
delegate: { routes: { executor: worksTheStep } },
|
|
100
102
|
});
|
|
101
103
|
}
|
|
102
104
|
|
|
@@ -125,7 +127,9 @@ describe("planNode", () => {
|
|
|
125
127
|
|
|
126
128
|
describe("executeStep", () => {
|
|
127
129
|
test("hands the step to the executor, with the objective and the history as context", async () => {
|
|
128
|
-
const desk = stubDelegate({
|
|
130
|
+
const desk = stubDelegate({
|
|
131
|
+
routes: { executor: stepReply("Flights are around 180 return.") },
|
|
132
|
+
});
|
|
129
133
|
|
|
130
134
|
const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", [
|
|
131
135
|
{ step: "Pick dates", result: "Mid-May", settled: true, searches: [] },
|
|
@@ -147,12 +151,14 @@ describe("executeStep", () => {
|
|
|
147
151
|
// delegation — so the calls are the only honest source for the desk's
|
|
148
152
|
// "what the wait bought" line.
|
|
149
153
|
const desk = stubDelegate({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
routes: {
|
|
155
|
+
executor: {
|
|
156
|
+
text: stepReply("Flights are around 180 return."),
|
|
157
|
+
toolCalls: [
|
|
158
|
+
{ name: "search", input: { query: "lisbon flights may" } },
|
|
159
|
+
{ name: "search", input: { query: "lisbon flights june" } },
|
|
160
|
+
],
|
|
161
|
+
},
|
|
156
162
|
},
|
|
157
163
|
});
|
|
158
164
|
|
|
@@ -164,7 +170,7 @@ describe("executeStep", () => {
|
|
|
164
170
|
test("the executor is given its two tools and a bounded budget", async () => {
|
|
165
171
|
// What this template still OWNS now that the loop is the runtime's: which
|
|
166
172
|
// capabilities the step is worth, and how long it may spend.
|
|
167
|
-
const desk = stubDelegate({ executor: stepReply("done") });
|
|
173
|
+
const desk = stubDelegate({ routes: { executor: stepReply("done") } });
|
|
168
174
|
await executeStep(desk.delegate, "objective", "step", []);
|
|
169
175
|
|
|
170
176
|
const executor = desk.calls[0]?.subagent;
|
|
@@ -181,7 +187,9 @@ describe("executeStep", () => {
|
|
|
181
187
|
// read one string, so a step that found nothing and a step that answered
|
|
182
188
|
// arrived in the same shape.
|
|
183
189
|
const desk = stubDelegate({
|
|
184
|
-
|
|
190
|
+
routes: {
|
|
191
|
+
executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
|
|
192
|
+
},
|
|
185
193
|
});
|
|
186
194
|
|
|
187
195
|
const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
|
|
@@ -195,9 +203,11 @@ describe("executeStep", () => {
|
|
|
195
203
|
// so `accepted` is false — and a `settled: true` from an answer the runtime
|
|
196
204
|
// refused is exactly the claim not to take at face value.
|
|
197
205
|
const desk = stubDelegate({
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
206
|
+
routes: {
|
|
207
|
+
executor: {
|
|
208
|
+
text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
|
|
209
|
+
complaint: "You reported the step as unsettled without searching for anything.",
|
|
210
|
+
},
|
|
201
211
|
},
|
|
202
212
|
});
|
|
203
213
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* readback and the one-customer-per-call rule all live in that file.
|
|
9
9
|
*/
|
|
10
10
|
import retailAgent from "virtual:aai/agent";
|
|
11
|
-
import type { SessionEvent } from "@alexkroman1/aai
|
|
11
|
+
import type { SessionEvent } from "@alexkroman1/aai";
|
|
12
12
|
// An EVAL: does this desk actually behave? Run it with `aai eval`.
|
|
13
13
|
//
|
|
14
14
|
// `agent.test.ts` drives each tool directly and asserts about its result;
|