@voicethere/agent 0.21.0 → 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 (44) hide show
  1. package/dist/llm/agent/config.d.ts +51 -0
  2. package/dist/llm/agent/config.d.ts.map +1 -1
  3. package/dist/llm/agent/config.js +61 -0
  4. package/dist/llm/agent/config.js.map +1 -1
  5. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  6. package/dist/llm/agent/create-llm-agent.js +109 -4
  7. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  8. package/dist/llm/agent/hooks.d.ts +23 -0
  9. package/dist/llm/agent/hooks.d.ts.map +1 -1
  10. package/dist/llm/agent/link-extractor.d.ts +43 -0
  11. package/dist/llm/agent/link-extractor.d.ts.map +1 -0
  12. package/dist/llm/agent/link-extractor.js +184 -0
  13. package/dist/llm/agent/link-extractor.js.map +1 -0
  14. package/dist/llm/anthropic-provider.d.ts.map +1 -1
  15. package/dist/llm/anthropic-provider.js +3 -0
  16. package/dist/llm/anthropic-provider.js.map +1 -1
  17. package/dist/llm/catalog.d.ts.map +1 -1
  18. package/dist/llm/catalog.js +5 -3
  19. package/dist/llm/catalog.js.map +1 -1
  20. package/dist/llm/gemini-provider.d.ts.map +1 -1
  21. package/dist/llm/gemini-provider.js +10 -1
  22. package/dist/llm/gemini-provider.js.map +1 -1
  23. package/dist/llm/index.d.ts +4 -2
  24. package/dist/llm/index.d.ts.map +1 -1
  25. package/dist/llm/index.js +1 -0
  26. package/dist/llm/index.js.map +1 -1
  27. package/dist/llm/openai-provider.d.ts.map +1 -1
  28. package/dist/llm/openai-provider.js +3 -0
  29. package/dist/llm/openai-provider.js.map +1 -1
  30. package/dist/llm/types.d.ts +2 -0
  31. package/dist/llm/types.d.ts.map +1 -1
  32. package/dist/llm/types.js.map +1 -1
  33. package/dist/templates/llm-agent/agent.js +374 -75
  34. package/dist/templates/llm-docs-rag/agent.js +375 -75
  35. package/dist/templates/llm-mcp-service/agent.js +374 -75
  36. package/eject/llm/loop.ts +134 -5
  37. package/package.json +1 -1
  38. package/schema/voicethere.llm.schema.json +27 -0
  39. package/templates/llm-agent/README.md +27 -1
  40. package/templates/llm-agent/voicethere.llm.json +1 -1
  41. package/templates/llm-docs-rag/README.md +2 -1
  42. package/templates/llm-docs-rag/voicethere.llm.json +2 -1
  43. package/templates/llm-mcp-service/README.md +27 -1
  44. package/templates/llm-mcp-service/voicethere.llm.json +1 -1
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.21.0. 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.21.0",
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,
@@ -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": {
@@ -35,7 +35,8 @@ Redeploy the project. The agent connects to `/mcp` on the service with the proje
35
35
 
36
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
37
  - Edit `prompt.md` for tone and scope. Keep the rule that the model searches before it states a fact.
38
- - Set the provider, model and API key as in the `llm-agent` template: the template starts on OpenRouter with `amazon/nova-micro-v1`, key `AGENT_OPENROUTER_API_KEY` (a project secret).
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).
39
40
 
40
41
  ## Files
41
42
 
@@ -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": {
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "interruptible": true
35
35
  },
36
+ "toolChoice": "required-first-round",
36
37
  "tools": {
37
38
  "maxRounds": 5,
38
39
  "timeoutMs": 15000
@@ -42,7 +42,7 @@ The rest of this file is the `llm-agent` README, which applies here too.
42
42
 
43
43
  ## Set the API key
44
44
 
45
- 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.
45
+ 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.
46
46
 
47
47
  ## Filler phrases
48
48
 
@@ -69,6 +69,32 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
69
69
 
70
70
  `speech.coalesceMs` (0 to 1000, default 150) sets how long the agent holds a finished sentence to join it with the next one. Sentences that complete within the window are spoken as one utterance, so a reply the model returns at once has no gap between its sentences. The buffer is also spoken when the stream ends, at 400 characters, or when a tool call starts. Chat `assistant_delta` messages are not delayed. `0` speaks every sentence on its own.
71
71
 
72
+ ## Always search first
73
+
74
+ 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.
75
+
76
+ ## Links in replies
77
+
78
+ 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:
79
+
80
+ ```json
81
+ {
82
+ "type": "assistant_content",
83
+ "turnId": "…",
84
+ "content": { "kind": "link", "url": "https://…", "label": "pricing page" }
85
+ }
86
+ ```
87
+
88
+ 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.
89
+
90
+ Config `links`:
91
+
92
+ - `mode`: `extract` (default) or `off` (the text stays as the model wrote it, URL included).
93
+ - `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.
94
+ - `maxPerTurn` (1 to 10, default 3).
95
+
96
+ 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`.
97
+
72
98
  ## Prompt guidance for phone calls
73
99
 
74
100
  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": {