@voicethere/agent 0.20.1 → 0.22.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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/llm/agent/config.d.ts +51 -0
  3. package/dist/llm/agent/config.d.ts.map +1 -1
  4. package/dist/llm/agent/config.js +61 -0
  5. package/dist/llm/agent/config.js.map +1 -1
  6. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  7. package/dist/llm/agent/create-llm-agent.js +109 -4
  8. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  9. package/dist/llm/agent/hooks.d.ts +23 -0
  10. package/dist/llm/agent/hooks.d.ts.map +1 -1
  11. package/dist/llm/agent/link-extractor.d.ts +43 -0
  12. package/dist/llm/agent/link-extractor.d.ts.map +1 -0
  13. package/dist/llm/agent/link-extractor.js +184 -0
  14. package/dist/llm/agent/link-extractor.js.map +1 -0
  15. package/dist/llm/anthropic-provider.d.ts.map +1 -1
  16. package/dist/llm/anthropic-provider.js +3 -0
  17. package/dist/llm/anthropic-provider.js.map +1 -1
  18. package/dist/llm/catalog.d.ts.map +1 -1
  19. package/dist/llm/catalog.js +5 -3
  20. package/dist/llm/catalog.js.map +1 -1
  21. package/dist/llm/gemini-provider.d.ts.map +1 -1
  22. package/dist/llm/gemini-provider.js +10 -1
  23. package/dist/llm/gemini-provider.js.map +1 -1
  24. package/dist/llm/index.d.ts +4 -2
  25. package/dist/llm/index.d.ts.map +1 -1
  26. package/dist/llm/index.js +1 -0
  27. package/dist/llm/index.js.map +1 -1
  28. package/dist/llm/openai-provider.d.ts.map +1 -1
  29. package/dist/llm/openai-provider.js +3 -0
  30. package/dist/llm/openai-provider.js.map +1 -1
  31. package/dist/llm/types.d.ts +2 -0
  32. package/dist/llm/types.d.ts.map +1 -1
  33. package/dist/llm/types.js.map +1 -1
  34. package/dist/templates/llm-agent/agent.js +374 -75
  35. package/dist/templates/llm-docs-rag/agent.js +59923 -0
  36. package/dist/templates/llm-mcp-service/agent.js +374 -75
  37. package/dist/templates/registry.d.ts.map +1 -1
  38. package/dist/templates/registry.js +25 -0
  39. package/dist/templates/registry.js.map +1 -1
  40. package/eject/llm/loop.ts +134 -5
  41. package/package.json +1 -1
  42. package/schema/voicethere.llm.schema.json +27 -0
  43. package/templates/README.md +1 -0
  44. package/templates/llm-agent/README.md +27 -1
  45. package/templates/llm-agent/voicethere.llm.json +1 -1
  46. package/templates/llm-docs-rag/README.md +50 -0
  47. package/templates/llm-docs-rag/agent.ts +27 -0
  48. package/templates/llm-docs-rag/hooks.ts +21 -0
  49. package/templates/llm-docs-rag/md.d.ts +4 -0
  50. package/templates/llm-docs-rag/prompt.md +17 -0
  51. package/templates/llm-docs-rag/tools.ts +5 -0
  52. package/templates/llm-docs-rag/voicethere.llm.json +52 -0
  53. package/templates/llm-mcp-service/README.md +27 -1
  54. package/templates/llm-mcp-service/voicethere.llm.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,KAAK,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP,MAAM,GACN,YAAY,GACZ,aAAa,GACb,OAAO,CAAC;AAEZ,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;IACnB,mFAAmF;IACnF,YAAY,EAAE,OAAO,CAAC;IACtB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,oFAAoF;IACp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C,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;AAMrE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,eAAe,CAEnE;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,uBAAuB,CAMnE;AAED,wBAAgB,yBAAyB,IAAI,uBAAuB,EAAE,CAErE"}
@@ -223,6 +223,31 @@ export const AGENT_TEMPLATES = [
223
223
  ioredis: "^5.11.1",
224
224
  },
225
225
  },
226
+ {
227
+ id: "llm-docs-rag",
228
+ entry: "llm-docs-rag/agent.ts",
229
+ kind: "product",
230
+ seedOnCreate: true,
231
+ title: "LLM agent + docs search",
232
+ summary: "LLM agent that answers from your docs through a project service with hybrid vector and full-text search.",
233
+ category: "voice-data",
234
+ description: "Same LLM agent as llm-agent, wired to a docs search service as its tool source (toolSources kind service, path /mcp, tools search_docs and get_doc). The README shows how to build your docs into the public docs-rag-mcp base image and set it as the project service. The prompt searches before it states a fact and cites the page URL.",
235
+ sourceFiles: [
236
+ "llm-docs-rag/agent.ts",
237
+ "llm-docs-rag/voicethere.llm.json",
238
+ "llm-docs-rag/prompt.md",
239
+ "llm-docs-rag/tools.ts",
240
+ "llm-docs-rag/hooks.ts",
241
+ "llm-docs-rag/md.d.ts",
242
+ ],
243
+ npmDependencies: {
244
+ openai: "^7.43.0",
245
+ "@anthropic-ai/sdk": "^1.3.0",
246
+ "@google/genai": "^2.31.0",
247
+ "@modelcontextprotocol/sdk": "^1.32.2",
248
+ ioredis: "^5.11.1",
249
+ },
250
+ },
226
251
  {
227
252
  id: "echo-smoke",
228
253
  entry: "echo-smoke/agent.ts",
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AA6BA,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE;QACE,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,SAAS;QACf,YAAY,E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AM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACrE,CAAC"}
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.20.1. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.22.0. Package updates no longer change this file.
2
2
  import { randomUUID } from "node:crypto";
3
3
  import {
4
4
  type AgentHandlers,
@@ -16,7 +16,10 @@ import {
16
16
  type SpeakResultStatus,
17
17
  } from "@voicethere/agent";
18
18
  import {
19
+ type AgentContent,
20
+ cleanLinkSentence,
19
21
  ConversationHistory,
22
+ countLinkMarks,
20
23
  createLlmEmbedder,
21
24
  createLlmProvider,
22
25
  createRedisKnowledgeBase,
@@ -24,9 +27,11 @@ import {
24
27
  type CustomTool,
25
28
  DEFAULT_EMBEDDING_DIMS,
26
29
  DEFAULT_EMBEDDING_MODEL,
30
+ type ExtractedLink,
27
31
  type KnowledgeBase,
28
32
  type KnowledgeDocument,
29
33
  type KnowledgeLogger,
34
+ LinkExtractor,
30
35
  LLM_AGENT_CONFIG_DEFAULTS,
31
36
  type LlmAgentConfig,
32
37
  type LlmAgentHooks,
@@ -128,6 +133,11 @@ interface TurnState {
128
133
  fallbackSpoken: boolean;
129
134
  /** Characters of `<thinking>` blocks removed from the reply this turn. */
130
135
  thinkingCharsStripped: number;
136
+ /** URLs sent as `assistant_content` in this turn. */
137
+ linkUrls: Set<string>;
138
+ linksDropped: number;
139
+ /** Tool result texts of this turn (links.requireToolSource). */
140
+ toolResults: string[];
131
141
  status: TurnSummary["status"];
132
142
  }
133
143
 
@@ -167,6 +177,40 @@ function truncateBytes(text: string, max: number): string {
167
177
  return `${buf.subarray(0, end).toString("utf8")}\n[truncated]`;
168
178
  }
169
179
 
180
+ /** Validates customer content for `ctx.sendContent`; https links only. */
181
+ function checkContent(content: AgentContent): AgentContent {
182
+ const c = content as Partial<AgentContent> | null | undefined;
183
+ if (!c || c.kind !== "link") {
184
+ throw configError(
185
+ 'sendContent: content.kind must be "link"',
186
+ "INVALID_CONTENT",
187
+ );
188
+ }
189
+ let url: URL;
190
+ try {
191
+ url = new URL(String(c.url));
192
+ } catch {
193
+ throw configError(
194
+ "sendContent: content.url is not a URL",
195
+ "INVALID_CONTENT",
196
+ );
197
+ }
198
+ if (url.protocol !== "https:") {
199
+ throw configError(
200
+ "sendContent: content.url must be https",
201
+ "INVALID_CONTENT",
202
+ );
203
+ }
204
+ if (c.label !== undefined && typeof c.label !== "string") {
205
+ throw configError(
206
+ "sendContent: content.label must be a string",
207
+ "INVALID_CONTENT",
208
+ );
209
+ }
210
+ const label = c.label?.trim();
211
+ return { kind: "link", url: String(c.url), ...(label ? { label } : {}) };
212
+ }
213
+
170
214
  function interruptionNote(played: string, unplayed: string): string {
171
215
  return `(The caller interrupted your previous reply after: "${played}". They did not hear: "${unplayed}".)`;
172
216
  }
@@ -243,6 +287,10 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
243
287
  const fillersInterruptible =
244
288
  fillerCfg?.interruptible ?? D.fillersInterruptible;
245
289
  const coalesceMs = config.speech?.coalesceMs ?? D.speechCoalesceMs;
290
+ const linksMode = config.links?.mode ?? D.linksMode;
291
+ const linksRequireToolSource =
292
+ config.links?.requireToolSource ?? D.linksRequireToolSource;
293
+ const linksMaxPerTurn = config.links?.maxPerTurn ?? D.linksMaxPerTurn;
246
294
  const legacyToolFiller =
247
295
  toolCallPhrases.length === 0 && toolWaitPhrases.length === 0
248
296
  ? config.tools?.filler
@@ -322,6 +370,54 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
322
370
  }
323
371
  }
324
372
 
373
+ /**
374
+ * The one place where `assistant_content` leaves the agent. Dedupes by URL
375
+ * per turn and applies `links.maxPerTurn`. Voice turns add `spoken: true`
376
+ * and `inReplyTo`, like `sendSpokenDelta`.
377
+ */
378
+ function sendContent(
379
+ s: SessionState,
380
+ t: TurnState,
381
+ content: AgentContent,
382
+ ): boolean {
383
+ if (t.controller.signal.aborted || s.ended) return false;
384
+ if (t.linkUrls.has(content.url)) return false;
385
+ if (t.linkUrls.size >= linksMaxPerTurn) {
386
+ t.linksDropped += 1;
387
+ return false;
388
+ }
389
+ t.linkUrls.add(content.url);
390
+ sendToClient(s.sessionId, {
391
+ type: "assistant_content",
392
+ turnId: t.turnId,
393
+ content,
394
+ ...(t.source === "voice"
395
+ ? { spoken: true, ...(t.inReplyTo ? { inReplyTo: t.inReplyTo } : {}) }
396
+ : {}),
397
+ });
398
+ return true;
399
+ }
400
+
401
+ /** A link the extractor took out of the model's reply. */
402
+ function offerLink(s: SessionState, t: TurnState, link: ExtractedLink): void {
403
+ if (!link.secure) {
404
+ t.linksDropped += 1;
405
+ return;
406
+ }
407
+ if (
408
+ linksRequireToolSource &&
409
+ !t.toolResults.some((r) => r.includes(link.url))
410
+ ) {
411
+ t.linksDropped += 1;
412
+ return;
413
+ }
414
+ sendContent(s, t, {
415
+ kind: "link",
416
+ url: link.url,
417
+ ...(link.label ? { label: link.label } : {}),
418
+ });
419
+ }
420
+
325
421
  /** The one place where a sentence of a reply leaves the agent. */
326
422
  function deliver(
327
423
  s: SessionState,
@@ -816,6 +912,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
816
912
  }
817
913
  }
818
914
  content = truncateBytes(content, toolMaxBytes);
915
+ if (!isError) t.toolResults.push(content);
819
916
  t.toolCalls.push({ name: call.name, isError, ms: now() - started });
820
917
  return { callId: call.id, name: call.name, content, isError };
821
918
  };
@@ -873,12 +970,29 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
873
970
  t.roundText = "";
874
971
  const splitter = new SentenceSplitter();
875
972
  const stripper = new ThinkingStripper();
973
+ const links = linksMode === "extract" ? new LinkExtractor() : undefined;
974
+ const emitModelSentence = async (sentence: string): Promise<void> => {
975
+ if (!links) {
976
+ await emitSentence(s, t, ctx, sentence);
977
+ return;
978
+ }
979
+ const marks = countLinkMarks(sentence);
980
+ const clean = cleanLinkSentence(sentence);
981
+ if (clean) await emitSentence(s, t, ctx, clean);
982
+ for (let i = 0; i < marks; i += 1) {
983
+ const link = links.takeLink();
984
+ if (link) offerLink(s, t, link);
985
+ }
986
+ };
876
987
  let done: Extract<LlmStreamEvent, { type: "done" }> | undefined;
877
988
  const stream = provider!.stream({
878
989
  model: resolveModel(config.provider, config.model),
879
990
  system: opts.systemPrompt,
880
991
  messages,
881
992
  tools: registry ? registry.list().map((e) => e.spec) : [],
993
+ ...(config.toolChoice === "required-first-round" && t.llmCalls === 1
994
+ ? { toolChoice: "required" as const }
995
+ : {}),
882
996
  temperature: config.temperature,
883
997
  maxOutputTokens: config.maxOutputTokens ?? D.maxOutputTokens,
884
998
  signal,
@@ -887,8 +1001,9 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
887
1001
  if (signal.aborted) break;
888
1002
  if (ev.type === "text_delta") {
889
1003
  if (t.firstTokenMs === undefined) t.firstTokenMs = now() - t.startedAt;
890
- for (const sentence of splitter.push(stripper.push(ev.text))) {
891
- await emitSentence(s, t, ctx, sentence);
1004
+ const text = stripper.push(ev.text);
1005
+ for (const sentence of splitter.push(links ? links.push(text) : text)) {
1006
+ await emitModelSentence(sentence);
892
1007
  }
893
1008
  } else {
894
1009
  done = ev;
@@ -901,13 +1016,15 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
901
1016
  "stream ended without done",
902
1017
  );
903
1018
  }
904
- const tail = stripper.end();
1019
+ const stripped = stripper.end();
1020
+ const tail = links ? links.push(stripped) + links.end() : stripped;
905
1021
  const sentences = tail
906
1022
  ? [...splitter.push(tail), ...splitter.end()]
907
1023
  : splitter.end();
908
1024
  for (const sentence of sentences) {
909
- await emitSentence(s, t, ctx, sentence);
1025
+ await emitModelSentence(sentence);
910
1026
  }
1027
+ for (const link of links?.takeAll() ?? []) offerLink(s, t, link);
911
1028
  t.thinkingCharsStripped += stripper.strippedChars;
912
1029
  // History keeps what was spoken, not the model's private reasoning.
913
1030
  const cleaned = stripThinking(done.text);
@@ -945,6 +1062,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
945
1062
  ...(t.inputTokens !== undefined ? { inputTokens: t.inputTokens } : {}),
946
1063
  ...(t.outputTokens !== undefined ? { outputTokens: t.outputTokens } : {}),
947
1064
  ...(t.errorCode ? { errorCode: t.errorCode } : {}),
1065
+ ...(t.linkUrls.size > 0 ? { linksSent: t.linkUrls.size } : {}),
1066
+ ...(t.linksDropped > 0 ? { linksDropped: t.linksDropped } : {}),
948
1067
  };
949
1068
  }
950
1069
 
@@ -1169,6 +1288,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1169
1288
  inputTokens: summary.inputTokens,
1170
1289
  outputTokens: summary.outputTokens,
1171
1290
  thinkingCharsStripped: t.thinkingCharsStripped,
1291
+ linksSent: t.linkUrls.size,
1292
+ linksDropped: t.linksDropped,
1172
1293
  },
1173
1294
  s.sessionId,
1174
1295
  );
@@ -1206,6 +1327,9 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1206
1327
  pendingChars: 0,
1207
1328
  fallbackSpoken: false,
1208
1329
  thinkingCharsStripped: 0,
1330
+ linkUrls: new Set(),
1331
+ linksDropped: 0,
1332
+ toolResults: [],
1209
1333
  status: "completed",
1210
1334
  };
1211
1335
  const ctx: TurnContext = {
@@ -1219,6 +1343,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1219
1343
  const parts = [...splitter.push(`${speech}\n`), ...splitter.end()];
1220
1344
  for (const part of parts) deliver(s, t, part, o?.interruptible);
1221
1345
  },
1346
+ sendContent: (content) => sendContent(s, t, checkContent(content)),
1222
1347
  };
1223
1348
  const active: ActiveTurn = {
1224
1349
  turnId,
@@ -1272,6 +1397,10 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1272
1397
  source,
1273
1398
  signal: new AbortController().signal,
1274
1399
  speak: () => {},
1400
+ sendContent: (content) => {
1401
+ checkContent(content);
1402
+ return false;
1403
+ },
1275
1404
  };
1276
1405
  await callHook("onTurnEnd", s.sessionId, () =>
1277
1406
  hooks.onTurnEnd!(summary, ctx),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.20.1",
3
+ "version": "0.22.0",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -42,6 +42,11 @@
42
42
  "maximum": 8192,
43
43
  "default": 512
44
44
  },
45
+ "toolChoice": {
46
+ "enum": ["auto", "required-first-round"],
47
+ "default": "auto",
48
+ "description": "required-first-round: the first LLM call of every turn must call a tool (for example a docs search before any answer). Later calls in the turn are auto. Ignored when the agent has no tools. Needs tools.maxRounds >= 2."
49
+ },
45
50
  "greeting": {
46
51
  "type": "object",
47
52
  "additionalProperties": false,
@@ -375,6 +380,28 @@
375
380
  "type": "boolean",
376
381
  "default": true
377
382
  },
383
+ "links": {
384
+ "type": "object",
385
+ "additionalProperties": false,
386
+ "description": "Links in the reply. extract (default) keeps URLs out of speech and chat text and sends each https URL once as an assistant_content link message; off leaves the text as written.",
387
+ "properties": {
388
+ "mode": {
389
+ "enum": ["extract", "off"],
390
+ "default": "extract"
391
+ },
392
+ "requireToolSource": {
393
+ "type": "boolean",
394
+ "default": false,
395
+ "description": "Send only URLs that appear in a tool result of the same turn, so the model cannot invent a link. Other URLs are still removed from speech."
396
+ },
397
+ "maxPerTurn": {
398
+ "type": "integer",
399
+ "minimum": 1,
400
+ "maximum": 10,
401
+ "default": 3
402
+ }
403
+ }
404
+ },
378
405
  "knowledge": {
379
406
  "type": "object",
380
407
  "additionalProperties": false,
@@ -76,6 +76,7 @@ Each folder has its own README. Summary:
76
76
  | `webhooks-redis` | `webhooks-redis/` | Webhooks plus Redis counter |
77
77
  | `llm-agent` | `llm-agent/` | LLM voice and chat agent, tools, MCP, optional knowledge (RAG) |
78
78
  | `llm-mcp-service` | `llm-mcp-service/` | `llm-agent` plus a project service that serves MCP tools |
79
+ | `llm-docs-rag` | `llm-docs-rag/` | `llm-agent` answering from your docs via the `docs-rag-mcp` image |
79
80
 
80
81
  ## E2e templates
81
82
 
@@ -14,7 +14,7 @@ A voice and chat agent powered by an LLM, with custom tools and MCP servers. Sou
14
14
 
15
15
  ## Set the API key
16
16
 
17
- The template starts on OpenRouter with the model `amazon/nova-micro-v1`. Create a key at openrouter.ai, add it as a project secret named `AGENT_OPENROUTER_API_KEY`, then deploy. For production, pick the model from OpenRouter's list yourself, checking cost, latency and tool support. The key is read by name from `apiKeySecret` in `voicethere.llm.json`; it is never stored in the file. Only project secrets whose names start with `AGENT_` reach the agent.
17
+ The template starts on OpenRouter with the model `anthropic/claude-haiku-5.5`. Create a key at openrouter.ai, add it as a project secret named `AGENT_OPENROUTER_API_KEY`, then deploy. For production, pick the model from OpenRouter's list yourself, checking cost, latency and tool support. The key is read by name from `apiKeySecret` in `voicethere.llm.json`; it is never stored in the file. Only project secrets whose names start with `AGENT_` reach the agent.
18
18
 
19
19
  ## Filler phrases
20
20
 
@@ -45,6 +45,32 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
45
45
 
46
46
  A voice reply also reaches the client as text. Each spoken sentence arrives as `{ "type": "assistant_delta", "turnId", "text", "spoken": true }`, and the turn ends with one `{ "type": "assistant_done", "turnId", "text", "spoken": true, "status" }`. `status` is `completed`, `failed`, `interrupted` or `cancelled`, and `text` holds the sentences delivered so far. When the runner sends an utterance id for the caller's final (`SpeechContext.utteranceId` in `onUserSpeechFinal`), both messages also carry `inReplyTo`, the caller utterance the reply answers. Render one line per `turnId` and reveal it as the speech plays. Typed (chat) turns keep sending `assistant_delta`, `assistant_done` and `chat_reply` without `spoken`. Fillers are never sent as text.
47
47
 
48
+ ## Always search first
49
+
50
+ Small models often answer from memory instead of calling a tool, even when the prompt says to call it. Set `"toolChoice": "required-first-round"` in `voicethere.llm.json` and the first LLM call of every turn must call a tool. The model sees the result before it says anything about the question. The calls after the tool result are free again, so the model can answer or call another tool. Small talk ("thanks") also triggers a tool call, so use this for assistants whose answers should always come from a tool, like a docs search.
51
+
52
+ ## Links in replies
53
+
54
+ A URL in the model's reply is never spoken. The agent takes it out of the text before TTS, so `speak`, `assistant_delta` and `assistant_done` carry the sentence without it, and sends each https URL once as its own message:
55
+
56
+ ```json
57
+ {
58
+ "type": "assistant_content",
59
+ "turnId": "…",
60
+ "content": { "kind": "link", "url": "https://…", "label": "pricing page" }
61
+ }
62
+ ```
63
+
64
+ It arrives before that turn's `assistant_done`, with the same `turnId`. Voice turns add `"spoken": true` and `inReplyTo`, like the text messages. A markdown link `[pricing page](https://…)` keeps its label in the spoken sentence and sends it as `label`. A short lead-in such as "Docs:" before the link is dropped with it. `http://` links are removed from speech and never sent. Clients should ignore `content.kind` values they do not know.
65
+
66
+ Config `links`:
67
+
68
+ - `mode`: `extract` (default) or `off` (the text stays as the model wrote it, URL included).
69
+ - `requireToolSource` (default `false`): send only URLs that appear in a tool result of the same turn. Use it with a docs search tool so the model cannot link to a page it made up. Other URLs are still removed from speech.
70
+ - `maxPerTurn` (1 to 10, default 3).
71
+
72
+ Hooks and tools can send their own link with `ctx.sendContent({ kind: "link", url, label })`. It takes https only, skips a URL already sent in the turn, and returns whether it sent. The turn summary reports `linksSent` and `linksDropped`.
73
+
48
74
  ## Prompt guidance for phone calls
49
75
 
50
76
  The template prompt ends with a "Voice call" section. In your own agent you can append the same text with `CALL_AGENT_PROMPT_GUIDANCE` from `@voicethere/agent/llm`:
@@ -2,7 +2,7 @@
2
2
  "$schema": "./node_modules/@voicethere/agent/schema/voicethere.llm.schema.json",
3
3
  "version": 1,
4
4
  "provider": "openrouter",
5
- "model": "amazon/nova-micro-v1",
5
+ "model": "anthropic/claude-haiku-5.5",
6
6
  "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
7
  "maxOutputTokens": 300,
8
8
  "greeting": {
@@ -0,0 +1,50 @@
1
+ # llm-docs-rag
2
+
3
+ An LLM agent that answers questions about your own documentation. The docs live in a project service that runs the `docs-rag-mcp` image: a read-only index with vector search and full-text search, baked into the image next to a small embedding model. The agent lists the service's tools at `/mcp` (`toolSources: [{ "kind": "service", "path": "/mcp", "allow": ["search_docs", "get_doc"] }]` in `voicethere.llm.json`), and the prompt tells the model to call `search_docs` before it states any product fact and to name the page URL. Retrieval inside the agent (`knowledge`) stays off. Source: `templates/llm-docs-rag/agent.ts`.
4
+
5
+ Search runs in the service. No API key, no outside call and no runtime write: the index is built when you build the image.
6
+
7
+ ## Build your docs image
8
+
9
+ 1. Put your Markdown files in a `docs/` folder. The page id is the file path, the title is the first `#` heading.
10
+ 2. Copy `Dockerfile.customer` from the `services/docs-rag-mcp/examples` folder of the `@voicethere/agent` repository next to `docs/`, then build and push it:
11
+
12
+ ```bash
13
+ docker build -f Dockerfile.customer \
14
+ --build-arg BASE=ghcr.io/voicethere/docs-rag-mcp:<version> \
15
+ --build-arg BASE_URL=https://docs.example.com/ \
16
+ -t registry.example.com/acme/docs-mcp:1 .
17
+ docker push registry.example.com/acme/docs-mcp:1
18
+ ```
19
+
20
+ `BASE_URL` is optional. With it, each page gets a URL (`BASE_URL` plus the file path without `.md`), and the agent can read it out. Use a release tag of the base image, or `latest`.
21
+
22
+ To get a corpus from rendered pages instead of Markdown files, pass a JSON file with `docs-rag build --corpus corpus.json --out /index`; the format is in the service README.
23
+
24
+ ## Set the project service
25
+
26
+ In the dashboard, open **Services** and set:
27
+
28
+ - Image: the one you pushed. A public image needs no registry credential.
29
+ - Port: `8080`, HTTP health check path `/healthz`
30
+ - CPU 500 m and memory 1024 MiB are a safe start; the service takes about 260 MiB after the first searches. Choose "always on" so the first caller does not wait for a cold start.
31
+
32
+ Redeploy the project. The agent connects to `/mcp` on the service with the project's service token and discovers `search_docs` and `get_doc`; the agent log shows an `llm tools discovered` line.
33
+
34
+ ## Make it yours
35
+
36
+ - Tool names and the search tool's description are set with environment variables on the image: `DOCS_RAG_TOOL_PREFIX` (for example `acme_`, which gives `acme_search_docs` and `acme_get_doc`; update `allow` and the prompt to match) and `DOCS_RAG_DESCRIPTION` (for example `Search the Acme docs`).
37
+ - Edit `prompt.md` for tone and scope. Keep the rule that the model searches before it states a fact.
38
+ - `"toolChoice": "required-first-round"` makes every turn start with a docs search, so the answer comes from your docs and not from the model's memory. Remove it if the assistant should also handle small talk without searching.
39
+ - Set the provider, model and API key as in the `llm-agent` template: the template starts on OpenRouter with `anthropic/claude-haiku-5.5`, key `AGENT_OPENROUTER_API_KEY` (a project secret).
40
+
41
+ ## Files
42
+
43
+ - `agent.ts` wires the pieces together. You rarely need to change it.
44
+ - `voicethere.llm.json` holds the provider, model, greeting, barge-in, history and tool settings. The dashboard LLM tab edits this file.
45
+ - `prompt.md` is the system prompt.
46
+ - `tools.ts` lists your own tools. It is empty: the docs tools come from the service.
47
+ - `hooks.ts` is where you adjust a turn in code. It is empty by default.
48
+ - `md.d.ts` lets TypeScript accept `import prompt from "./prompt.md"`.
49
+
50
+ See the docs page `/docs/llm-agents` for the full list of settings.
@@ -0,0 +1,27 @@
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 { tools } from "./tools";
7
+ import { hooks } from "./hooks";
8
+
9
+ // The template runs on OpenRouter, which is served by the openai module, so
10
+ // switching between openai and openrouter needs no import change. To use
11
+ // another provider, change "provider" in voicethere.llm.json and import its
12
+ // module instead:
13
+ // anthropic → import { anthropic } from "@voicethere/agent/llm/anthropic";
14
+ // gemini → import { gemini } from "@voicethere/agent/llm/gemini";
15
+ //
16
+ // The docs come from a project service that runs the docs-rag-mcp image
17
+ // (toolSources in voicethere.llm.json), so knowledge (RAG inside the agent)
18
+ // stays off.
19
+ defineAgent(
20
+ createLlmAgent({
21
+ config,
22
+ systemPrompt,
23
+ tools,
24
+ hooks,
25
+ providers: [openai],
26
+ }),
27
+ );
@@ -0,0 +1,21 @@
1
+ import type { LlmAgentHooks } from "@voicethere/agent/llm";
2
+
3
+ export const hooks: LlmAgentHooks = {};
4
+
5
+ // Example: rewrite or drop a sentence before it is spoken.
6
+ //
7
+ // export const hooks: LlmAgentHooks = {
8
+ // onAssistantText: (text) => text.replace(/\*+/g, ""),
9
+ // };
10
+ //
11
+ // Example: take over a turn, then fall back to the model.
12
+ //
13
+ // export const hooks: LlmAgentHooks = {
14
+ // respond: async (ctx, next) => {
15
+ // if (/^(bye|goodbye)\b/i.test(ctx.inputText)) {
16
+ // ctx.speak("Goodbye!");
17
+ // return;
18
+ // }
19
+ // return next();
20
+ // },
21
+ // };
@@ -0,0 +1,4 @@
1
+ declare module "*.md" {
2
+ const text: string;
3
+ export default text;
4
+ }
@@ -0,0 +1,17 @@
1
+ You are a helpful assistant that answers questions about our documentation. People may talk to you by voice, so everything you say can be read aloud.
2
+
3
+ Call search_docs before you state any fact about the product: prices, limits, settings, commands, names or steps. Answer from what the search returns and give the number or name as the page shows it. If the first search does not answer the question, search again with different words, or call get_doc with the page id of the best hit to read the whole page.
4
+
5
+ Name the page you used and say its URL. If the search finds nothing relevant, say you could not find it in the documentation instead of guessing.
6
+
7
+ Answer in short, spoken sentences. Two or three sentences are usually enough. Do not use markdown, bullet lists, headings, emoji or special characters, because they sound wrong when spoken. Say prices and dates the way a person would, and round long numbers when the exact value does not matter.
8
+
9
+ Ask one question at a time and wait for the answer before asking the next one.
10
+
11
+ ## Voice call
12
+
13
+ You are on a live phone call. Always answer right away; never leave the caller in silence.
14
+
15
+ Keep sentences short; one idea per sentence. No lists, no markdown, no emojis; say numbers and dates the way a person would.
16
+
17
+ If you cannot help, say so in one sentence and offer what you can do.
@@ -0,0 +1,5 @@
1
+ import type { CustomTool } from "@voicethere/agent/llm";
2
+
3
+ // The docs tools (search_docs, get_doc) come from the project service over MCP.
4
+ // Add your own tools here with defineTool from "@voicethere/agent/llm".
5
+ export const tools: CustomTool[] = [];
@@ -0,0 +1,52 @@
1
+ {
2
+ "$schema": "./node_modules/@voicethere/agent/schema/voicethere.llm.schema.json",
3
+ "version": 1,
4
+ "provider": "openrouter",
5
+ "model": "anthropic/claude-haiku-5.5",
6
+ "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
+ "maxOutputTokens": 300,
8
+ "greeting": {
9
+ "text": "Hi! Ask me anything about our documentation.",
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": [
26
+ "Let me check that for you.",
27
+ "One moment, I'll look that up."
28
+ ]
29
+ },
30
+ "toolWait": {
31
+ "phrases": ["Still checking, one moment.", "Almost there."],
32
+ "afterMs": 4000
33
+ },
34
+ "interruptible": true
35
+ },
36
+ "toolChoice": "required-first-round",
37
+ "tools": {
38
+ "maxRounds": 5,
39
+ "timeoutMs": 15000
40
+ },
41
+ "toolSources": [
42
+ {
43
+ "kind": "service",
44
+ "path": "/mcp",
45
+ "allow": ["search_docs", "get_doc"]
46
+ }
47
+ ],
48
+ "knowledge": {
49
+ "store": "off"
50
+ },
51
+ "interruptPolicy": "cancel"
52
+ }