@voicethere/agent 0.13.0 → 0.14.1

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 (47) hide show
  1. package/dist/agent.js +2 -2
  2. package/dist/build-bundle.d.ts +12 -0
  3. package/dist/build-bundle.d.ts.map +1 -1
  4. package/dist/build-bundle.js +13 -3
  5. package/dist/build-bundle.js.map +1 -1
  6. package/dist/llm/agent/config.d.ts +123 -0
  7. package/dist/llm/agent/config.d.ts.map +1 -1
  8. package/dist/llm/agent/config.js +170 -1
  9. package/dist/llm/agent/config.js.map +1 -1
  10. package/dist/llm/agent/create-llm-agent.d.ts +2 -0
  11. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  12. package/dist/llm/agent/create-llm-agent.js +186 -9
  13. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  14. package/dist/llm/agent/prompt-guidance.d.ts +7 -0
  15. package/dist/llm/agent/prompt-guidance.d.ts.map +1 -0
  16. package/dist/llm/agent/prompt-guidance.js +15 -0
  17. package/dist/llm/agent/prompt-guidance.js.map +1 -0
  18. package/dist/llm/index.d.ts +2 -1
  19. package/dist/llm/index.d.ts.map +1 -1
  20. package/dist/llm/index.js +1 -0
  21. package/dist/llm/index.js.map +1 -1
  22. package/dist/templates/echo/agent.js +2 -2
  23. package/dist/templates/echo-dc/agent.js +2 -2
  24. package/dist/templates/game-sync/agent.js +2 -2
  25. package/dist/templates/language-switch/agent.js +2 -2
  26. package/dist/templates/llm-agent/agent.js +356 -15
  27. package/dist/templates/positional-tts/agent.js +2 -2
  28. package/dist/templates/recording-consent/agent.js +2 -2
  29. package/dist/templates/spatial-showcase/agent.js +2 -2
  30. package/dist/templates/voice-showcase/agent.js +2 -2
  31. package/dist/templates/voice-starter/agent.js +2 -2
  32. package/dist/templates/webhooks/agent.js +2 -2
  33. package/dist/templates/webhooks-redis/agent.js +2 -2
  34. package/dist/templates/world-sync/agent.js +2 -2
  35. package/dist/templates/world-sync-binary/agent.js +2 -2
  36. package/dist/verify/run-verify-start.d.ts.map +1 -1
  37. package/dist/verify/run-verify-start.js +3 -0
  38. package/dist/verify/run-verify-start.js.map +1 -1
  39. package/dist/verify/run-verify.d.ts.map +1 -1
  40. package/dist/verify/run-verify.js +39 -2
  41. package/dist/verify/run-verify.js.map +1 -1
  42. package/eject/llm/loop.ts +213 -11
  43. package/package.json +1 -1
  44. package/schema/voicethere.llm.schema.json +93 -0
  45. package/templates/llm-agent/README.md +39 -0
  46. package/templates/llm-agent/prompt.md +10 -0
  47. package/templates/llm-agent/voicethere.llm.json +18 -2
@@ -1,5 +1,7 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
1
+ import { spawnSync } from "node:child_process";
2
+ import { copyFileSync, existsSync, mkdtempSync, readFileSync, rmSync, } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join, resolve } from "node:path";
3
5
  import { buildAgentBundle } from "../build-bundle.js";
4
6
  import { detectVerifyCallbacks, hasDefineAgentRegistration, parseBundleArg, } from "./lib.js";
5
7
  const MIN_NODE_MAJOR = 26;
@@ -12,6 +14,35 @@ function failCheck(checks, name, detail) {
12
14
  checks.push({ name, ok: false, detail });
13
15
  return { ok: false, checks, bundlePath: "" };
14
16
  }
17
+ /**
18
+ * Parse the bundle as an ES module without running it (`node --check`). Bundles are
19
+ * ESM whatever their extension, so the check runs on a `.mjs` copy. Catches errors that
20
+ * stop the bundle from loading at all, such as a duplicate top-level declaration.
21
+ * Returns the first line of Node's error, or undefined when the bundle parses.
22
+ */
23
+ function checkBundleParses(bundlePath) {
24
+ const dir = mkdtempSync(join(tmpdir(), "voicethere-verify-parse-"));
25
+ try {
26
+ const copy = join(dir, "bundle.mjs");
27
+ copyFileSync(bundlePath, copy);
28
+ const result = spawnSync(process.execPath, ["--check", copy], {
29
+ encoding: "utf8",
30
+ timeout: 15_000,
31
+ });
32
+ if (result.error) {
33
+ return result.error.message;
34
+ }
35
+ if (result.status === 0) {
36
+ return undefined;
37
+ }
38
+ const lines = (result.stderr ?? "").split("\n").map((line) => line.trim());
39
+ return (lines.find((line) => /Error:/.test(line)) ??
40
+ `node --check exited with code ${result.status}`);
41
+ }
42
+ finally {
43
+ rmSync(dir, { recursive: true, force: true });
44
+ }
45
+ }
15
46
  export async function runAgentVerify(options = {}) {
16
47
  const cwd = options.cwd ?? process.cwd();
17
48
  const checks = [];
@@ -63,6 +94,12 @@ export async function runAgentVerify(options = {}) {
63
94
  detail: resolvedBundle,
64
95
  });
65
96
  logLine(quiet, `✓ Bundle present (${resolvedBundle})`);
97
+ const parseError = checkBundleParses(resolvedBundle);
98
+ if (parseError) {
99
+ return failCheck(checks, "Bundle parses", parseError);
100
+ }
101
+ checks.push({ name: "Bundle parses", ok: true, detail: "node --check" });
102
+ logLine(quiet, "✓ Bundle parses");
66
103
  const bundleSource = readFileSync(resolvedBundle, "utf8");
67
104
  if (!hasDefineAgentRegistration(bundleSource)) {
68
105
  return failCheck(checks, "Agent registration", "Bundle must register handlers with defineAgent(...)");
@@ -1 +1 @@
1
- {"version":3,"file":"run-verify.js","sourceRoot":"","sources":["../../src/verify/run-verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,MAAM,cAAc,GAAG,EAAE,CAAC;AAyB1B,SAAS,OAAO,CAAC,KAA0B,EAAE,OAAe;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAChB,MAA2B,EAC3B,IAAY,EACZ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;SAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.13.0. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.14.1. Package updates no longer change this file.
2
2
  import { randomUUID } from "node:crypto";
3
3
  import {
4
4
  type AgentHandlers,
@@ -52,11 +52,19 @@ export interface CreateLlmAgentOptions {
52
52
  /** Provider SDK modules this agent may use, e.g. `[openai]` from `@voicethere/agent/llm/openai`. Must include the one `config.provider` selects. */
53
53
  providers?: readonly LlmProviderModule[];
54
54
  now?: () => number;
55
+ /** Test injection: random number in [0, 1) used to pick a filler phrase. */
56
+ random?: () => number;
55
57
  /** Test injection for MCP tool sources. */
56
58
  sourceFactory?: (opts: McpToolSourceOptions) => McpToolSource;
57
59
  }
58
60
 
59
61
  type Source = "voice" | "chat";
62
+ type FillerKind = "thinking" | "toolCall" | "toolWait";
63
+
64
+ const MAX_FILLERS_PER_TURN = 3;
65
+ const MAX_TOOL_WAIT_FILLERS = 2;
66
+ const TOOL_CALL_GAP_MS = 2_000;
67
+ const COALESCE_MAX_CHARS = 400;
60
68
 
61
69
  interface TurnState {
62
70
  turnId: string;
@@ -77,6 +85,19 @@ interface TurnState {
77
85
  playedOverride?: string;
78
86
  spokeFirst: boolean;
79
87
  fillerSpoken: boolean;
88
+ /** Fillers from the `fillers` block spoken in this turn (cap 2). */
89
+ fillersSpoken: number;
90
+ thinkingSpoken: boolean;
91
+ toolCallSpoken: boolean;
92
+ toolWaitSpoken: number;
93
+ lastFillerAt?: number;
94
+ /** True once reply speech started after the last filler. */
95
+ replySinceFiller: boolean;
96
+ fillerTimers: Map<FillerKind, ReturnType<typeof setTimeout>>;
97
+ /** Sentences completed but not yet spoken (speech coalescing). */
98
+ pending: string[];
99
+ pendingChars: number;
100
+ coalesceTimer?: ReturnType<typeof setTimeout>;
80
101
  fallbackSpoken: boolean;
81
102
  status: TurnSummary["status"];
82
103
  }
@@ -93,6 +114,7 @@ interface SessionState {
93
114
  active?: ActiveTurn;
94
115
  queued?: { text: string; source: Source };
95
116
  announcing: number;
117
+ lastFillerPhrase?: string;
96
118
  chain: Promise<void>;
97
119
  lastInterruption?: {
98
120
  turnId: string;
@@ -149,6 +171,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
149
171
  }
150
172
  const hooks = opts.hooks ?? {};
151
173
  const now = opts.now ?? Date.now;
174
+ const random = opts.random ?? Math.random;
152
175
  const getEnv = opts.env ?? (() => process.env);
153
176
  const makeSource =
154
177
  opts.sourceFactory ?? ((o: McpToolSourceOptions) => new McpToolSource(o));
@@ -162,6 +185,19 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
162
185
  const useNote = config.history?.interruptionNote ?? D.interruptionNote;
163
186
  const historyTurns = config.history?.turns ?? D.historyTurns;
164
187
  const serviceWaitMs = config.serviceWaitMs ?? D.serviceWaitMs;
188
+ const fillerCfg = config.fillers;
189
+ const thinkingPhrases = fillerCfg?.thinking?.phrases ?? [];
190
+ const toolCallPhrases = fillerCfg?.toolCall?.phrases ?? [];
191
+ const toolWaitPhrases = fillerCfg?.toolWait?.phrases ?? [];
192
+ const thinkingAfterMs = fillerCfg?.thinking?.afterMs ?? D.thinkingAfterMs;
193
+ const toolWaitAfterMs = fillerCfg?.toolWait?.afterMs ?? D.toolWaitAfterMs;
194
+ const fillersInterruptible =
195
+ fillerCfg?.interruptible ?? D.fillersInterruptible;
196
+ const coalesceMs = config.speech?.coalesceMs ?? D.speechCoalesceMs;
197
+ const legacyToolFiller =
198
+ toolCallPhrases.length === 0 && toolWaitPhrases.length === 0
199
+ ? config.tools?.filler
200
+ : undefined;
165
201
 
166
202
  let provider: LlmProvider | undefined = opts.provider;
167
203
  let registry: ToolRegistry | undefined;
@@ -206,11 +242,9 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
206
242
  text: string,
207
243
  interruptible = true,
208
244
  ): void {
245
+ flushSpeech(s, t);
209
246
  t.spoken.push(text);
210
- if (!t.spokeFirst) {
211
- t.spokeFirst = true;
212
- setAgentState(s.sessionId, "speaking");
213
- }
247
+ markReplyStarted(s, t);
214
248
  if (t.source === "chat") {
215
249
  sendToClient(s.sessionId, {
216
250
  type: "assistant_delta",
@@ -241,6 +275,147 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
241
275
  }
242
276
  }
243
277
 
278
+ // ---- fillers -----------------------------------------------------------
279
+
280
+ function clearFillerTimer(t: TurnState, kind?: FillerKind): void {
281
+ for (const [k, timer] of t.fillerTimers) {
282
+ if (kind && k !== kind) continue;
283
+ clearTimeout(timer);
284
+ t.fillerTimers.delete(k);
285
+ }
286
+ }
287
+
288
+ function phrasesFor(kind: FillerKind): string[] {
289
+ return kind === "thinking"
290
+ ? thinkingPhrases
291
+ : kind === "toolCall"
292
+ ? toolCallPhrases
293
+ : toolWaitPhrases;
294
+ }
295
+
296
+ function pickFiller(s: SessionState, kind: FillerKind): string {
297
+ const all = phrasesFor(kind);
298
+ const pool =
299
+ all.length > 1 ? all.filter((p) => p !== s.lastFillerPhrase) : all;
300
+ const i = Math.min(pool.length - 1, Math.floor(random() * pool.length));
301
+ return pool[i];
302
+ }
303
+
304
+ /**
305
+ * Speaks a filler of `kind` now, unless the turn's limits say no. Returns
306
+ * the ms to wait when the gap to the previous filler is too short.
307
+ */
308
+ function tryFiller(
309
+ s: SessionState,
310
+ t: TurnState,
311
+ kind: FillerKind,
312
+ afterMs: number,
313
+ ): { wait: number } | undefined {
314
+ if (t.controller.signal.aborted || s.ended) return undefined;
315
+ if (t.source === "chat" && !speakChat) return undefined;
316
+ if (phrasesFor(kind).length === 0) return undefined;
317
+ if (t.fillersSpoken >= MAX_FILLERS_PER_TURN) return undefined;
318
+ if (kind === "thinking" && (t.thinkingSpoken || t.spokeFirst)) {
319
+ return undefined;
320
+ }
321
+ if (kind === "toolCall" && (t.toolCallSpoken || t.spokeFirst)) {
322
+ return undefined;
323
+ }
324
+ if (kind === "toolWait" && t.toolWaitSpoken >= MAX_TOOL_WAIT_FILLERS) {
325
+ return undefined;
326
+ }
327
+ if (t.lastFillerAt !== undefined && !t.replySinceFiller) {
328
+ const gap = kind === "toolCall" ? TOOL_CALL_GAP_MS : afterMs;
329
+ const rest = gap - (now() - t.lastFillerAt);
330
+ if (rest > 0) return kind === "toolCall" ? undefined : { wait: rest };
331
+ }
332
+ const text = pickFiller(s, kind);
333
+ s.lastFillerPhrase = text;
334
+ t.fillersSpoken += 1;
335
+ t.lastFillerAt = now();
336
+ t.replySinceFiller = false;
337
+ if (kind === "thinking") t.thinkingSpoken = true;
338
+ if (kind === "toolCall") t.toolCallSpoken = true;
339
+ if (kind === "toolWait") t.toolWaitSpoken += 1;
340
+ speakAnnouncement(s, t.turnId, text, fillersInterruptible);
341
+ return undefined;
342
+ }
343
+
344
+ function armFiller(
345
+ s: SessionState,
346
+ t: TurnState,
347
+ kind: FillerKind,
348
+ delayMs: number,
349
+ afterMs: number,
350
+ ): void {
351
+ if (phrasesFor(kind).length === 0 || s.ended) return;
352
+ clearFillerTimer(t, kind);
353
+ const timer = setTimeout(() => {
354
+ t.fillerTimers.delete(kind);
355
+ const r = tryFiller(s, t, kind, afterMs);
356
+ if (r) armFiller(s, t, kind, r.wait, afterMs);
357
+ }, delayMs);
358
+ t.fillerTimers.set(kind, timer);
359
+ }
360
+
361
+ // ---- speech coalescing -------------------------------------------------
362
+
363
+ function dropPending(t: TurnState): void {
364
+ if (t.coalesceTimer) clearTimeout(t.coalesceTimer);
365
+ t.coalesceTimer = undefined;
366
+ t.pending = [];
367
+ t.pendingChars = 0;
368
+ }
369
+
370
+ /** Speaks the buffered sentences as one utterance. */
371
+ function flushSpeech(s: SessionState, t: TurnState): void {
372
+ if (t.coalesceTimer) clearTimeout(t.coalesceTimer);
373
+ t.coalesceTimer = undefined;
374
+ if (t.pending.length === 0) return;
375
+ const text = t.pending.join(" ");
376
+ t.pending = [];
377
+ t.pendingChars = 0;
378
+ if (t.controller.signal.aborted || s.ended) return;
379
+ speak(s.sessionId, text, { turnId: t.turnId });
380
+ }
381
+
382
+ /** A sentence of the model's reply: chat delta now, speech coalesced. */
383
+ function deliverReply(s: SessionState, t: TurnState, text: string): void {
384
+ if (coalesceMs <= 0) {
385
+ deliver(s, t, text);
386
+ return;
387
+ }
388
+ markReplyStarted(s, t);
389
+ t.spoken.push(text);
390
+ if (t.source === "chat") {
391
+ sendToClient(s.sessionId, {
392
+ type: "assistant_delta",
393
+ turnId: t.turnId,
394
+ text,
395
+ });
396
+ }
397
+ if (t.source !== "voice" && !speakChat) return;
398
+ t.pending.push(text);
399
+ t.pendingChars += text.length;
400
+ if (t.pendingChars >= COALESCE_MAX_CHARS) {
401
+ flushSpeech(s, t);
402
+ } else if (!t.coalesceTimer) {
403
+ t.coalesceTimer = setTimeout(() => {
404
+ t.coalesceTimer = undefined;
405
+ flushSpeech(s, t);
406
+ }, coalesceMs);
407
+ }
408
+ }
409
+
410
+ function markReplyStarted(s: SessionState, t: TurnState): void {
411
+ t.replySinceFiller = true;
412
+ if (!t.spokeFirst) {
413
+ t.spokeFirst = true;
414
+ clearFillerTimer(t, "thinking");
415
+ setAgentState(s.sessionId, "speaking");
416
+ }
417
+ }
418
+
244
419
  // ---- tools -------------------------------------------------------------
245
420
 
246
421
  function buildRegistry(env: Record<string, string | undefined>): void {
@@ -405,7 +580,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
405
580
  }
406
581
  if (t.controller.signal.aborted) return;
407
582
  t.roundText += `${t.roundText ? " " : ""}${out}`;
408
- deliver(s, t, out);
583
+ deliverReply(s, t, out);
409
584
  }
410
585
 
411
586
  async function runRound(
@@ -429,6 +604,9 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
429
604
  ];
430
605
  }
431
606
  t.llmCalls += 1;
607
+ if (t.llmCalls === 1 && !t.spokeFirst) {
608
+ armFiller(s, t, "thinking", thinkingAfterMs, thinkingAfterMs);
609
+ }
432
610
  t.roundOpen = true;
433
611
  t.roundText = "";
434
612
  const splitter = new SentenceSplitter();
@@ -463,6 +641,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
463
641
  for (const sentence of splitter.end()) {
464
642
  await emitSentence(s, t, ctx, sentence);
465
643
  }
644
+ flushSpeech(s, t);
466
645
  if (done.usage) {
467
646
  if (done.usage.inputTokens !== undefined) {
468
647
  t.inputTokens = (t.inputTokens ?? 0) + done.usage.inputTokens;
@@ -574,18 +753,21 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
574
753
  .join(",")
575
754
  .slice(0, 64),
576
755
  });
577
- const fillerCfg = config.tools?.filler;
578
- if (fillerCfg && !t.fillerSpoken) {
756
+ clearFillerTimer(t, "thinking");
757
+ tryFiller(s, t, "toolCall", 0);
758
+ armFiller(s, t, "toolWait", toolWaitAfterMs, toolWaitAfterMs);
759
+ const fillerLegacy = legacyToolFiller;
760
+ if (fillerLegacy && !t.fillerSpoken) {
579
761
  filler = setTimeout(() => {
580
762
  if (t.fillerSpoken || signal.aborted) return;
581
763
  t.fillerSpoken = true;
582
764
  speakAnnouncement(
583
765
  s,
584
766
  t.turnId,
585
- fillerCfg.text,
586
- fillerCfg.interruptible ?? D.fillerInterruptible,
767
+ fillerLegacy.text,
768
+ fillerLegacy.interruptible ?? D.fillerInterruptible,
587
769
  );
588
- }, fillerCfg.afterMs ?? D.fillerAfterMs);
770
+ }, fillerLegacy.afterMs ?? D.fillerAfterMs);
589
771
  }
590
772
  let results: LlmToolResult[];
591
773
  try {
@@ -593,6 +775,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
593
775
  } finally {
594
776
  if (filler) clearTimeout(filler);
595
777
  filler = undefined;
778
+ clearFillerTimer(t);
596
779
  }
597
780
  s.history.addToolResults(results, { turnId: t.turnId });
598
781
  if (signal.aborted)
@@ -624,6 +807,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
624
807
  return summarize(t);
625
808
  } finally {
626
809
  if (filler) clearTimeout(filler);
810
+ clearFillerTimer(t);
811
+ if (signal.aborted) dropPending(t);
627
812
  }
628
813
  }
629
814
 
@@ -716,6 +901,14 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
716
901
  roundText: "",
717
902
  spokeFirst: false,
718
903
  fillerSpoken: false,
904
+ fillersSpoken: 0,
905
+ thinkingSpoken: false,
906
+ toolCallSpoken: false,
907
+ toolWaitSpoken: 0,
908
+ replySinceFiller: false,
909
+ fillerTimers: new Map(),
910
+ pending: [],
911
+ pendingChars: 0,
719
912
  fallbackSpoken: false,
720
913
  status: "completed",
721
914
  };
@@ -798,6 +991,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
798
991
  cancelSpeech(s.sessionId, { turnId: active.turnId });
799
992
  active.state.abortStatus = "cancelled";
800
993
  active.state.controller.abort();
994
+ clearFillerTimer(active.state);
995
+ dropPending(active.state);
801
996
  let timer: ReturnType<typeof setTimeout> | undefined;
802
997
  await Promise.race([
803
998
  active.promise,
@@ -828,6 +1023,9 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
828
1023
 
829
1024
  return {
830
1025
  async onAgentStart() {
1026
+ for (const w of validated.warnings) {
1027
+ agentLog("warn", `config warning: ${w.path} ${w.message}`);
1028
+ }
831
1029
  const env = getEnv();
832
1030
  const apiKey = env[config.apiKeySecret];
833
1031
  if (!nonEmpty(apiKey)) {
@@ -901,6 +1099,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
901
1099
  const active = s.active;
902
1100
  if (active && active.turnId === ctx.turnId) {
903
1101
  const t = active.state;
1102
+ clearFillerTimer(t);
1103
+ dropPending(t);
904
1104
  if (t.roundOpen) {
905
1105
  t.playedOverride = ctx.playedText;
906
1106
  if (note) s.history.setPendingNote(note);
@@ -924,6 +1124,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
924
1124
  if (s.active) {
925
1125
  s.active.state.abortStatus = "cancelled";
926
1126
  s.active.state.controller.abort();
1127
+ clearFillerTimer(s.active.state);
1128
+ dropPending(s.active.state);
927
1129
  }
928
1130
  sessions.delete(ctx.sessionId);
929
1131
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -135,6 +135,8 @@
135
135
  },
136
136
  "filler": {
137
137
  "type": "object",
138
+ "deprecated": true,
139
+ "description": "Deprecated: use the top-level fillers block. Ignored when fillers is set.",
138
140
  "additionalProperties": false,
139
141
  "required": [
140
142
  "text"
@@ -159,6 +161,97 @@
159
161
  }
160
162
  }
161
163
  },
164
+ "fillers": {
165
+ "type": "object",
166
+ "description": "Short sentences the agent speaks while the caller waits. Off when absent. At most 3 fillers per turn, never back to back.",
167
+ "additionalProperties": false,
168
+ "properties": {
169
+ "thinking": {
170
+ "type": "object",
171
+ "description": "Spoken when no sentence of the reply was spoken afterMs after the model call started. At most once per turn.",
172
+ "additionalProperties": false,
173
+ "properties": {
174
+ "phrases": {
175
+ "type": "array",
176
+ "description": "Phrases to pick from at random, never the same as the previous filler of the session. Empty or absent turns this situation off.",
177
+ "maxItems": 20,
178
+ "items": {
179
+ "type": "string",
180
+ "minLength": 1,
181
+ "maxLength": 60
182
+ }
183
+ },
184
+ "afterMs": {
185
+ "type": "integer",
186
+ "description": "Wait for the first sentence of the reply, in milliseconds.",
187
+ "minimum": 300,
188
+ "maximum": 10000,
189
+ "default": 1500
190
+ }
191
+ }
192
+ },
193
+ "toolCall": {
194
+ "type": "object",
195
+ "description": "Spoken right when the model requests a tool call, only if nothing was spoken in the turn yet. At most once per turn.",
196
+ "additionalProperties": false,
197
+ "properties": {
198
+ "phrases": {
199
+ "type": "array",
200
+ "description": "Phrases to pick from at random, never the same as the previous filler of the session. Empty or absent turns this situation off.",
201
+ "maxItems": 20,
202
+ "items": {
203
+ "type": "string",
204
+ "minLength": 1,
205
+ "maxLength": 120
206
+ }
207
+ }
208
+ }
209
+ },
210
+ "toolWait": {
211
+ "type": "object",
212
+ "description": "Spoken when a tool round is still running afterMs after it started. At most once per tool round, twice per turn.",
213
+ "additionalProperties": false,
214
+ "properties": {
215
+ "phrases": {
216
+ "type": "array",
217
+ "description": "Phrases to pick from at random, never the same as the previous filler of the session. Empty or absent turns this situation off.",
218
+ "maxItems": 20,
219
+ "items": {
220
+ "type": "string",
221
+ "minLength": 1,
222
+ "maxLength": 120
223
+ }
224
+ },
225
+ "afterMs": {
226
+ "type": "integer",
227
+ "description": "How long a tool round runs before the filler, in milliseconds.",
228
+ "minimum": 1000,
229
+ "maximum": 30000,
230
+ "default": 4000
231
+ }
232
+ }
233
+ },
234
+ "interruptible": {
235
+ "type": "boolean",
236
+ "description": "Whether barge-in may cut a filler.",
237
+ "default": true
238
+ }
239
+ }
240
+ },
241
+ "speech": {
242
+ "type": "object",
243
+ "description": "How the reply is spoken.",
244
+ "additionalProperties": false,
245
+ "properties": {
246
+ "coalesceMs": {
247
+ "type": "integer",
248
+ "description": "Sentences that complete within this window are spoken as one utterance, so a reply that arrives at once has no gap between sentences. 0 speaks every sentence on its own.",
249
+ "minimum": 0,
250
+ "maximum": 1000,
251
+ "default": 150
252
+ }
253
+ }
254
+ },
162
255
  "toolSources": {
163
256
  "type": "array",
164
257
  "maxItems": 8,
@@ -15,6 +15,45 @@ A voice and chat agent powered by an LLM, with custom tools and MCP servers. Sou
15
15
 
16
16
  The default provider is OpenAI. Add a project secret named `AGENT_OPENAI_API_KEY` with your key, then deploy. 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
17
 
18
+ ## Filler phrases
19
+
20
+ The `fillers` block in `voicethere.llm.json` lists short sentences the agent speaks while the caller waits. Each situation has its own phrases; leave a situation out, or give it an empty list, to turn it off. The whole block is off when absent.
21
+
22
+ ```json
23
+ "fillers": {
24
+ "thinking": { "phrases": ["Hmm.", "Okay.", "Mm-hm.", "Right."], "afterMs": 1500 },
25
+ "toolCall": { "phrases": ["Let me check that for you.", "One moment, I'll look that up."] },
26
+ "toolWait": { "phrases": ["Still checking, one moment.", "Almost there."], "afterMs": 4000 },
27
+ "interruptible": true
28
+ }
29
+ ```
30
+
31
+ - `thinking`: no sentence of the reply was spoken `afterMs` (300 to 10000, default 1500) after the model call started. Phrases up to 60 characters. Once per turn.
32
+ - `toolCall`: the model asked for a tool and nothing has been spoken in this turn yet (no reply sentence, and no `thinking` filler in the last 2 seconds). It is spoken at once, before the tool runs. Phrases up to 120 characters. Once per turn.
33
+ - `toolWait`: a tool round is still running `afterMs` (1000 to 30000, default 4000) after it started. Once per tool round, twice per turn.
34
+ - At most 3 fillers per turn. Two fillers never play back to back unless the reply spoke in between or `afterMs` passed. Phrases are picked at random and never repeat the previous filler of the session. Each list takes up to 20 phrases.
35
+ - Callers can cut a filler by speaking (`interruptible`, default true). If the answer arrives while a filler plays, the answer follows it.
36
+ - Fillers are speech only. They do not appear in the conversation the model sees or in chat text.
37
+ - `tools.filler` (a single text) is deprecated. It still works when `toolCall` and `toolWait` have no phrases; otherwise `fillers` wins and a warning is logged.
38
+
39
+ ## Speech coalescing
40
+
41
+ `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.
42
+
43
+ ## Prompt guidance for phone calls
44
+
45
+ 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`:
46
+
47
+ ```ts
48
+ import { CALL_AGENT_PROMPT_GUIDANCE } from "@voicethere/agent/llm";
49
+
50
+ createLlmAgent({
51
+ systemPrompt: `${prompt}\n\n${CALL_AGENT_PROMPT_GUIDANCE}` /* ... */,
52
+ });
53
+ ```
54
+
55
+ It is never added automatically.
56
+
18
57
  ## Switch providers
19
58
 
20
59
  Change `provider`, `model` and `apiKeySecret` in `voicethere.llm.json`. For example, `anthropic` with `AGENT_ANTHROPIC_API_KEY`, `gemini` with `AGENT_GEMINI_API_KEY`, or `openrouter` with `AGENT_OPENROUTER_API_KEY`. Create the matching project secret before you deploy.
@@ -9,3 +9,13 @@ If you do not know something, say so plainly instead of guessing. Offer to help
9
9
  Use your tools when they help. For example, call get_current_time when someone asks what time or date it is, and pass the time zone if they name one.
10
10
 
11
11
  Keep numbers and dates easy to say. Say "March third" instead of "03/03", and round long numbers when the exact value does not matter.
12
+
13
+ ## Voice call
14
+
15
+ You are on a live phone call. Always answer right away; never leave the caller in silence.
16
+
17
+ Before you call a tool, say one short sentence that you are looking it up (for example "Let me check that for you."), then call the tool.
18
+
19
+ Keep sentences short; one idea per sentence. No lists, no markdown, no emojis; say numbers and dates the way a person would.
20
+
21
+ If you cannot help, say so in one sentence and offer what you can do.
@@ -11,10 +11,26 @@
11
11
  },
12
12
  "bargeIn": { "mode": "project" },
13
13
  "history": { "turns": 20, "interruptionNote": true },
14
+ "fillers": {
15
+ "thinking": {
16
+ "phrases": ["Hmm.", "Okay.", "Mm-hm.", "Right."],
17
+ "afterMs": 1500
18
+ },
19
+ "toolCall": {
20
+ "phrases": [
21
+ "Let me check that for you.",
22
+ "One moment, I'll look that up."
23
+ ]
24
+ },
25
+ "toolWait": {
26
+ "phrases": ["Still checking, one moment.", "Almost there."],
27
+ "afterMs": 4000
28
+ },
29
+ "interruptible": true
30
+ },
14
31
  "tools": {
15
32
  "maxRounds": 5,
16
- "timeoutMs": 15000,
17
- "filler": { "text": "One moment." }
33
+ "timeoutMs": 15000
18
34
  },
19
35
  "toolSources": [],
20
36
  "interruptPolicy": "cancel"