@voicethere/agent 0.33.2 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/llm/agent/config.d.ts +47 -0
- package/dist/llm/agent/config.d.ts.map +1 -1
- package/dist/llm/agent/config.js +128 -0
- package/dist/llm/agent/config.js.map +1 -1
- package/dist/llm/agent/create-llm-agent.d.ts +4 -0
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +63 -9
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/llm/anthropic-provider.d.ts.map +1 -1
- package/dist/llm/anthropic-provider.js +1 -0
- package/dist/llm/anthropic-provider.js.map +1 -1
- package/dist/llm/gemini-provider.d.ts.map +1 -1
- package/dist/llm/gemini-provider.js +1 -0
- package/dist/llm/gemini-provider.js.map +1 -1
- package/dist/llm/openai-provider.d.ts.map +1 -1
- package/dist/llm/openai-provider.js +1 -0
- package/dist/llm/openai-provider.js.map +1 -1
- package/dist/llm/types.d.ts +6 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js.map +1 -1
- package/dist/templates/flow-agent/agent.js +23 -0
- package/dist/templates/llm-agent/agent.js +189 -8
- package/dist/templates/llm-board/agent.js +189 -8
- package/dist/templates/llm-docs-rag/agent.js +189 -8
- package/dist/templates/llm-language-switch/agent.js +60918 -0
- package/dist/templates/llm-language-tutor/agent.js +189 -8
- package/dist/templates/llm-mcp-service/agent.js +189 -8
- package/dist/templates/llm-store-support/agent.js +189 -8
- package/dist/templates/llm-support-sticky-user/agent.js +189 -8
- package/dist/templates/registry.d.ts.map +1 -1
- package/dist/templates/registry.js +25 -0
- package/dist/templates/registry.js.map +1 -1
- package/eject/llm/loop.ts +79 -9
- package/package.json +1 -1
- package/schema/voicethere.llm.schema.json +24 -0
- package/templates/README.md +1 -0
- package/templates/llm-agent/README.md +25 -0
- package/templates/llm-language-switch/README.md +32 -0
- package/templates/llm-language-switch/agent.ts +25 -0
- package/templates/llm-language-switch/language.ts +223 -0
- package/templates/llm-language-switch/md.d.ts +4 -0
- package/templates/llm-language-switch/prompt.md +7 -0
- package/templates/llm-language-switch/voicethere.llm.json +23 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE;QACE,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,qBAAqB;QAC5B,OAAO,EAAE,0DAA0D;QACnE,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,8EAA8E;QAChF,WAAW,EAAE,CAAC,eAAe,CAAC;KAC/B;IACD;QACE,EAAE,EAAE,SAAS;QACb,KAAK,EAAE,kBAAkB;QACzB,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,6BAA6B;QACpC,OAAO,EAAE,2CAA2C;QACpD,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,qEAAqE;QACvE,WAAW,EAAE,CAAC,kBAAkB,CAAC;KAClC;IACD;QACE,EAAE,EAAE,iBAAiB;QACrB,KAAK,EAAE,0BAA0B;QACjC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,iBAAiB;QACxB,OAAO,EACL,qIAAqI;QACvI,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,qVAAqV;QACvV,WAAW,EAAE,CAAC,0BAA0B,CAAC;KAC1C;IACD;QACE,EAAE,EAAE,cAAc;QAClB,KAAK,EAAE,uBAAuB;QAC9B,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,cAAc;QACrB,OAAO,EACL,sGAAsG;QACxG,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,2ZAA2Z;Q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CAAC;AAClB,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACrE,CAAC"}
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE;QACE,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,qBAAqB;QAC5B,OAAO,EAAE,0DAA0D;QACnE,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,8EAA8E;QAChF,WAAW,EAAE,CAAC,eAAe,CAAC;KAC/B;IACD;QACE,EAAE,EAAE,SAAS;QACb,KAAK,EAAE,kBAAkB;QACzB,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,6BAA6B;QACpC,OAAO,EAAE,2CAA2C;QACpD,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,qEAAqE;QACvE,WAAW,EAAE,CAAC,kBAAkB,CAAC;KAClC;IACD;QACE,EAAE,EAAE,iBAAiB;QACrB,KAAK,EAAE,0BAA0B;QACjC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,iBAAiB;QACxB,OAAO,EACL,qIAAqI;QACvI,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,qVAAqV;QACvV,WAAW,EAAE,CAAC,0BAA0B,CAAC;KAC1C;IACD;QACE,EAAE,EAAE,cAAc;QAClB,KAAK,EAAE,uBAAuB;QAC9B,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,cAAc;QACrB,OAAO,EACL,sGAAsG;QACxG,QAAQ,EAAE,OAAO;QACjB,WAAW,EACT,2ZAA2Z;QAC7Z,WA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G,CAC5B,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAC3D,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,EAAU;IAC1C,OAAO,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAU;IACxC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,eAAe,CAAC,MAAM,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.
|
|
1
|
+
// Copied from @voicethere/agent 0.35.0. Package updates no longer change this file.
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import {
|
|
4
4
|
type AgentHandlers,
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
agentLog,
|
|
7
7
|
announce,
|
|
8
8
|
cancelSpeech,
|
|
9
|
+
disconnectClient,
|
|
9
10
|
getSessionUser,
|
|
10
11
|
parseChatText,
|
|
11
12
|
recordReply,
|
|
@@ -61,6 +62,10 @@ import {
|
|
|
61
62
|
|
|
62
63
|
const D = LLM_AGENT_CONFIG_DEFAULTS;
|
|
63
64
|
const CANCEL_SETTLE_MS = 2_000;
|
|
65
|
+
/** Longest wait for the closing message to finish before the call is closed (`failedReplies`). */
|
|
66
|
+
export const FAIL_CLOSE_SPEAK_WAIT_MS = 15_000;
|
|
67
|
+
/** Disconnect reason sent to the runner when `failedReplies` closes the call. */
|
|
68
|
+
export const FAIL_CLOSE_REASON = "llm_failed_replies";
|
|
64
69
|
|
|
65
70
|
export interface CreateLlmAgentOptions {
|
|
66
71
|
/** Validated here; an invalid config throws `LLM_CONFIG_INVALID`. */
|
|
@@ -144,6 +149,8 @@ interface TurnState {
|
|
|
144
149
|
pendingChars: number;
|
|
145
150
|
coalesceTimer?: ReturnType<typeof setTimeout>;
|
|
146
151
|
fallbackSpoken: boolean;
|
|
152
|
+
/** The closing message of `failedReplies` was spoken this turn; completes when it finished. */
|
|
153
|
+
closeSpeech?: Promise<unknown>;
|
|
147
154
|
/** Characters of `<thinking>` blocks removed from the reply this turn. */
|
|
148
155
|
thinkingCharsStripped: number;
|
|
149
156
|
/** URLs sent as `assistant_content` in this turn. */
|
|
@@ -191,6 +198,10 @@ interface SessionState {
|
|
|
191
198
|
unplayedText: string;
|
|
192
199
|
};
|
|
193
200
|
ended: boolean;
|
|
201
|
+
/** Consecutive failed turns (`failedReplies`). Per session, never module state. */
|
|
202
|
+
failedStreak: number;
|
|
203
|
+
/** The call is being closed by `failedReplies`: no further turn starts. */
|
|
204
|
+
closing: boolean;
|
|
194
205
|
}
|
|
195
206
|
|
|
196
207
|
function configError(message: string, code: string): Error {
|
|
@@ -304,6 +315,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
304
315
|
const toolMaxBytes = config.tools?.maxResultBytes ?? D.toolMaxResultBytes;
|
|
305
316
|
const policy = config.interruptPolicy ?? D.interruptPolicy;
|
|
306
317
|
const fallbackText = config.fallbackText ?? D.fallbackText;
|
|
318
|
+
const closeAfter = config.failedReplies?.closeAfter;
|
|
319
|
+
const closeMessage = config.failedReplies?.message ?? D.failedRepliesMessage;
|
|
307
320
|
const speakChat = config.speakChatReplies ?? D.speakChatReplies;
|
|
308
321
|
const useNote = config.history?.interruptionNote ?? D.interruptionNote;
|
|
309
322
|
const historyTurns = config.history?.turns ?? D.historyTurns;
|
|
@@ -530,24 +543,25 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
530
543
|
t: TurnState,
|
|
531
544
|
text: string,
|
|
532
545
|
interruptible = true,
|
|
533
|
-
):
|
|
546
|
+
): Promise<unknown> {
|
|
534
547
|
flushSpeech(s, t);
|
|
535
548
|
t.spoken.push(text);
|
|
536
549
|
markReplyStarted(s, t);
|
|
537
550
|
sendReplyDelta(s, t, text);
|
|
538
551
|
if (t.source === "voice" || speakChat) {
|
|
539
552
|
if (interruptible) {
|
|
540
|
-
trackSpeech(s, speak(s.sessionId, text, replyOpts(t)), {
|
|
553
|
+
return trackSpeech(s, speak(s.sessionId, text, replyOpts(t)), {
|
|
541
554
|
turnId: t.turnId,
|
|
542
555
|
text,
|
|
543
556
|
sentences: t.spoken,
|
|
544
557
|
indexes: [t.spoken.length - 1],
|
|
545
|
-
});
|
|
546
|
-
} else {
|
|
547
|
-
const h = announce(s.sessionId, text, replyOpts(t));
|
|
548
|
-
trackAnnouncement(s, h.done);
|
|
558
|
+
}).done;
|
|
549
559
|
}
|
|
560
|
+
const h = announce(s.sessionId, text, replyOpts(t));
|
|
561
|
+
trackAnnouncement(s, h.done);
|
|
562
|
+
return h.done;
|
|
550
563
|
}
|
|
564
|
+
return Promise.resolve();
|
|
551
565
|
}
|
|
552
566
|
|
|
553
567
|
/**
|
|
@@ -1051,6 +1065,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1051
1065
|
...(config.toolChoice === "required-first-round" && t.llmCalls === 1
|
|
1052
1066
|
? { toolChoice: "required" as const }
|
|
1053
1067
|
: {}),
|
|
1068
|
+
...(config.vendorConfig ? { vendorConfig: config.vendorConfig } : {}),
|
|
1054
1069
|
temperature: config.temperature,
|
|
1055
1070
|
maxOutputTokens: config.maxOutputTokens ?? D.maxOutputTokens,
|
|
1056
1071
|
signal,
|
|
@@ -1137,9 +1152,60 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1137
1152
|
function speakFallback(s: SessionState, t: TurnState): void {
|
|
1138
1153
|
if (t.fallbackSpoken) return;
|
|
1139
1154
|
t.fallbackSpoken = true;
|
|
1155
|
+
if (closeAfter !== undefined && s.failedStreak + 1 >= closeAfter) {
|
|
1156
|
+
t.closeSpeech = deliver(s, t, closeMessage);
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1140
1159
|
deliver(s, t, fallbackText);
|
|
1141
1160
|
}
|
|
1142
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* `failedReplies`: counts consecutive failed turns. At the limit the closing
|
|
1164
|
+
* message is on its way (or is spoken here when a `respond` hook failed the
|
|
1165
|
+
* turn), the wait for it is bounded, then the runner is asked to disconnect.
|
|
1166
|
+
* The runner registers `customer_disconnect` before teardown.
|
|
1167
|
+
*/
|
|
1168
|
+
function trackFailedReplies(
|
|
1169
|
+
s: SessionState,
|
|
1170
|
+
t: TurnState,
|
|
1171
|
+
summary: TurnSummary,
|
|
1172
|
+
): boolean {
|
|
1173
|
+
if (closeAfter === undefined || s.closing || s.ended) return false;
|
|
1174
|
+
if (summary.status === "completed") {
|
|
1175
|
+
s.failedStreak = 0;
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
if (summary.status !== "failed") return false;
|
|
1179
|
+
s.failedStreak += 1;
|
|
1180
|
+
if (s.failedStreak < closeAfter) return false;
|
|
1181
|
+
s.closing = true;
|
|
1182
|
+
t.closeSpeech ??= deliver(s, t, closeMessage);
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
async function closeAfterFailedReplies(
|
|
1187
|
+
s: SessionState,
|
|
1188
|
+
t: TurnState,
|
|
1189
|
+
): Promise<void> {
|
|
1190
|
+
const started = now();
|
|
1191
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
1192
|
+
await Promise.race([
|
|
1193
|
+
t.closeSpeech,
|
|
1194
|
+
new Promise<void>((resolve) => {
|
|
1195
|
+
timer = setTimeout(resolve, FAIL_CLOSE_SPEAK_WAIT_MS);
|
|
1196
|
+
}),
|
|
1197
|
+
]);
|
|
1198
|
+
if (timer) clearTimeout(timer);
|
|
1199
|
+
if (s.ended) return;
|
|
1200
|
+
agentLog(
|
|
1201
|
+
"info",
|
|
1202
|
+
"closing call after failed replies",
|
|
1203
|
+
{ closeAfter, waitedMs: now() - started },
|
|
1204
|
+
s.sessionId,
|
|
1205
|
+
);
|
|
1206
|
+
disconnectClient(s.sessionId, { reason: FAIL_CLOSE_REASON });
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1143
1209
|
async function ensureService(t: TurnState): Promise<void> {
|
|
1144
1210
|
if (serviceWaited || !serviceSource || serviceWaitMs <= 0) return;
|
|
1145
1211
|
serviceWaited = true;
|
|
@@ -1382,6 +1448,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1382
1448
|
});
|
|
1383
1449
|
}
|
|
1384
1450
|
setAgentState(s.sessionId, "listening");
|
|
1451
|
+
const closeNow = trackFailedReplies(s, t, summary);
|
|
1385
1452
|
if (hooks.onTurnEnd) {
|
|
1386
1453
|
await callHook("onTurnEnd", s.sessionId, () =>
|
|
1387
1454
|
hooks.onTurnEnd!(summary, ctx),
|
|
@@ -1406,6 +1473,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1406
1473
|
},
|
|
1407
1474
|
s.sessionId,
|
|
1408
1475
|
);
|
|
1476
|
+
if (closeNow) await closeAfterFailedReplies(s, t);
|
|
1409
1477
|
}
|
|
1410
1478
|
|
|
1411
1479
|
function startTurn(
|
|
@@ -1473,7 +1541,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1473
1541
|
} finally {
|
|
1474
1542
|
if (s.active === active) s.active = undefined;
|
|
1475
1543
|
const q = s.queued;
|
|
1476
|
-
if (q && !s.ended && !s.active) {
|
|
1544
|
+
if (q && !s.ended && !s.closing && !s.active) {
|
|
1477
1545
|
s.queued = undefined;
|
|
1478
1546
|
startTurn(s, q.text, q.source, q.utteranceId);
|
|
1479
1547
|
}
|
|
@@ -1487,7 +1555,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1487
1555
|
source: Source,
|
|
1488
1556
|
utteranceId?: string,
|
|
1489
1557
|
): Promise<void> {
|
|
1490
|
-
if (s.ended) return;
|
|
1558
|
+
if (s.ended || s.closing) return;
|
|
1491
1559
|
if (
|
|
1492
1560
|
source === "voice" &&
|
|
1493
1561
|
config.speechDuringNonInterruptible === "discard" &&
|
|
@@ -1611,6 +1679,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1611
1679
|
announcing: 0,
|
|
1612
1680
|
chain: Promise.resolve(),
|
|
1613
1681
|
ended: false,
|
|
1682
|
+
failedStreak: 0,
|
|
1683
|
+
closing: false,
|
|
1614
1684
|
};
|
|
1615
1685
|
sessions.set(ctx.sessionId, s);
|
|
1616
1686
|
const mode = config.bargeIn?.mode ?? D.bargeInMode;
|
package/package.json
CHANGED
|
@@ -382,6 +382,30 @@
|
|
|
382
382
|
"maxLength": 500,
|
|
383
383
|
"default": "Sorry, something went wrong. Please try again."
|
|
384
384
|
},
|
|
385
|
+
"failedReplies": {
|
|
386
|
+
"type": "object",
|
|
387
|
+
"additionalProperties": false,
|
|
388
|
+
"required": ["closeAfter"],
|
|
389
|
+
"description": "Close the call after this many failed replies in a row. Off when absent. A completed reply resets the count.",
|
|
390
|
+
"properties": {
|
|
391
|
+
"closeAfter": {
|
|
392
|
+
"type": "integer",
|
|
393
|
+
"minimum": 1,
|
|
394
|
+
"maximum": 20
|
|
395
|
+
},
|
|
396
|
+
"message": {
|
|
397
|
+
"type": "string",
|
|
398
|
+
"minLength": 1,
|
|
399
|
+
"maxLength": 300,
|
|
400
|
+
"default": "Sorry, I can't answer right now. Please try again later.",
|
|
401
|
+
"description": "Spoken and sent to chat on the closing reply, instead of fallbackText."
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
"vendorConfig": {
|
|
406
|
+
"type": "object",
|
|
407
|
+
"description": "Extra request keys for the provider's own API, merged under the fields the agent sets itself (at most 8 KB serialized). Keys the agent sets itself (model, messages or contents, system, tools, tool choice, stream, max tokens, temperature) are rejected. See the provider's API reference for the keys it accepts."
|
|
408
|
+
},
|
|
385
409
|
"speakChatReplies": {
|
|
386
410
|
"type": "boolean",
|
|
387
411
|
"default": true
|
package/templates/README.md
CHANGED
|
@@ -76,6 +76,7 @@ Each folder has its own README. Summary:
|
|
|
76
76
|
| `webhooks` | `webhooks/` | Inbound HMAC webhooks |
|
|
77
77
|
| `webhooks-redis` | `webhooks-redis/` | Webhooks plus Redis counter |
|
|
78
78
|
| `llm-agent` | `llm-agent/` | LLM voice and chat agent, tools, MCP, optional knowledge (RAG) |
|
|
79
|
+
| `llm-language-switch` | `llm-language-switch/` | `llm-agent` that follows a mid-call language switch (runner auto-switch, VoiceThere speech both sides) |
|
|
79
80
|
| `llm-language-tutor` | `llm-language-tutor/` | English practice partner: `llm-agent` plus a lessons knowledge base (Redis) |
|
|
80
81
|
| `llm-store-support` | `llm-store-support/` | Support assistant for a sample store: Markdown knowledge (Redis) plus an MCP price tool on a project service |
|
|
81
82
|
| `llm-board` | `llm-board/` | Shared sticky-note board over the data channel with an LLM facilitator (no Redis) |
|
|
@@ -91,6 +91,31 @@ createLlmAgent({
|
|
|
91
91
|
|
|
92
92
|
It is never added automatically.
|
|
93
93
|
|
|
94
|
+
## Close the call after failed replies
|
|
95
|
+
|
|
96
|
+
Off by default. Set `failedReplies` in `voicethere.llm.json` to hang up when the model keeps failing:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
"failedReplies": { "closeAfter": 3, "message": "Sorry, I can't answer right now. Please try again later." }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `closeAfter` (integer 1 to 20): consecutive failed replies that end the call. A completed reply resets the count. Cancelled and interrupted replies leave it unchanged. The count is per session.
|
|
103
|
+
- `message` (1 to 300 characters, optional): spoken and sent to chat on the closing reply instead of `fallbackText`. Default: "Sorry, I can't answer right now. Please try again later."
|
|
104
|
+
- After the message the agent waits for the speech to finish, at most 15 seconds, then asks the runner to disconnect the caller with the reason `llm_failed_replies`. No further reply starts after that.
|
|
105
|
+
|
|
106
|
+
## Provider request options (`vendorConfig`)
|
|
107
|
+
|
|
108
|
+
`vendorConfig` is a plain JSON object (at most 8 KB serialized) merged into the provider request next to the fields the agent sets. The agent never reads it. Use the keys your provider's API documents:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
"vendorConfig": { "top_p": 0.8 }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- OpenAI and OpenRouter: chat completion parameters, sent as given.
|
|
115
|
+
- Anthropic: `messages.create` parameters, sent as given.
|
|
116
|
+
- Gemini: keys of `GenerateContentConfig`. The Gemini SDK sends only the keys it knows and drops the rest.
|
|
117
|
+
- Keys the agent sets itself are rejected at load time with the key named: the model, the messages (`messages`, `contents`, `system`, `systemInstruction`), `tools`, the tool choice (`tool_choice`, `toolConfig`), `stream`, the max tokens (`max_tokens`, `max_completion_tokens`, `maxOutputTokens`) and `temperature`. Provider-specific extras the agent sends (`stream_options`, `output_config`, `abortSignal`) are rejected too.
|
|
118
|
+
|
|
94
119
|
## Output token cap
|
|
95
120
|
|
|
96
121
|
`maxOutputTokens` is 1024 in `voicethere.llm.json`. Thinking models count hidden reasoning against `maxOutputTokens`, so keep spoken replies short in the prompt, not with a small cap. A reply cut off by the cap before anything was spoken ends the turn with `LLM_OUTPUT_TRUNCATED` and the fallback text.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# llm-language-switch
|
|
2
|
+
|
|
3
|
+
A small travel-help assistant that follows the caller when they change language in the middle of the call. Speak English, then start speaking German, Spanish or French: the runner detects the language, switches speech-to-text and the voice, and replays the utterance, and the LLM answers in the new language in the new voice. Source: `templates/llm-language-switch/agent.ts` and `language.ts`.
|
|
4
|
+
|
|
5
|
+
## What you need
|
|
6
|
+
|
|
7
|
+
- A project secret named `AGENT_OPENROUTER_API_KEY` (a key from openrouter.ai).
|
|
8
|
+
- These project settings. Without them the call stays in English and the agent logs `language_switch.auto_off`:
|
|
9
|
+
- voice language settings: language identification on and `autoSwitch` on, with replay of the switching utterance and voice switching on;
|
|
10
|
+
- VoiceThere speech-to-text and text-to-speech on both sides (auto-switch needs both);
|
|
11
|
+
- `voice.allowedLanguages` set to `["en", "de", "es", "fr"]`.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
The runner owns the switch. The agent never calls `setVoiceLanguage`.
|
|
16
|
+
|
|
17
|
+
- `onVoiceLanguageChanged` records the committed language and sends `{ "type": "language", "language": "de" }` to the client. Only a committed language changes what the LLM is told. The agent appends one line ("The caller now speaks German (de). Reply only in German.") to a copy of the last caller message on every LLM call, so it never piles up in the history.
|
|
18
|
+
- `onUserLanguage` only reports what was heard: `{ "type": "language_detected", "language": "it", "supported": false }`. The runner may still reject a detection, so the LLM note does not change on it.
|
|
19
|
+
- When the detected language is not in `SUPPORTED_LANGUAGES`, the runner does not switch and the transcript comes from the wrong language's speech model. The agent skips the LLM for that utterance and says, in the current language, "I heard Italian. I can talk with you in English, German, Spanish or French." That notice is not added to the LLM history.
|
|
20
|
+
- Typed chat messages are answered in the language they are written in (the prompt says so); chat does not change the voice.
|
|
21
|
+
|
|
22
|
+
## Files
|
|
23
|
+
|
|
24
|
+
- `agent.ts` wires `createLlmAgent` into `languageSwitchAgent`.
|
|
25
|
+
- `language.ts` holds `SUPPORTED_LANGUAGES`, the language note and the unsupported-language notice. Keep `SUPPORTED_LANGUAGES` equal to the project's `voice.allowedLanguages`.
|
|
26
|
+
- `voicethere.llm.json` holds the model, greeting and limits.
|
|
27
|
+
- `prompt.md` is the system prompt.
|
|
28
|
+
- `md.d.ts` lets TypeScript accept `import x from "./x.md"`.
|
|
29
|
+
|
|
30
|
+
## Cost
|
|
31
|
+
|
|
32
|
+
Measured on VoiceThere's demo: see the use-case page.
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { languageSwitchAgent } from "./language";
|
|
7
|
+
|
|
8
|
+
// The runner owns the language switch: project auto-switch detects the new
|
|
9
|
+
// language, warms its speech models, swaps STT and voice and replays the
|
|
10
|
+
// utterance. This agent never calls setVoiceLanguage. It only tells the LLM
|
|
11
|
+
// which language the caller speaks now (language.ts), so the reply comes in
|
|
12
|
+
// that language, and reports the language to the client.
|
|
13
|
+
//
|
|
14
|
+
// Needs the project secret AGENT_OPENROUTER_API_KEY and the project settings
|
|
15
|
+
// described in README.md (auto-switch on, VoiceThere speech on both sides).
|
|
16
|
+
defineAgent(
|
|
17
|
+
languageSwitchAgent((hooks) =>
|
|
18
|
+
createLlmAgent({
|
|
19
|
+
config,
|
|
20
|
+
systemPrompt,
|
|
21
|
+
providers: [openai],
|
|
22
|
+
hooks,
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agentLog,
|
|
3
|
+
isRunnerLidAutoSwitchEnabled,
|
|
4
|
+
sendToClient,
|
|
5
|
+
speak,
|
|
6
|
+
type AgentHandlers,
|
|
7
|
+
} from "@voicethere/agent";
|
|
8
|
+
import type { LlmAgentHooks, LlmMessage } from "@voicethere/agent/llm";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Languages the call switches to. Keep this equal to the project's
|
|
12
|
+
* `voice.allowedLanguages`: the runner does not switch to any other detected
|
|
13
|
+
* language, and this agent then tells the caller what it heard.
|
|
14
|
+
*/
|
|
15
|
+
export const SUPPORTED_LANGUAGES: readonly string[] = ["en", "de", "es", "fr"];
|
|
16
|
+
|
|
17
|
+
/** The language a session starts in (the project's voice language). */
|
|
18
|
+
export const DEFAULT_LANGUAGE = "en";
|
|
19
|
+
|
|
20
|
+
/** Lower-case ISO 639-1 code from `de`, `DE` or `de-DE`. */
|
|
21
|
+
export function normalizeLanguage(code: string): string {
|
|
22
|
+
return code.trim().toLowerCase().split(/[-_]/)[0] ?? "";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isSupported(code: string): boolean {
|
|
26
|
+
return SUPPORTED_LANGUAGES.includes(normalizeLanguage(code));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The language's name written in `inLanguage`, or the code when unknown. */
|
|
30
|
+
export function languageName(code: string, inLanguage: string): string {
|
|
31
|
+
try {
|
|
32
|
+
const names = new Intl.DisplayNames([inLanguage], { type: "language" });
|
|
33
|
+
return names.of(code) ?? code;
|
|
34
|
+
} catch {
|
|
35
|
+
return code;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The one line that tells the LLM which language the caller speaks now. */
|
|
40
|
+
export function languageNote(code: string): string {
|
|
41
|
+
const name = languageName(code, "en");
|
|
42
|
+
return `The caller now speaks ${name} (${code}). Reply only in ${name}.`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface NoticeText {
|
|
46
|
+
heard: (language: string) => string;
|
|
47
|
+
can: (list: string) => string;
|
|
48
|
+
or: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const NOTICE: Record<string, NoticeText> = {
|
|
52
|
+
en: {
|
|
53
|
+
heard: (l) => `I heard ${l}.`,
|
|
54
|
+
can: (list) => `I can talk with you in ${list}.`,
|
|
55
|
+
or: "or",
|
|
56
|
+
},
|
|
57
|
+
de: {
|
|
58
|
+
heard: (l) => `Ich habe ${l} gehört.`,
|
|
59
|
+
can: (list) => `Ich kann mit dir in diesen Sprachen sprechen: ${list}.`,
|
|
60
|
+
or: "oder",
|
|
61
|
+
},
|
|
62
|
+
es: {
|
|
63
|
+
heard: (l) => `Escuché ${l}.`,
|
|
64
|
+
can: (list) => `Puedo hablar contigo en ${list}.`,
|
|
65
|
+
or: "o",
|
|
66
|
+
},
|
|
67
|
+
fr: {
|
|
68
|
+
heard: (l) => `J'ai entendu ${l}.`,
|
|
69
|
+
can: (list) => `Je peux parler avec vous en ${list}.`,
|
|
70
|
+
or: "ou",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* What the agent says when the caller spoke a language it cannot switch to:
|
|
76
|
+
* in the session's current language, naming the heard language and the
|
|
77
|
+
* supported ones ("I heard Italian. I can talk with you in English, German,
|
|
78
|
+
* Spanish or French.").
|
|
79
|
+
*/
|
|
80
|
+
export function unsupportedNotice(heard: string, current: string): string {
|
|
81
|
+
const lang = isSupported(current)
|
|
82
|
+
? normalizeLanguage(current)
|
|
83
|
+
: DEFAULT_LANGUAGE;
|
|
84
|
+
const text = NOTICE[lang]!;
|
|
85
|
+
const names = SUPPORTED_LANGUAGES.map((c) => languageName(c, lang));
|
|
86
|
+
const list =
|
|
87
|
+
names.length > 1
|
|
88
|
+
? `${names.slice(0, -1).join(", ")} ${text.or} ${names[names.length - 1]}`
|
|
89
|
+
: (names[0] ?? "");
|
|
90
|
+
return `${text.heard(languageName(heard, lang))} ${text.can(list)}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Appends the language note to a copy of the last caller message, so the
|
|
95
|
+
* model sees it last on every call and it never stacks in the history. The
|
|
96
|
+
* LLM message type has no system role; the stored history is not touched.
|
|
97
|
+
*/
|
|
98
|
+
export function withLanguageNote(
|
|
99
|
+
messages: LlmMessage[],
|
|
100
|
+
code: string,
|
|
101
|
+
): LlmMessage[] {
|
|
102
|
+
const note = languageNote(code);
|
|
103
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
104
|
+
const m = messages[i]!;
|
|
105
|
+
if (m.role === "user") {
|
|
106
|
+
const copy = messages.slice();
|
|
107
|
+
copy[i] = { role: "user", text: `${m.text}\n\n(${note})` };
|
|
108
|
+
return copy;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return messages;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Turn id prefix of the unsupported-language notice (not an LLM reply). */
|
|
115
|
+
const NOTICE_TURN_PREFIX = "lang-notice-";
|
|
116
|
+
|
|
117
|
+
interface SessionLanguage {
|
|
118
|
+
/** Committed by the runner (`voice_language_changed`), never a guess. */
|
|
119
|
+
current: string;
|
|
120
|
+
/** Detected language outside the list, waiting for its final. */
|
|
121
|
+
unsupported?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Wraps an LLM agent so it follows the runner's language switch. `create`
|
|
126
|
+
* receives the hooks to pass to `createLlmAgent`.
|
|
127
|
+
*/
|
|
128
|
+
export function languageSwitchAgent(
|
|
129
|
+
create: (hooks: LlmAgentHooks) => AgentHandlers,
|
|
130
|
+
): AgentHandlers {
|
|
131
|
+
const sessions = new Map<string, SessionLanguage>();
|
|
132
|
+
|
|
133
|
+
const llm = create({
|
|
134
|
+
onBeforeLlmCall(messages, ctx) {
|
|
135
|
+
// Typed chat is answered in the language it is written in.
|
|
136
|
+
if (ctx.source === "chat") return;
|
|
137
|
+
const code = sessions.get(ctx.sessionId)?.current ?? DEFAULT_LANGUAGE;
|
|
138
|
+
return withLanguageNote(messages, code);
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
...llm,
|
|
144
|
+
|
|
145
|
+
onSessionStart(ctx) {
|
|
146
|
+
sessions.set(ctx.sessionId, { current: DEFAULT_LANGUAGE });
|
|
147
|
+
if (!isRunnerLidAutoSwitchEnabled(ctx.env)) {
|
|
148
|
+
agentLog(
|
|
149
|
+
"warn",
|
|
150
|
+
"language_switch.auto_off",
|
|
151
|
+
{ detail: "project auto-switch is off; the call stays in English" },
|
|
152
|
+
ctx.sessionId,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return llm.onSessionStart?.(ctx);
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// A detection is not a switch: the runner may still reject it
|
|
159
|
+
// (not_allowed, dwell, confirm). Only tell the client, and remember an
|
|
160
|
+
// unsupported language for the final that follows.
|
|
161
|
+
onUserLanguage(ctx) {
|
|
162
|
+
const language = normalizeLanguage(ctx.language);
|
|
163
|
+
if (!language) return;
|
|
164
|
+
const supported = isSupported(language);
|
|
165
|
+
sendToClient(ctx.sessionId, {
|
|
166
|
+
type: "language_detected",
|
|
167
|
+
language,
|
|
168
|
+
supported,
|
|
169
|
+
});
|
|
170
|
+
const state = sessions.get(ctx.sessionId);
|
|
171
|
+
if (state) state.unsupported = supported ? undefined : language;
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
onVoiceLanguageChanged(ctx) {
|
|
175
|
+
const language = normalizeLanguage(ctx.language);
|
|
176
|
+
if (!language) return;
|
|
177
|
+
const state = sessions.get(ctx.sessionId);
|
|
178
|
+
if (state) {
|
|
179
|
+
state.current = language;
|
|
180
|
+
state.unsupported = undefined;
|
|
181
|
+
}
|
|
182
|
+
sendToClient(ctx.sessionId, { type: "language", language });
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
onUserSpeechFinal(ctx) {
|
|
186
|
+
const state = sessions.get(ctx.sessionId);
|
|
187
|
+
if (state?.unsupported && !ctx.replay) {
|
|
188
|
+
// The transcript came from the wrong language's STT: do not ask the
|
|
189
|
+
// LLM, say what was heard in the current language instead.
|
|
190
|
+
const text = unsupportedNotice(state.unsupported, state.current);
|
|
191
|
+
state.unsupported = undefined;
|
|
192
|
+
const turnId = `${NOTICE_TURN_PREFIX}${ctx.utteranceId ?? Date.now()}`;
|
|
193
|
+
sendToClient(ctx.sessionId, {
|
|
194
|
+
type: "assistant_delta",
|
|
195
|
+
turnId,
|
|
196
|
+
text,
|
|
197
|
+
spoken: true,
|
|
198
|
+
});
|
|
199
|
+
sendToClient(ctx.sessionId, {
|
|
200
|
+
type: "assistant_done",
|
|
201
|
+
turnId,
|
|
202
|
+
text,
|
|
203
|
+
spoken: true,
|
|
204
|
+
status: "completed",
|
|
205
|
+
});
|
|
206
|
+
speak(ctx.sessionId, text, { turnId });
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
return llm.onUserSpeechFinal?.(ctx);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
onAgentInterrupted(ctx) {
|
|
213
|
+
// The notice is not an LLM reply: no interruption note for it.
|
|
214
|
+
if (ctx.turnId?.startsWith(NOTICE_TURN_PREFIX)) return;
|
|
215
|
+
return llm.onAgentInterrupted?.(ctx);
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
onSessionEnd(ctx) {
|
|
219
|
+
sessions.delete(ctx.sessionId);
|
|
220
|
+
return llm.onSessionEnd?.(ctx);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
You are a friendly travel-help assistant. People talk to you by voice, so everything you say is read aloud.
|
|
2
|
+
|
|
3
|
+
Answer in one to three short spoken sentences, in plain words. Do not use markdown, lists, emoji or special characters.
|
|
4
|
+
|
|
5
|
+
Reply in the language the caller speaks now. A note at the end of the conversation names that language; follow it. If the caller types a message, answer in the language the message is written in.
|
|
6
|
+
|
|
7
|
+
Help with simple travel questions: getting around, ordering food, greetings, small talk about a trip. If you do not know something, say so and offer a related tip.
|
|
@@ -0,0 +1,23 @@
|
|
|
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": 256,
|
|
8
|
+
"greeting": {
|
|
9
|
+
"text": "Hi! Talk to me in English, German, Spanish or French. Switch any time and I'll follow.",
|
|
10
|
+
"interruptible": true
|
|
11
|
+
},
|
|
12
|
+
"bargeIn": { "mode": "project" },
|
|
13
|
+
"history": { "turns": 20, "interruptionNote": true },
|
|
14
|
+
"fillers": {
|
|
15
|
+
"thinking": {
|
|
16
|
+
"phrases": ["Okay.", "Right.", "Let me think."],
|
|
17
|
+
"afterMs": 1500
|
|
18
|
+
},
|
|
19
|
+
"interruptible": true
|
|
20
|
+
},
|
|
21
|
+
"toolSources": [],
|
|
22
|
+
"interruptPolicy": "cancel"
|
|
23
|
+
}
|