@voicethere/agent 0.29.3 → 0.31.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.
Files changed (55) hide show
  1. package/README.md +2 -0
  2. package/dist/agent.js +15 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/llm/agent/redact.d.ts +16 -0
  7. package/dist/llm/agent/redact.d.ts.map +1 -1
  8. package/dist/llm/agent/redact.js +28 -6
  9. package/dist/llm/agent/redact.js.map +1 -1
  10. package/dist/protocol.d.ts +20 -0
  11. package/dist/protocol.d.ts.map +1 -1
  12. package/dist/protocol.js.map +1 -1
  13. package/dist/runtime.d.ts +26 -1
  14. package/dist/runtime.d.ts.map +1 -1
  15. package/dist/runtime.js +28 -0
  16. package/dist/runtime.js.map +1 -1
  17. package/dist/templates/echo/agent.js +15 -1
  18. package/dist/templates/echo-dc/agent.js +15 -1
  19. package/dist/templates/flow-agent/agent.js +27 -7
  20. package/dist/templates/game-sync/agent.js +15 -1
  21. package/dist/templates/language-switch/agent.js +15 -1
  22. package/dist/templates/llm-agent/agent.js +27 -7
  23. package/dist/templates/llm-board/agent.js +60760 -0
  24. package/dist/templates/llm-docs-rag/agent.js +27 -7
  25. package/dist/templates/llm-language-tutor/agent.js +60563 -0
  26. package/dist/templates/llm-mcp-service/agent.js +27 -7
  27. package/dist/templates/llm-support-sticky-user/agent.js +27 -7
  28. package/dist/templates/positional-tts/agent.js +15 -1
  29. package/dist/templates/recording-consent/agent.js +15 -1
  30. package/dist/templates/registry.d.ts.map +1 -1
  31. package/dist/templates/registry.js +50 -0
  32. package/dist/templates/registry.js.map +1 -1
  33. package/dist/templates/spatial-showcase/agent.js +15 -1
  34. package/dist/templates/speaker-gate/agent.js +15 -1
  35. package/dist/templates/voice-showcase/agent.js +15 -1
  36. package/dist/templates/voice-starter/agent.js +15 -1
  37. package/dist/templates/webhooks/agent.js +15 -1
  38. package/dist/templates/webhooks-redis/agent.js +15 -1
  39. package/dist/templates/world-sync/agent.js +15 -1
  40. package/dist/templates/world-sync-binary/agent.js +15 -1
  41. package/eject/llm/loop.ts +1 -1
  42. package/package.json +2 -1
  43. package/templates/README.md +2 -0
  44. package/templates/llm-board/README.md +44 -0
  45. package/templates/llm-board/agent.ts +235 -0
  46. package/templates/llm-board/board.ts +196 -0
  47. package/templates/llm-board/md.d.ts +4 -0
  48. package/templates/llm-board/prompt.md +11 -0
  49. package/templates/llm-board/voicethere.llm.json +49 -0
  50. package/templates/llm-language-tutor/README.md +32 -0
  51. package/templates/llm-language-tutor/agent.ts +22 -0
  52. package/templates/llm-language-tutor/knowledge/lessons.md +121 -0
  53. package/templates/llm-language-tutor/md.d.ts +4 -0
  54. package/templates/llm-language-tutor/prompt.md +9 -0
  55. package/templates/llm-language-tutor/voicethere.llm.json +39 -0
@@ -0,0 +1,44 @@
1
+ # llm-board
2
+
3
+ A shared brainstorming board with an LLM facilitator. People add sticky notes from the browser; the facilitator reads, adds and edits notes by voice or chat through three tools. Source: `templates/llm-board/agent.ts`.
4
+
5
+ ## What you need
6
+
7
+ A project secret named `AGENT_OPENROUTER_API_KEY` (a key from openrouter.ai). No Redis: boards live in the agent process and are deleted when the last session in the room ends.
8
+
9
+ ## Files
10
+
11
+ - `agent.ts` routes board messages first and passes everything else to the LLM as chat. It also defines the tools `list_notes`, `add_note` and `update_note`.
12
+ - `board.ts` is the board itself and the message parser, with no VoiceThere imports.
13
+ - `voicethere.llm.json` holds the model (`amazon/nova-micro-v1` on OpenRouter), greeting and settings. Knowledge is off.
14
+ - `prompt.md` is the facilitator's system prompt.
15
+ - `md.d.ts` lets TypeScript accept `import x from "./x.md"`.
16
+
17
+ ## Message protocol
18
+
19
+ Data channel messages from the client:
20
+
21
+ | Message | Effect |
22
+ | ---------------------------------------------------------------- | --------------------------------------------------------------------------- |
23
+ | `{ "type": "note.add", "text", "x"?, "y"?, "color"? }` | Adds a note with author `user` |
24
+ | `{ "type": "note.update", "id", "text"?, "x"?, "y"?, "color"? }` | Changes the given fields |
25
+ | `{ "type": "note.remove", "id" }` | Deletes the note |
26
+ | `{ "type": "board.join", "room" }` | Joins a room (`a-z`, `0-9`, `-`, 6 to 40 characters) and leaves the old one |
27
+ | `{ "type": "board.sync" }` | Sends the current board to the requester only |
28
+
29
+ One agent process serves many sessions, so boards are scoped to rooms. A session that never sends `board.join` has a private board. Sessions that join the same room share one board and one set of notes, and the facilitator's tools read and change the board of the room the session is in. Anyone who knows a room id can join it, so use a long random id for a private room.
30
+
31
+ The agent answers every change with `{ "type": "board", "notes": Note[] }` to every session in the room. A `board.sync` is answered to the requester only.
32
+
33
+ A note is `{ id, text, x, y, color, author }`:
34
+
35
+ - `text`: 1 to 200 characters.
36
+ - `x`, `y`: 0 to 1, from the top left corner. Without them a new note takes a free spot on a grid.
37
+ - `color`: `yellow` (default), `blue`, `green` or `pink`.
38
+ - `author`: `user` or `ai`.
39
+
40
+ The board holds at most 60 notes. A message that fails validation (a 201 character text, a coordinate outside 0 to 1, an unknown id) changes nothing, and the board is sent back unchanged. Chat messages `{ "type": "chat", "text" }` go to the LLM as before.
41
+
42
+ ## Cost
43
+
44
+ Measured on VoiceThere's demo: see the use-case page.
@@ -0,0 +1,235 @@
1
+ import { defineAgent, sendToClient } from "@voicethere/agent";
2
+ import {
3
+ createLlmAgent,
4
+ defineTool,
5
+ type CreateLlmAgentOptions,
6
+ } from "@voicethere/agent/llm";
7
+ import { openai } from "@voicethere/agent/llm/openai";
8
+ import config from "./voicethere.llm.json";
9
+ import systemPrompt from "./prompt.md";
10
+ import {
11
+ Board,
12
+ NOTE_COLORS,
13
+ parseBoardMessage,
14
+ type BoardMessage,
15
+ type NoteColor,
16
+ } from "./board";
17
+
18
+ // Boards are room-scoped. A client joins a room with { type: "board.join",
19
+ // room }; every session in the room sees the same board. A session that never
20
+ // joins has a private room of its own ("s:" + sessionId; clients cannot name
21
+ // it because room ids match /^[a-z0-9-]{6,40}$/). One agent process serves
22
+ // many sessions, so a single process-wide board would show visitors each
23
+ // other's notes. A room's board is deleted when its last session leaves.
24
+ const boards = new Map<string, Board>();
25
+ const roomOf = new Map<string, string>();
26
+ const members = new Map<string, Set<string>>();
27
+
28
+ // Ids of sessions that ended, newest last, capped. A tool call or data message
29
+ // that arrives after the session ended must not bring its private room back,
30
+ // or the board would leak for the life of the process.
31
+ const MAX_ENDED = 1000;
32
+ const ended = new Set<string>();
33
+
34
+ function markEnded(sessionId: string): void {
35
+ ended.delete(sessionId);
36
+ ended.add(sessionId);
37
+ if (ended.size > MAX_ENDED) {
38
+ const oldest = ended.values().next().value;
39
+ if (oldest !== undefined) ended.delete(oldest);
40
+ }
41
+ }
42
+
43
+ const SESSION_ENDED = "The session has ended.";
44
+
45
+ function roomFor(sessionId: string): string | null {
46
+ if (ended.has(sessionId)) return null;
47
+ let room = roomOf.get(sessionId);
48
+ if (!room) {
49
+ room = `s:${sessionId}`;
50
+ enter(sessionId, room);
51
+ }
52
+ return room;
53
+ }
54
+
55
+ function enter(sessionId: string, room: string): void {
56
+ roomOf.set(sessionId, room);
57
+ let set = members.get(room);
58
+ if (!set) {
59
+ set = new Set();
60
+ members.set(room, set);
61
+ }
62
+ set.add(sessionId);
63
+ }
64
+
65
+ function leave(sessionId: string): void {
66
+ const room = roomOf.get(sessionId);
67
+ if (!room) return;
68
+ roomOf.delete(sessionId);
69
+ const set = members.get(room);
70
+ set?.delete(sessionId);
71
+ if (!set || set.size === 0) {
72
+ members.delete(room);
73
+ boards.delete(room);
74
+ }
75
+ }
76
+
77
+ function boardFor(sessionId: string): Board | null {
78
+ const room = roomFor(sessionId);
79
+ if (!room) return null;
80
+ let board = boards.get(room);
81
+ if (!board) {
82
+ board = new Board();
83
+ boards.set(room, board);
84
+ }
85
+ return board;
86
+ }
87
+
88
+ /** Sends the room's board to every session in it. */
89
+ function broadcast(sessionId: string): void {
90
+ const room = roomFor(sessionId);
91
+ const board = boardFor(sessionId);
92
+ if (!room || !board) return;
93
+ const payload = { type: "board", notes: board.list() };
94
+ for (const member of members.get(room) ?? []) {
95
+ sendToClient(member, payload);
96
+ }
97
+ }
98
+
99
+ function apply(sessionId: string, m: BoardMessage): void {
100
+ if (ended.has(sessionId)) return;
101
+ const board = boardFor(sessionId);
102
+ if (!board) return;
103
+ switch (m.type) {
104
+ case "board.join": {
105
+ if (roomOf.get(sessionId) !== m.room) {
106
+ leave(sessionId);
107
+ enter(sessionId, m.room);
108
+ }
109
+ break;
110
+ }
111
+ case "note.add":
112
+ board.add({ ...m, author: "user" });
113
+ break;
114
+ case "note.update": {
115
+ const { type: _type, id, ...patch } = m;
116
+ board.update(id, patch);
117
+ break;
118
+ }
119
+ case "note.remove":
120
+ board.remove(m.id);
121
+ break;
122
+ case "board.sync":
123
+ // Only the requester gets the board.
124
+ sendToClient(sessionId, {
125
+ type: "board",
126
+ notes: board.list(),
127
+ });
128
+ return;
129
+ }
130
+ broadcast(sessionId);
131
+ }
132
+
133
+ const colorSchema = { type: "string", enum: [...NOTE_COLORS] };
134
+
135
+ const listNotes = defineTool({
136
+ name: "list_notes",
137
+ description: "List every note on the shared board.",
138
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
139
+ handler: (_args, ctx) => {
140
+ const board = boardFor(ctx.sessionId);
141
+ if (!board) return SESSION_ENDED;
142
+ const notes = board.list();
143
+ if (notes.length === 0) return "The board is empty.";
144
+ return notes
145
+ .map((n) => `${n.id}: ${n.text} (${n.color}, ${n.author})`)
146
+ .join("\n");
147
+ },
148
+ });
149
+
150
+ const addNote = defineTool<{ text: string; color?: NoteColor }>({
151
+ name: "add_note",
152
+ description: "Add a note to the shared board. Text is 1 to 200 characters.",
153
+ inputSchema: {
154
+ type: "object",
155
+ properties: { text: { type: "string" }, color: colorSchema },
156
+ required: ["text"],
157
+ additionalProperties: false,
158
+ },
159
+ handler: ({ text, color }, ctx) => {
160
+ const board = boardFor(ctx.sessionId);
161
+ if (!board) return SESSION_ENDED;
162
+ const res = board.add({ text, color, author: "ai" });
163
+ if (!res.ok) return res.error;
164
+ broadcast(ctx.sessionId);
165
+ return `Added note ${res.value.id}.`;
166
+ },
167
+ });
168
+
169
+ const updateNote = defineTool<{
170
+ id: string;
171
+ text?: string;
172
+ color?: NoteColor;
173
+ x?: number;
174
+ y?: number;
175
+ }>({
176
+ name: "update_note",
177
+ description:
178
+ "Change a note's text, color or position (x and y between 0 and 1).",
179
+ inputSchema: {
180
+ type: "object",
181
+ properties: {
182
+ id: { type: "string" },
183
+ text: { type: "string" },
184
+ color: colorSchema,
185
+ x: { type: "number" },
186
+ y: { type: "number" },
187
+ },
188
+ required: ["id"],
189
+ additionalProperties: false,
190
+ },
191
+ handler: ({ id, ...patch }, ctx) => {
192
+ const board = boardFor(ctx.sessionId);
193
+ if (!board) return SESSION_ENDED;
194
+ const res = board.update(id, patch);
195
+ if (!res.ok) return res.error;
196
+ broadcast(ctx.sessionId);
197
+ return `Updated note ${id}.`;
198
+ },
199
+ });
200
+
201
+ export const boardTools = [listNotes, addNote, updateNote];
202
+
203
+ export function createBoardAgent(over: Partial<CreateLlmAgentOptions> = {}) {
204
+ const llm = createLlmAgent({
205
+ config,
206
+ systemPrompt,
207
+ tools: boardTools,
208
+ providers: [openai],
209
+ ...over,
210
+ });
211
+ return {
212
+ ...llm,
213
+ onDataChannelMessage(
214
+ ctx: Parameters<NonNullable<typeof llm.onDataChannelMessage>>[0],
215
+ ) {
216
+ const m = parseBoardMessage(ctx.message);
217
+ if (m) {
218
+ apply(ctx.sessionId, m);
219
+ return;
220
+ }
221
+ return llm.onDataChannelMessage?.(ctx);
222
+ },
223
+ onSessionStart(ctx: Parameters<NonNullable<typeof llm.onSessionStart>>[0]) {
224
+ ended.delete(ctx.sessionId);
225
+ return llm.onSessionStart?.(ctx);
226
+ },
227
+ onSessionEnd(ctx: { sessionId: string }) {
228
+ leave(ctx.sessionId);
229
+ markEnded(ctx.sessionId);
230
+ return llm.onSessionEnd?.(ctx);
231
+ },
232
+ };
233
+ }
234
+
235
+ defineAgent(createBoardAgent());
@@ -0,0 +1,196 @@
1
+ export const NOTE_COLORS = ["yellow", "blue", "green", "pink"] as const;
2
+ export type NoteColor = (typeof NOTE_COLORS)[number];
3
+
4
+ export const MAX_NOTES = 60;
5
+
6
+ /** Room ids a client may join. A session that never joins has a private room. */
7
+ export const ROOM_RE = /^[a-z0-9-]{6,40}$/;
8
+ export const MAX_NOTE_TEXT = 200;
9
+
10
+ export type Note = {
11
+ id: string;
12
+ /** 1 to 200 characters. */
13
+ text: string;
14
+ /** 0 to 1, left to right. */
15
+ x: number;
16
+ /** 0 to 1, top to bottom. */
17
+ y: number;
18
+ color: NoteColor;
19
+ author: "user" | "ai";
20
+ };
21
+
22
+ export type NotePatch = {
23
+ text?: string;
24
+ x?: number;
25
+ y?: number;
26
+ color?: NoteColor;
27
+ };
28
+
29
+ export type AddInput = {
30
+ text: string;
31
+ x?: number;
32
+ y?: number;
33
+ color?: NoteColor;
34
+ author: "user" | "ai";
35
+ };
36
+
37
+ /** Client to agent messages. Anything else is not a board message. */
38
+ export type BoardMessage =
39
+ | {
40
+ type: "note.add";
41
+ text: string;
42
+ x?: number;
43
+ y?: number;
44
+ color?: NoteColor;
45
+ }
46
+ | {
47
+ type: "note.update";
48
+ id: string;
49
+ text?: string;
50
+ x?: number;
51
+ y?: number;
52
+ color?: NoteColor;
53
+ }
54
+ | { type: "note.remove"; id: string }
55
+ | { type: "board.sync" }
56
+ | { type: "board.join"; room: string };
57
+
58
+ export type BoardResult<T> =
59
+ { ok: true; value: T } | { ok: false; error: string };
60
+
61
+ function validText(v: unknown): v is string {
62
+ return typeof v === "string" && v.length >= 1 && v.length <= MAX_NOTE_TEXT;
63
+ }
64
+
65
+ function unit(v: unknown): v is number {
66
+ return typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
67
+ }
68
+
69
+ function color(v: unknown): v is NoteColor {
70
+ return (
71
+ typeof v === "string" && (NOTE_COLORS as readonly string[]).includes(v)
72
+ );
73
+ }
74
+
75
+ /** A free spot on a 6 by 5 grid: the first cell no note sits on, else the first cell. */
76
+ export function freeSlot(notes: readonly Note[]): { x: number; y: number } {
77
+ const cols = 6;
78
+ const rows = 5;
79
+ for (let i = 0; i < cols * rows; i++) {
80
+ const x = (i % cols) / cols + 0.04;
81
+ const y = Math.floor(i / cols) / rows + 0.04;
82
+ const taken = notes.some(
83
+ (n) => Math.abs(n.x - x) < 0.01 && Math.abs(n.y - y) < 0.01,
84
+ );
85
+ if (!taken) return { x, y };
86
+ }
87
+ return { x: 0.04, y: 0.04 };
88
+ }
89
+
90
+ export class Board {
91
+ private notes = new Map<string, Note>();
92
+ private seq = 0;
93
+
94
+ add(input: AddInput): BoardResult<Note> {
95
+ if (!validText(input.text)) {
96
+ return {
97
+ ok: false,
98
+ error: `note text must be 1 to ${MAX_NOTE_TEXT} characters`,
99
+ };
100
+ }
101
+ if (this.notes.size >= MAX_NOTES)
102
+ return { ok: false, error: "board is full" };
103
+ if (input.x !== undefined && !unit(input.x))
104
+ return { ok: false, error: "x must be between 0 and 1" };
105
+ if (input.y !== undefined && !unit(input.y))
106
+ return { ok: false, error: "y must be between 0 and 1" };
107
+ if (input.color !== undefined && !color(input.color))
108
+ return { ok: false, error: "unknown color" };
109
+ const slot = freeSlot(this.list());
110
+ this.seq += 1;
111
+ const note: Note = {
112
+ id: `n${this.seq}`,
113
+ text: input.text,
114
+ x: input.x ?? slot.x,
115
+ y: input.y ?? slot.y,
116
+ color: input.color ?? "yellow",
117
+ author: input.author,
118
+ };
119
+ this.notes.set(note.id, note);
120
+ return { ok: true, value: note };
121
+ }
122
+
123
+ update(id: string, patch: NotePatch): BoardResult<Note> {
124
+ const note = this.notes.get(id);
125
+ if (!note) return { ok: false, error: `No note with id ${id}.` };
126
+ if (patch.text !== undefined && !validText(patch.text)) {
127
+ return {
128
+ ok: false,
129
+ error: `note text must be 1 to ${MAX_NOTE_TEXT} characters`,
130
+ };
131
+ }
132
+ if (patch.x !== undefined && !unit(patch.x))
133
+ return { ok: false, error: "x must be between 0 and 1" };
134
+ if (patch.y !== undefined && !unit(patch.y))
135
+ return { ok: false, error: "y must be between 0 and 1" };
136
+ if (patch.color !== undefined && !color(patch.color))
137
+ return { ok: false, error: "unknown color" };
138
+ const next: Note = {
139
+ ...note,
140
+ ...(patch.text !== undefined ? { text: patch.text } : {}),
141
+ ...(patch.x !== undefined ? { x: patch.x } : {}),
142
+ ...(patch.y !== undefined ? { y: patch.y } : {}),
143
+ ...(patch.color !== undefined ? { color: patch.color } : {}),
144
+ };
145
+ this.notes.set(id, next);
146
+ return { ok: true, value: next };
147
+ }
148
+
149
+ remove(id: string): boolean {
150
+ return this.notes.delete(id);
151
+ }
152
+
153
+ list(): Note[] {
154
+ return [...this.notes.values()];
155
+ }
156
+ }
157
+
158
+ export function parseBoardMessage(msg: unknown): BoardMessage | null {
159
+ if (!msg || typeof msg !== "object") return null;
160
+ const m = msg as Record<string, unknown>;
161
+ switch (m.type) {
162
+ case "board.sync":
163
+ return { type: "board.sync" };
164
+ case "board.join":
165
+ return typeof m.room === "string" && ROOM_RE.test(m.room)
166
+ ? { type: "board.join", room: m.room }
167
+ : null;
168
+ case "note.remove":
169
+ return typeof m.id === "string" && m.id
170
+ ? { type: "note.remove", id: m.id }
171
+ : null;
172
+ case "note.add": {
173
+ if (typeof m.text !== "string") return null;
174
+ return {
175
+ type: "note.add",
176
+ text: m.text,
177
+ ...(m.x !== undefined ? { x: m.x as number } : {}),
178
+ ...(m.y !== undefined ? { y: m.y as number } : {}),
179
+ ...(m.color !== undefined ? { color: m.color as NoteColor } : {}),
180
+ };
181
+ }
182
+ case "note.update": {
183
+ if (typeof m.id !== "string" || !m.id) return null;
184
+ return {
185
+ type: "note.update",
186
+ id: m.id,
187
+ ...(m.text !== undefined ? { text: m.text as string } : {}),
188
+ ...(m.x !== undefined ? { x: m.x as number } : {}),
189
+ ...(m.y !== undefined ? { y: m.y as number } : {}),
190
+ ...(m.color !== undefined ? { color: m.color as NoteColor } : {}),
191
+ };
192
+ }
193
+ default:
194
+ return null;
195
+ }
196
+ }
@@ -0,0 +1,4 @@
1
+ declare module "*.md" {
2
+ const text: string;
3
+ export default text;
4
+ }
@@ -0,0 +1,11 @@
1
+ You are the facilitator of a shared brainstorming board. The people in the room put sticky notes on it, and you can read, add and change notes with your tools. People talk to you by voice, so everything you say is read aloud.
2
+
3
+ Keep spoken replies to one or two short sentences. Do not use markdown, lists, emoji or special characters.
4
+
5
+ Call list_notes before you group, compare or summarise notes, and before you change one. Never guess what is on the board.
6
+
7
+ Add notes only when someone asks you to, or when you are asked to summarise; then add one short note per theme with add_note. Use update_note to fix a note's text, color or position when asked. Say briefly what you did, for example "I added a note about pricing."
8
+
9
+ If a tool says the board is full or a note does not exist, say so plainly and suggest what to do next.
10
+
11
+ Ask one question at a time, and only when you need it to do what was asked.
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "./node_modules/@voicethere/agent/schema/voicethere.llm.schema.json",
3
+ "version": 1,
4
+ "provider": "openrouter",
5
+ "model": "amazon/nova-micro-v1",
6
+ "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
+ "maxOutputTokens": 512,
8
+ "greeting": {
9
+ "text": "Hi! I'm your board facilitator. Add some notes, or ask me to group or summarise them.",
10
+ "interruptible": true
11
+ },
12
+ "bargeIn": {
13
+ "mode": "project"
14
+ },
15
+ "history": {
16
+ "turns": 20,
17
+ "interruptionNote": true
18
+ },
19
+ "fillers": {
20
+ "thinking": {
21
+ "phrases": ["Okay.", "Right.", "Sure.", "Let me see."],
22
+ "afterMs": 1500
23
+ },
24
+ "toolCall": {
25
+ "phrases": ["Let me look at the board.", "One moment."]
26
+ },
27
+ "toolWait": {
28
+ "phrases": ["Still checking, one moment.", "Almost there."],
29
+ "afterMs": 4000
30
+ },
31
+ "interruptible": true
32
+ },
33
+ "tools": {
34
+ "maxRounds": 5,
35
+ "timeoutMs": 15000
36
+ },
37
+ "toolSources": [],
38
+ "knowledge": {
39
+ "store": "off",
40
+ "topK": 4,
41
+ "embeddings": {
42
+ "provider": "openai",
43
+ "model": "text-embedding-3-small",
44
+ "dimensions": 512,
45
+ "apiKeySecret": "AGENT_OPENAI_API_KEY"
46
+ }
47
+ },
48
+ "interruptPolicy": "cancel"
49
+ }
@@ -0,0 +1,32 @@
1
+ # llm-language-tutor
2
+
3
+ An English practice partner for learners at levels A2 to B2. It talks in short turns, corrects one mistake per turn, asks a follow-up question, and looks up phrases and idioms in a lessons file through `search_knowledge`. Source: `templates/llm-language-tutor/agent.ts`.
4
+
5
+ ## What you need
6
+
7
+ - **Project Redis** turned on for the project. The agent indexes `knowledge/lessons.md` in Redis when it starts and skips the work when the file has not changed.
8
+ - A project secret named `AGENT_OPENROUTER_API_KEY` (a key from openrouter.ai). The same key serves the chat model and the embeddings, so `knowledge.embeddings` has no `apiKeySecret`.
9
+
10
+ Without Project Redis or the key the agent still answers, but `search_knowledge` is off.
11
+
12
+ ## Files
13
+
14
+ - `agent.ts` wires the pieces together.
15
+ - `voicethere.llm.json` holds the model (`amazon/nova-micro-v1` on OpenRouter), greeting and the `knowledge` block (`store: "redis"`, `topK: 3`, namespace `tutor`).
16
+ - `prompt.md` is the tutor's system prompt.
17
+ - `knowledge/lessons.md` has eight lessons as `##` headings, each with useful phrases and two idioms. Each heading starts a retrievable chunk.
18
+ - `md.d.ts` lets TypeScript accept `import x from "./x.md"`.
19
+
20
+ ## Embeddings model
21
+
22
+ The template uses `openai/text-embedding-3-small`. OpenRouter's embeddings guide names it (https://openrouter.ai/docs/api/reference/embeddings) and its embeddings request reference uses it as the `model` example (https://openrouter.ai/docs/api-reference/embeddings/create-embeddings). That reference documents `dimensions` as a request field (the number of dimensions of the output embeddings) but does not list which models accept it. `knowledge.embeddings.dimensions` is not set in `voicethere.llm.json`, so the agent uses its default of 512 and sends `dimensions: 512` with every embeddings request. Set the field to another value between 64 and 3072 to change it.
23
+
24
+ ## Edit the lessons
25
+
26
+ Replace or add `##` sections in `knowledge/lessons.md`. A lesson is easiest to find when its heading names the topic and its phrases are written as the learner would ask about them. Redeploy; the index rebuilds because the file hash changes.
27
+
28
+ To teach another language, change `prompt.md` and the project's voice language (see `/docs/spoken-language` in the VoiceThere docs), then write the lessons in that language.
29
+
30
+ ## Cost
31
+
32
+ Measured on VoiceThere's demo: see the use-case page.
@@ -0,0 +1,22 @@
1
+ import { defineAgent } from "@voicethere/agent";
2
+ import { createLlmAgent } from "@voicethere/agent/llm";
3
+ import { openai } from "@voicethere/agent/llm/openai";
4
+ import config from "./voicethere.llm.json";
5
+ import systemPrompt from "./prompt.md";
6
+ import lessons from "./knowledge/lessons.md";
7
+
8
+ // Needs Project Redis enabled (the lessons are indexed there at start) and the
9
+ // project secret AGENT_OPENROUTER_API_KEY, which serves both the chat model
10
+ // and the embeddings. To teach another language, change prompt.md and the
11
+ // project's voice language (see /docs/spoken-language), then replace the
12
+ // lessons in knowledge/lessons.md.
13
+ defineAgent(
14
+ createLlmAgent({
15
+ config,
16
+ systemPrompt,
17
+ providers: [openai],
18
+ knowledge: {
19
+ documents: [{ id: "lessons", title: "Lessons", text: lessons }],
20
+ },
21
+ }),
22
+ );