@voicethere/agent 0.24.0 → 0.26.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 (160) hide show
  1. package/README.md +28 -0
  2. package/dist/agent.js +11 -2
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +11 -0
  6. package/dist/cli.js.map +1 -1
  7. package/dist/flow/classify.d.ts +12 -0
  8. package/dist/flow/classify.d.ts.map +1 -0
  9. package/dist/flow/classify.js +37 -0
  10. package/dist/flow/classify.js.map +1 -0
  11. package/dist/flow/cli-flow.d.ts +19 -0
  12. package/dist/flow/cli-flow.d.ts.map +1 -0
  13. package/dist/flow/cli-flow.js +566 -0
  14. package/dist/flow/cli-flow.js.map +1 -0
  15. package/dist/flow/core/compile.d.ts +131 -0
  16. package/dist/flow/core/compile.d.ts.map +1 -0
  17. package/dist/flow/core/compile.js +197 -0
  18. package/dist/flow/core/compile.js.map +1 -0
  19. package/dist/flow/core/conditions.d.ts +5 -0
  20. package/dist/flow/core/conditions.d.ts.map +1 -0
  21. package/dist/flow/core/conditions.js +70 -0
  22. package/dist/flow/core/conditions.js.map +1 -0
  23. package/dist/flow/core/effects.d.ts +105 -0
  24. package/dist/flow/core/effects.d.ts.map +1 -0
  25. package/dist/flow/core/effects.js +2 -0
  26. package/dist/flow/core/effects.js.map +1 -0
  27. package/dist/flow/core/generate-mock.d.ts +16 -0
  28. package/dist/flow/core/generate-mock.d.ts.map +1 -0
  29. package/dist/flow/core/generate-mock.js +206 -0
  30. package/dist/flow/core/generate-mock.js.map +1 -0
  31. package/dist/flow/core/host.d.ts +9 -0
  32. package/dist/flow/core/host.d.ts.map +1 -0
  33. package/dist/flow/core/host.js +99 -0
  34. package/dist/flow/core/host.js.map +1 -0
  35. package/dist/flow/core/index.d.ts +17 -0
  36. package/dist/flow/core/index.d.ts.map +1 -0
  37. package/dist/flow/core/index.js +17 -0
  38. package/dist/flow/core/index.js.map +1 -0
  39. package/dist/flow/core/interpreter.d.ts +69 -0
  40. package/dist/flow/core/interpreter.d.ts.map +1 -0
  41. package/dist/flow/core/interpreter.js +738 -0
  42. package/dist/flow/core/interpreter.js.map +1 -0
  43. package/dist/flow/core/json-pointer.d.ts +6 -0
  44. package/dist/flow/core/json-pointer.d.ts.map +1 -0
  45. package/dist/flow/core/json-pointer.js +28 -0
  46. package/dist/flow/core/json-pointer.js.map +1 -0
  47. package/dist/flow/core/migrate.d.ts +16 -0
  48. package/dist/flow/core/migrate.d.ts.map +1 -0
  49. package/dist/flow/core/migrate.js +29 -0
  50. package/dist/flow/core/migrate.js.map +1 -0
  51. package/dist/flow/core/mock-effects.d.ts +14 -0
  52. package/dist/flow/core/mock-effects.d.ts.map +1 -0
  53. package/dist/flow/core/mock-effects.js +90 -0
  54. package/dist/flow/core/mock-effects.js.map +1 -0
  55. package/dist/flow/core/mocks.d.ts +55 -0
  56. package/dist/flow/core/mocks.d.ts.map +1 -0
  57. package/dist/flow/core/mocks.js +73 -0
  58. package/dist/flow/core/mocks.js.map +1 -0
  59. package/dist/flow/core/route.d.ts +29 -0
  60. package/dist/flow/core/route.d.ts.map +1 -0
  61. package/dist/flow/core/route.js +61 -0
  62. package/dist/flow/core/route.js.map +1 -0
  63. package/dist/flow/core/schema.d.ts +19 -0
  64. package/dist/flow/core/schema.d.ts.map +1 -0
  65. package/dist/flow/core/schema.js +317 -0
  66. package/dist/flow/core/schema.js.map +1 -0
  67. package/dist/flow/core/template.d.ts +16 -0
  68. package/dist/flow/core/template.d.ts.map +1 -0
  69. package/dist/flow/core/template.js +65 -0
  70. package/dist/flow/core/template.js.map +1 -0
  71. package/dist/flow/core/trace.d.ts +26 -0
  72. package/dist/flow/core/trace.d.ts.map +1 -0
  73. package/dist/flow/core/trace.js +2 -0
  74. package/dist/flow/core/trace.js.map +1 -0
  75. package/dist/flow/core/types.d.ts +159 -0
  76. package/dist/flow/core/types.d.ts.map +1 -0
  77. package/dist/flow/core/types.js +2 -0
  78. package/dist/flow/core/types.js.map +1 -0
  79. package/dist/flow/core/validate.d.ts +3 -0
  80. package/dist/flow/core/validate.d.ts.map +1 -0
  81. package/dist/flow/core/validate.js +550 -0
  82. package/dist/flow/core/validate.js.map +1 -0
  83. package/dist/flow/create-flow-agent.d.ts +36 -0
  84. package/dist/flow/create-flow-agent.d.ts.map +1 -0
  85. package/dist/flow/create-flow-agent.js +175 -0
  86. package/dist/flow/create-flow-agent.js.map +1 -0
  87. package/dist/flow/effects-node.d.ts +21 -0
  88. package/dist/flow/effects-node.d.ts.map +1 -0
  89. package/dist/flow/effects-node.js +189 -0
  90. package/dist/flow/effects-node.js.map +1 -0
  91. package/dist/flow/index.d.ts +12 -0
  92. package/dist/flow/index.d.ts.map +1 -0
  93. package/dist/flow/index.js +7 -0
  94. package/dist/flow/index.js.map +1 -0
  95. package/dist/flow/llm-node.d.ts +24 -0
  96. package/dist/flow/llm-node.d.ts.map +1 -0
  97. package/dist/flow/llm-node.js +251 -0
  98. package/dist/flow/llm-node.js.map +1 -0
  99. package/dist/flow/record.d.ts +22 -0
  100. package/dist/flow/record.d.ts.map +1 -0
  101. package/dist/flow/record.js +126 -0
  102. package/dist/flow/record.js.map +1 -0
  103. package/dist/llm/agent/build-tool-registry.d.ts +26 -0
  104. package/dist/llm/agent/build-tool-registry.d.ts.map +1 -0
  105. package/dist/llm/agent/build-tool-registry.js +106 -0
  106. package/dist/llm/agent/build-tool-registry.js.map +1 -0
  107. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  108. package/dist/llm/agent/create-llm-agent.js +45 -106
  109. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  110. package/dist/llm/anthropic-provider.d.ts.map +1 -1
  111. package/dist/llm/anthropic-provider.js +10 -0
  112. package/dist/llm/anthropic-provider.js.map +1 -1
  113. package/dist/llm/catalog.d.ts +4 -0
  114. package/dist/llm/catalog.d.ts.map +1 -1
  115. package/dist/llm/catalog.js +7 -0
  116. package/dist/llm/catalog.js.map +1 -1
  117. package/dist/llm/gemini-provider.d.ts.map +1 -1
  118. package/dist/llm/gemini-provider.js +12 -0
  119. package/dist/llm/gemini-provider.js.map +1 -1
  120. package/dist/llm/index.d.ts +2 -0
  121. package/dist/llm/index.d.ts.map +1 -1
  122. package/dist/llm/index.js +1 -0
  123. package/dist/llm/index.js.map +1 -1
  124. package/dist/llm/openai-provider.d.ts.map +1 -1
  125. package/dist/llm/openai-provider.js +10 -0
  126. package/dist/llm/openai-provider.js.map +1 -1
  127. package/dist/llm/types.d.ts +7 -2
  128. package/dist/llm/types.d.ts.map +1 -1
  129. package/dist/llm/types.js.map +1 -1
  130. package/dist/protocol.d.ts +4 -0
  131. package/dist/protocol.d.ts.map +1 -1
  132. package/dist/protocol.js.map +1 -1
  133. package/dist/runtime.d.ts +4 -0
  134. package/dist/runtime.d.ts.map +1 -1
  135. package/dist/runtime.js +10 -0
  136. package/dist/runtime.js.map +1 -1
  137. package/dist/templates/echo/agent.js +12 -2
  138. package/dist/templates/flow-agent/agent.js +49085 -0
  139. package/dist/templates/language-switch/agent.js +12 -2
  140. package/dist/templates/llm-agent/agent.js +156 -106
  141. package/dist/templates/llm-docs-rag/agent.js +156 -106
  142. package/dist/templates/llm-mcp-service/agent.js +156 -106
  143. package/dist/templates/positional-tts/agent.js +12 -2
  144. package/dist/templates/recording-consent/agent.js +12 -2
  145. package/dist/templates/registry.d.ts.map +1 -1
  146. package/dist/templates/registry.js +23 -0
  147. package/dist/templates/registry.js.map +1 -1
  148. package/dist/templates/spatial-showcase/agent.js +12 -2
  149. package/dist/templates/voice-showcase/agent.js +12 -2
  150. package/dist/templates/voice-starter/agent.js +12 -2
  151. package/dist/templates/webhooks/agent.js +12 -2
  152. package/eject/llm/loop.ts +51 -104
  153. package/package.json +19 -2
  154. package/schema/voicethere.flow.schema.json +681 -0
  155. package/templates/flow-agent/README.md +38 -0
  156. package/templates/flow-agent/agent.ts +14 -0
  157. package/templates/flow-agent/tools.ts +5 -0
  158. package/templates/flow-agent/voicethere.flow.json +80 -0
  159. package/templates/flow-agent/voicethere.flow.mocks.json +17 -0
  160. package/templates/llm-agent/README.md +4 -2
@@ -0,0 +1,38 @@
1
+ # flow-agent
2
+
3
+ A scripted voice and chat conversation built from nodes: speak, listen, route by example sentences, call an API or an MCP tool, ask an LLM, branch on variables, end. Source: `templates/flow-agent/agent.ts`.
4
+
5
+ ## Files
6
+
7
+ - `agent.ts` wires the flow to the agent runtime. You rarely need to change it.
8
+ - `voicethere.flow.json` is the conversation. The dashboard Flow tab edits this file; you can edit it by hand too.
9
+ - `voicethere.flow.mocks.json` holds mock answers for `route`, `llm`, `http` and `mcp` nodes. It is for local runs only, and the deployed agent never reads it.
10
+ - `tools.ts` lists your own tools for `llm` nodes. It is empty by default.
11
+
12
+ ## Set the API key
13
+
14
+ The flow starts on OpenRouter with the model `anthropic/claude-haiku-5.5`, which supports the forced tool call the route classifier makes. Create a key at openrouter.ai, add it as a project secret named `AGENT_OPENROUTER_API_KEY`, then deploy. The key is read by name from `apiKeySecret` in `voicethere.flow.json`; it is never stored in the file. Only project secrets whose names start with `AGENT_` reach the agent.
15
+
16
+ To use another provider, change `provider`, `model` and `apiKeySecret` in the `models` block and import that provider's module in `agent.ts` (the comment there shows how).
17
+
18
+ ## Test it locally
19
+
20
+ Check the flow file:
21
+
22
+ ```bash
23
+ npx @voicethere/agent flow validate
24
+ ```
25
+
26
+ Talk to it in the terminal with mock answers, so no key and no network are needed:
27
+
28
+ ```bash
29
+ npx @voicethere/agent flow run --mock
30
+ ```
31
+
32
+ Run it with real calls, reading keys from an env file you name:
33
+
34
+ ```bash
35
+ npx @voicethere/agent flow run --env my-keys.env
36
+ ```
37
+
38
+ Add `--record` to save the real HTTP, MCP and LLM answers as mock cases, `--trace out.json` to write the steps, and `--step` to pause before each node. `npx @voicethere/agent flow mock generate` fills the mocks file with generated data. Press Ctrl-C to stop a run: the recording and the trace collected so far are written first, then it exits with code 130. In `--step` mode, Ctrl-C exits without saving the trace or recording.
@@ -0,0 +1,14 @@
1
+ import { defineAgent } from "@voicethere/agent";
2
+ import { createFlowAgent } from "@voicethere/agent/flow";
3
+ import { openai } from "@voicethere/agent/llm/openai";
4
+ import flow from "./voicethere.flow.json";
5
+ import { tools } from "./tools";
6
+
7
+ // The template runs on OpenRouter, which is served by the openai module, so
8
+ // switching between openai and openrouter needs no import change. Only the
9
+ // provider you import here is bundled. To use another provider, change
10
+ // "provider" in the "models" block of voicethere.flow.json and import its
11
+ // module instead:
12
+ // anthropic → import { anthropic } from "@voicethere/agent/llm/anthropic";
13
+ // gemini → import { gemini } from "@voicethere/agent/llm/gemini";
14
+ defineAgent(createFlowAgent({ flow, tools, providers: [openai] }));
@@ -0,0 +1,5 @@
1
+ import type { CustomTool } from "@voicethere/agent/llm";
2
+
3
+ // Custom tools that `llm` nodes can offer (list their names in the node's
4
+ // "tools" field). Build each one with defineTool from "@voicethere/agent/llm".
5
+ export const tools: CustomTool[] = [];
@@ -0,0 +1,80 @@
1
+ {
2
+ "version": 1,
3
+ "start": "greet",
4
+ "models": {
5
+ "default": {
6
+ "provider": "openrouter",
7
+ "model": "anthropic/claude-haiku-5.5",
8
+ "apiKeySecret": "AGENT_OPENROUTER_API_KEY"
9
+ },
10
+ "classifier": { "use": "default" }
11
+ },
12
+ "nodes": [
13
+ {
14
+ "id": "greet",
15
+ "type": "speak",
16
+ "text": "Hi! Is this about billing or support?",
17
+ "interruptible": true,
18
+ "next": "ask"
19
+ },
20
+ {
21
+ "id": "ask",
22
+ "type": "listen",
23
+ "timeoutMs": 8000,
24
+ "next": "topic",
25
+ "onNoInput": "reprompt"
26
+ },
27
+ {
28
+ "id": "reprompt",
29
+ "type": "speak",
30
+ "text": "Sorry, I did not catch that. Is it billing or support?",
31
+ "next": "ask"
32
+ },
33
+ {
34
+ "id": "topic",
35
+ "type": "route",
36
+ "input": "{{last.transcript}}",
37
+ "paths": [
38
+ {
39
+ "id": "billing",
40
+ "examples": [
41
+ "I have a question about my invoice",
42
+ "why was I charged twice",
43
+ "billing"
44
+ ],
45
+ "next": "billingReply"
46
+ },
47
+ {
48
+ "id": "support",
49
+ "examples": [
50
+ "my app is not working",
51
+ "I need help with setup",
52
+ "technical problem"
53
+ ],
54
+ "next": "supportHelp"
55
+ }
56
+ ],
57
+ "onNone": "reprompt",
58
+ "onError": "reprompt",
59
+ "timeoutMs": 3000
60
+ },
61
+ {
62
+ "id": "billingReply",
63
+ "type": "speak",
64
+ "text": "Thanks. A billing specialist will follow up on your invoice by email.",
65
+ "next": "end"
66
+ },
67
+ {
68
+ "id": "supportHelp",
69
+ "type": "llm",
70
+ "instructions": "Help with the caller's support question in two short spoken sentences.",
71
+ "send": "conversation",
72
+ "historyTurns": 6,
73
+ "speak": true,
74
+ "saveAs": "answer",
75
+ "next": "end",
76
+ "onError": "reprompt"
77
+ },
78
+ { "id": "end", "type": "end", "reason": "done" }
79
+ ]
80
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "version": 1,
3
+ "nodes": {
4
+ "topic": [
5
+ { "name": "billing", "route": { "path": "billing" } },
6
+ { "name": "support", "route": { "path": "support" } }
7
+ ],
8
+ "supportHelp": [
9
+ {
10
+ "name": "answer",
11
+ "llm": {
12
+ "text": "Try restarting the app. If that does not help, I will send you the setup guide."
13
+ }
14
+ }
15
+ ]
16
+ }
17
+ }
@@ -34,7 +34,9 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
34
34
  - `toolWait`: a tool round is still running `afterMs` (1000 to 30000, default 4000) after it started. Once per tool round, twice per turn.
35
35
  - 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.
36
36
  - Callers can cut a filler by speaking (`interruptible`, default true). If the answer arrives while a filler plays, the answer follows it.
37
- - Fillers are speech only. They do not appear in the conversation the model sees or in chat text.
37
+ - Fillers are not part of the conversation the model sees (`ConversationHistory`), so the model does not copy them, and they never appear in `assistant_delta`, `assistant_done` or `chat_reply` text.
38
+ - Each filler that is spoken also reaches the client once as `{ "type": "assistant_filler", "turnId", "text" }`, with the `turnId` of the turn it belongs to, so a chat UI can show it as its own line before the reply. A filler that is not spoken (typed chat with `speakChatReplies` off, a limit reached) sends nothing.
39
+ - The speak request for a filler carries `kind: "filler"` and `fillerKind` (`"thinking"`, `"toolCall"` or `"toolWait"`), so a runner can tag the stored utterance. Replies carry neither. Runners that predate the options ignore them.
38
40
  - `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.
39
41
 
40
42
  ## Speech coalescing
@@ -43,7 +45,7 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
43
45
 
44
46
  ## Client messages for voice replies
45
47
 
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.
48
+ 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 part of this reply text; see `assistant_filler` below.
47
49
 
48
50
  ## Always search first
49
51