signalwire-agents 0.1.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 (245) hide show
  1. package/CLAUDE.md +112 -0
  2. package/README.md +417 -0
  3. package/dist/AgentBase.d.ts +481 -0
  4. package/dist/AgentBase.js +1155 -0
  5. package/dist/AgentBase.js.map +1 -0
  6. package/dist/AgentServer.d.ts +60 -0
  7. package/dist/AgentServer.js +128 -0
  8. package/dist/AgentServer.js.map +1 -0
  9. package/dist/AuthHandler.d.ts +56 -0
  10. package/dist/AuthHandler.js +119 -0
  11. package/dist/AuthHandler.js.map +1 -0
  12. package/dist/ConfigLoader.d.ts +68 -0
  13. package/dist/ConfigLoader.js +150 -0
  14. package/dist/ConfigLoader.js.map +1 -0
  15. package/dist/ContextBuilder.d.ts +431 -0
  16. package/dist/ContextBuilder.js +751 -0
  17. package/dist/ContextBuilder.js.map +1 -0
  18. package/dist/DataMap.d.ts +179 -0
  19. package/dist/DataMap.js +321 -0
  20. package/dist/DataMap.js.map +1 -0
  21. package/dist/Logger.d.ts +91 -0
  22. package/dist/Logger.js +191 -0
  23. package/dist/Logger.js.map +1 -0
  24. package/dist/PomBuilder.d.ts +144 -0
  25. package/dist/PomBuilder.js +249 -0
  26. package/dist/PomBuilder.js.map +1 -0
  27. package/dist/PromptManager.d.ts +85 -0
  28. package/dist/PromptManager.js +108 -0
  29. package/dist/PromptManager.js.map +1 -0
  30. package/dist/SchemaUtils.d.ts +42 -0
  31. package/dist/SchemaUtils.js +148 -0
  32. package/dist/SchemaUtils.js.map +1 -0
  33. package/dist/ServerlessAdapter.d.ts +100 -0
  34. package/dist/ServerlessAdapter.js +166 -0
  35. package/dist/ServerlessAdapter.js.map +1 -0
  36. package/dist/SessionManager.d.ts +86 -0
  37. package/dist/SessionManager.js +155 -0
  38. package/dist/SessionManager.js.map +1 -0
  39. package/dist/SslConfig.d.ts +77 -0
  40. package/dist/SslConfig.js +100 -0
  41. package/dist/SslConfig.js.map +1 -0
  42. package/dist/SwaigFunction.d.ts +88 -0
  43. package/dist/SwaigFunction.js +125 -0
  44. package/dist/SwaigFunction.js.map +1 -0
  45. package/dist/SwaigFunctionResult.d.ts +442 -0
  46. package/dist/SwaigFunctionResult.js +735 -0
  47. package/dist/SwaigFunctionResult.js.map +1 -0
  48. package/dist/SwmlBuilder.d.ts +37 -0
  49. package/dist/SwmlBuilder.js +55 -0
  50. package/dist/SwmlBuilder.js.map +1 -0
  51. package/dist/cli/agent-loader.d.ts +22 -0
  52. package/dist/cli/agent-loader.js +106 -0
  53. package/dist/cli/agent-loader.js.map +1 -0
  54. package/dist/cli/mock-data.d.ts +37 -0
  55. package/dist/cli/mock-data.js +79 -0
  56. package/dist/cli/mock-data.js.map +1 -0
  57. package/dist/cli/swaig-test.d.ts +32 -0
  58. package/dist/cli/swaig-test.js +405 -0
  59. package/dist/cli/swaig-test.js.map +1 -0
  60. package/dist/index.d.ts +36 -0
  61. package/dist/index.js +44 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/prefabs/ConciergeAgent.d.ts +64 -0
  64. package/dist/prefabs/ConciergeAgent.js +188 -0
  65. package/dist/prefabs/ConciergeAgent.js.map +1 -0
  66. package/dist/prefabs/FAQBotAgent.d.ts +68 -0
  67. package/dist/prefabs/FAQBotAgent.js +206 -0
  68. package/dist/prefabs/FAQBotAgent.js.map +1 -0
  69. package/dist/prefabs/InfoGathererAgent.d.ts +73 -0
  70. package/dist/prefabs/InfoGathererAgent.js +202 -0
  71. package/dist/prefabs/InfoGathererAgent.js.map +1 -0
  72. package/dist/prefabs/ReceptionistAgent.d.ts +65 -0
  73. package/dist/prefabs/ReceptionistAgent.js +205 -0
  74. package/dist/prefabs/ReceptionistAgent.js.map +1 -0
  75. package/dist/prefabs/SurveyAgent.d.ts +84 -0
  76. package/dist/prefabs/SurveyAgent.js +324 -0
  77. package/dist/prefabs/SurveyAgent.js.map +1 -0
  78. package/dist/prefabs/index.d.ts +13 -0
  79. package/dist/prefabs/index.js +14 -0
  80. package/dist/prefabs/index.js.map +1 -0
  81. package/dist/skills/SkillBase.d.ts +134 -0
  82. package/dist/skills/SkillBase.js +105 -0
  83. package/dist/skills/SkillBase.js.map +1 -0
  84. package/dist/skills/SkillManager.d.ts +83 -0
  85. package/dist/skills/SkillManager.js +159 -0
  86. package/dist/skills/SkillManager.js.map +1 -0
  87. package/dist/skills/SkillRegistry.d.ts +105 -0
  88. package/dist/skills/SkillRegistry.js +195 -0
  89. package/dist/skills/SkillRegistry.js.map +1 -0
  90. package/dist/skills/builtin/api_ninjas_trivia.d.ts +35 -0
  91. package/dist/skills/builtin/api_ninjas_trivia.js +161 -0
  92. package/dist/skills/builtin/api_ninjas_trivia.js.map +1 -0
  93. package/dist/skills/builtin/claude_skills.d.ts +34 -0
  94. package/dist/skills/builtin/claude_skills.js +156 -0
  95. package/dist/skills/builtin/claude_skills.js.map +1 -0
  96. package/dist/skills/builtin/custom_skills.d.ts +59 -0
  97. package/dist/skills/builtin/custom_skills.js +231 -0
  98. package/dist/skills/builtin/custom_skills.js.map +1 -0
  99. package/dist/skills/builtin/datasphere.d.ts +34 -0
  100. package/dist/skills/builtin/datasphere.js +163 -0
  101. package/dist/skills/builtin/datasphere.js.map +1 -0
  102. package/dist/skills/builtin/datasphere_serverless.d.ts +54 -0
  103. package/dist/skills/builtin/datasphere_serverless.js +155 -0
  104. package/dist/skills/builtin/datasphere_serverless.js.map +1 -0
  105. package/dist/skills/builtin/datetime.d.ts +31 -0
  106. package/dist/skills/builtin/datetime.js +95 -0
  107. package/dist/skills/builtin/datetime.js.map +1 -0
  108. package/dist/skills/builtin/google_maps.d.ts +33 -0
  109. package/dist/skills/builtin/google_maps.js +233 -0
  110. package/dist/skills/builtin/google_maps.js.map +1 -0
  111. package/dist/skills/builtin/index.d.ts +28 -0
  112. package/dist/skills/builtin/index.js +75 -0
  113. package/dist/skills/builtin/index.js.map +1 -0
  114. package/dist/skills/builtin/info_gatherer.d.ts +52 -0
  115. package/dist/skills/builtin/info_gatherer.js +237 -0
  116. package/dist/skills/builtin/info_gatherer.js.map +1 -0
  117. package/dist/skills/builtin/joke.d.ts +32 -0
  118. package/dist/skills/builtin/joke.js +142 -0
  119. package/dist/skills/builtin/joke.js.map +1 -0
  120. package/dist/skills/builtin/math.d.ts +33 -0
  121. package/dist/skills/builtin/math.js +120 -0
  122. package/dist/skills/builtin/math.js.map +1 -0
  123. package/dist/skills/builtin/mcp_gateway.d.ts +35 -0
  124. package/dist/skills/builtin/mcp_gateway.js +85 -0
  125. package/dist/skills/builtin/mcp_gateway.js.map +1 -0
  126. package/dist/skills/builtin/native_vector_search.d.ts +44 -0
  127. package/dist/skills/builtin/native_vector_search.js +248 -0
  128. package/dist/skills/builtin/native_vector_search.js.map +1 -0
  129. package/dist/skills/builtin/play_background_file.d.ts +34 -0
  130. package/dist/skills/builtin/play_background_file.js +135 -0
  131. package/dist/skills/builtin/play_background_file.js.map +1 -0
  132. package/dist/skills/builtin/spider.d.ts +34 -0
  133. package/dist/skills/builtin/spider.js +164 -0
  134. package/dist/skills/builtin/spider.js.map +1 -0
  135. package/dist/skills/builtin/swml_transfer.d.ts +44 -0
  136. package/dist/skills/builtin/swml_transfer.js +204 -0
  137. package/dist/skills/builtin/swml_transfer.js.map +1 -0
  138. package/dist/skills/builtin/weather_api.d.ts +34 -0
  139. package/dist/skills/builtin/weather_api.js +136 -0
  140. package/dist/skills/builtin/weather_api.js.map +1 -0
  141. package/dist/skills/builtin/web_search.d.ts +34 -0
  142. package/dist/skills/builtin/web_search.js +141 -0
  143. package/dist/skills/builtin/web_search.js.map +1 -0
  144. package/dist/skills/builtin/wikipedia_search.d.ts +34 -0
  145. package/dist/skills/builtin/wikipedia_search.js +166 -0
  146. package/dist/skills/builtin/wikipedia_search.js.map +1 -0
  147. package/dist/skills/index.d.ts +11 -0
  148. package/dist/skills/index.js +10 -0
  149. package/dist/skills/index.js.map +1 -0
  150. package/dist/types.d.ts +85 -0
  151. package/dist/types.js +5 -0
  152. package/dist/types.js.map +1 -0
  153. package/docs/agent-guide.md +869 -0
  154. package/docs/api-reference.md +2419 -0
  155. package/docs/architecture.md +843 -0
  156. package/docs/cli-guide.md +579 -0
  157. package/docs/configuration.md +422 -0
  158. package/docs/contexts-guide.md +787 -0
  159. package/docs/datamap-guide.md +1141 -0
  160. package/docs/prefabs-guide.md +830 -0
  161. package/docs/security.md +436 -0
  162. package/docs/serverless-guide.md +513 -0
  163. package/docs/skills-guide.md +845 -0
  164. package/docs/swaig-reference.md +1627 -0
  165. package/examples/call-flow.ts +60 -0
  166. package/examples/contexts-steps.ts +62 -0
  167. package/examples/datamap-tools.ts +52 -0
  168. package/examples/dynamic-config.ts +51 -0
  169. package/examples/multi-agent.ts +67 -0
  170. package/examples/pom-prompt.ts +68 -0
  171. package/examples/simple-agent.ts +33 -0
  172. package/package.json +35 -0
  173. package/src/AgentBase.ts +1279 -0
  174. package/src/AgentServer.ts +149 -0
  175. package/src/AuthHandler.ts +141 -0
  176. package/src/ConfigLoader.ts +165 -0
  177. package/src/ContextBuilder.ts +796 -0
  178. package/src/DataMap.ts +365 -0
  179. package/src/Logger.ts +197 -0
  180. package/src/PomBuilder.ts +298 -0
  181. package/src/PromptManager.ts +133 -0
  182. package/src/SchemaUtils.ts +170 -0
  183. package/src/ServerlessAdapter.ts +218 -0
  184. package/src/SessionManager.ts +161 -0
  185. package/src/SslConfig.ts +118 -0
  186. package/src/SwaigFunction.ts +168 -0
  187. package/src/SwaigFunctionResult.ts +864 -0
  188. package/src/SwmlBuilder.ts +62 -0
  189. package/src/cli/agent-loader.ts +122 -0
  190. package/src/cli/mock-data.ts +110 -0
  191. package/src/cli/swaig-test.ts +440 -0
  192. package/src/index.ts +99 -0
  193. package/src/prefabs/ConciergeAgent.ts +251 -0
  194. package/src/prefabs/FAQBotAgent.ts +263 -0
  195. package/src/prefabs/InfoGathererAgent.ts +276 -0
  196. package/src/prefabs/ReceptionistAgent.ts +277 -0
  197. package/src/prefabs/SurveyAgent.ts +413 -0
  198. package/src/prefabs/index.ts +23 -0
  199. package/src/skills/SkillBase.ts +184 -0
  200. package/src/skills/SkillManager.ts +177 -0
  201. package/src/skills/SkillRegistry.ts +231 -0
  202. package/src/skills/builtin/api_ninjas_trivia.ts +230 -0
  203. package/src/skills/builtin/claude_skills.ts +239 -0
  204. package/src/skills/builtin/custom_skills.ts +326 -0
  205. package/src/skills/builtin/datasphere.ts +225 -0
  206. package/src/skills/builtin/datasphere_serverless.ts +194 -0
  207. package/src/skills/builtin/datetime.ts +115 -0
  208. package/src/skills/builtin/google_maps.ts +347 -0
  209. package/src/skills/builtin/index.ts +79 -0
  210. package/src/skills/builtin/info_gatherer.ts +331 -0
  211. package/src/skills/builtin/joke.ts +180 -0
  212. package/src/skills/builtin/math.ts +150 -0
  213. package/src/skills/builtin/mcp_gateway.ts +99 -0
  214. package/src/skills/builtin/native_vector_search.ts +327 -0
  215. package/src/skills/builtin/play_background_file.ts +189 -0
  216. package/src/skills/builtin/spider.ts +232 -0
  217. package/src/skills/builtin/swml_transfer.ts +285 -0
  218. package/src/skills/builtin/weather_api.ts +193 -0
  219. package/src/skills/builtin/web_search.ts +212 -0
  220. package/src/skills/builtin/wikipedia_search.ts +248 -0
  221. package/src/skills/index.ts +12 -0
  222. package/src/types.ts +99 -0
  223. package/tests/AgentBase.test.ts +693 -0
  224. package/tests/AgentServer.test.ts +102 -0
  225. package/tests/AuthHandler.test.ts +121 -0
  226. package/tests/ConfigLoader.test.ts +121 -0
  227. package/tests/DataMap.test.ts +286 -0
  228. package/tests/Logger.test.ts +218 -0
  229. package/tests/PomBuilder.test.ts +164 -0
  230. package/tests/ProxyDetection.test.ts +185 -0
  231. package/tests/SchemaUtils.test.ts +106 -0
  232. package/tests/ServerlessAdapter.test.ts +200 -0
  233. package/tests/SessionManager.test.ts +139 -0
  234. package/tests/SslConfig.test.ts +97 -0
  235. package/tests/SwaigFunctionResult.test.ts +298 -0
  236. package/tests/cli/mock-data.test.ts +94 -0
  237. package/tests/cli/swaig-test.test.ts +96 -0
  238. package/tests/prefabs/prefabs.test.ts +854 -0
  239. package/tests/setup.ts +6 -0
  240. package/tests/skills/SkillBase.test.ts +118 -0
  241. package/tests/skills/SkillManager.test.ts +164 -0
  242. package/tests/skills/SkillRegistry.test.ts +124 -0
  243. package/tests/skills/builtin.test.ts +924 -0
  244. package/tsconfig.json +18 -0
  245. package/vitest.config.ts +9 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Call Flow Verbs Example
3
+ *
4
+ * Control what happens before, during, and after the AI conversation
5
+ * using SWML verbs in the 5-phase rendering pipeline.
6
+ * Run: npx tsx examples/call-flow.ts
7
+ */
8
+
9
+ import { AgentBase, SwaigFunctionResult } from '../src/index.js';
10
+
11
+ const agent = new AgentBase({
12
+ name: 'call-flow-agent',
13
+ route: '/',
14
+ basicAuth: ['user', 'pass'],
15
+ recordCall: true, // Record the call (Phase 3)
16
+ recordFormat: 'mp4',
17
+ recordStereo: true,
18
+ });
19
+
20
+ agent.setPromptText('You are a receptionist. Help callers schedule appointments.');
21
+
22
+ // Phase 1: Play ringing before answering
23
+ agent.addPreAnswerVerb('play', {
24
+ urls: ['ring:us'],
25
+ auto_answer: false,
26
+ });
27
+
28
+ // Phase 3: Play a welcome message after answering but before the AI takes over
29
+ agent.addPostAnswerVerb('play', {
30
+ url: 'say:Welcome to Acme Corp. Please hold while I connect you with our AI assistant.',
31
+ });
32
+
33
+ // Phase 5: Hangup after the AI conversation ends
34
+ agent.addPostAiVerb('hangup', {});
35
+
36
+ // AI config
37
+ agent.addLanguage({ name: 'English', code: 'en-US', voice: 'rachel' });
38
+ agent.addPronunciation({ replace: 'Acme', with: 'Ak-mee' });
39
+ agent.setParam('temperature', 0.7);
40
+
41
+ // Post-prompt for call summary
42
+ agent.setPostPrompt('Provide a JSON summary with: caller_name, appointment_date, appointment_reason');
43
+
44
+ // Tool for scheduling
45
+ agent.defineTool({
46
+ name: 'schedule_appointment',
47
+ description: 'Schedule an appointment for the caller',
48
+ parameters: {
49
+ date: { type: 'string', description: 'Appointment date (YYYY-MM-DD)' },
50
+ time: { type: 'string', description: 'Appointment time (HH:MM)' },
51
+ reason: { type: 'string', description: 'Reason for the appointment' },
52
+ },
53
+ handler: (args) => {
54
+ return new SwaigFunctionResult(
55
+ `Appointment scheduled for ${args.date} at ${args.time}. Reason: ${args.reason}`,
56
+ );
57
+ },
58
+ });
59
+
60
+ agent.run();
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Contexts & Steps Example
3
+ *
4
+ * Multi-step conversation workflows where the AI follows a structured
5
+ * sequence of steps, each with its own prompt, criteria, and allowed tools.
6
+ * Run: npx tsx examples/contexts-steps.ts
7
+ */
8
+
9
+ import { AgentBase, SwaigFunctionResult } from '../src/index.js';
10
+
11
+ const agent = new AgentBase({
12
+ name: 'quiz-agent',
13
+ route: '/',
14
+ basicAuth: ['user', 'pass'],
15
+ });
16
+
17
+ agent.setPromptText('You are a fun quiz host named Quizzy.');
18
+
19
+ // Define tools
20
+ agent.defineTool({
21
+ name: 'get_score',
22
+ description: 'Get the current score for the player',
23
+ parameters: {},
24
+ handler: () => new SwaigFunctionResult('The player has 3 out of 5 correct.'),
25
+ });
26
+
27
+ agent.defineTool({
28
+ name: 'submit_answer',
29
+ description: 'Submit an answer to the current question',
30
+ parameters: {
31
+ answer: { type: 'string', description: 'The answer to check' },
32
+ },
33
+ handler: (args) => {
34
+ return new SwaigFunctionResult(`The answer "${args.answer}" has been recorded.`);
35
+ },
36
+ });
37
+
38
+ // Define the conversation flow
39
+ const ctx = agent.defineContexts();
40
+ const quiz = ctx.addContext('default');
41
+
42
+ // Step 1: Greet the player
43
+ quiz
44
+ .addStep('greeting', { task: 'Welcome the player and explain the quiz rules.' })
45
+ .setStepCriteria('Player has acknowledged the rules and is ready to start')
46
+ .setFunctions('none') // No tools needed for greeting
47
+ .setValidSteps(['question']);
48
+
49
+ // Step 2: Ask questions
50
+ quiz
51
+ .addStep('question', { task: 'Ask the player a trivia question and evaluate their answer.' })
52
+ .setStepCriteria('Player has answered the question')
53
+ .setFunctions(['submit_answer'])
54
+ .setValidSteps(['question', 'results']);
55
+
56
+ // Step 3: Show results
57
+ quiz
58
+ .addStep('results', { task: 'Show the final score and thank the player for playing.' })
59
+ .setFunctions(['get_score'])
60
+ .setEnd(true);
61
+
62
+ agent.run();
@@ -0,0 +1,52 @@
1
+ /**
2
+ * DataMap Tools Example
3
+ *
4
+ * Server-side tools that call external APIs without requiring
5
+ * your own webhook endpoints. The SignalWire platform executes
6
+ * these directly based on the data_map configuration.
7
+ * Run: npx tsx examples/datamap-tools.ts
8
+ */
9
+
10
+ import {
11
+ AgentBase,
12
+ DataMap,
13
+ SwaigFunctionResult,
14
+ createSimpleApiTool,
15
+ } from '../src/index.js';
16
+
17
+ const agent = new AgentBase({
18
+ name: 'weather-agent',
19
+ route: '/',
20
+ basicAuth: ['user', 'pass'],
21
+ });
22
+
23
+ agent.setPromptText(
24
+ 'You are a weather assistant. Help users check the weather in any city.',
25
+ );
26
+
27
+ // Method 1: Build a DataMap manually with full control
28
+ const weatherTool = new DataMap('get_weather')
29
+ .purpose('Get current weather for a city')
30
+ .parameter('city', 'string', 'The city name', { required: true })
31
+ .webhook('GET', 'https://wttr.in/${lc:args.city}?format=j1')
32
+ .output(
33
+ new SwaigFunctionResult(
34
+ 'Weather in ${args.city}: ${response.current_condition[0].temp_F}°F, ${response.current_condition[0].weatherDesc[0].value}',
35
+ ),
36
+ )
37
+ .fallbackOutput(
38
+ new SwaigFunctionResult('Sorry, I could not fetch the weather for that city.'),
39
+ );
40
+
41
+ agent.registerSwaigFunction(weatherTool.toSwaigFunction());
42
+
43
+ // Method 2: Use the createSimpleApiTool helper for quick API integrations
44
+ const jokeTool = createSimpleApiTool({
45
+ name: 'get_joke',
46
+ url: 'https://official-joke-api.appspot.com/random_joke',
47
+ responseTemplate: 'Here is a joke: ${response.setup} ... ${response.punchline}',
48
+ });
49
+
50
+ agent.registerSwaigFunction(jokeTool.toSwaigFunction());
51
+
52
+ agent.run();
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Dynamic Configuration Example
3
+ *
4
+ * Customize agent behavior per-request based on query parameters,
5
+ * headers, or request body. Each request gets an ephemeral copy
6
+ * of the agent, so modifications don't affect other callers.
7
+ * Run: npx tsx examples/dynamic-config.ts
8
+ */
9
+
10
+ import { AgentBase, SwaigFunctionResult } from '../src/index.js';
11
+
12
+ const agent = new AgentBase({
13
+ name: 'dynamic-agent',
14
+ route: '/',
15
+ basicAuth: ['user', 'pass'],
16
+ });
17
+
18
+ agent.setPromptText('You are a helpful assistant.');
19
+
20
+ agent.defineTool({
21
+ name: 'greet',
22
+ description: 'Greet the user by name',
23
+ parameters: {},
24
+ handler: () => new SwaigFunctionResult('Hello!'),
25
+ });
26
+
27
+ // Customize the agent per-request
28
+ agent.setDynamicConfigCallback(async (queryParams, bodyParams, headers, agentCopy) => {
29
+ const copy = agentCopy as AgentBase;
30
+
31
+ // Customize based on query params (e.g., ?lang=es&name=Carlos)
32
+ const lang = queryParams['lang'];
33
+ if (lang === 'es') {
34
+ copy.setPromptText('Eres un asistente amigable. Responde siempre en español.');
35
+ copy.setLanguages([{ name: 'Spanish', code: 'es-ES', voice: 'polly.Lucia' }]);
36
+ } else if (lang === 'fr') {
37
+ copy.setPromptText('Vous êtes un assistant sympathique. Répondez toujours en français.');
38
+ copy.setLanguages([{ name: 'French', code: 'fr-FR', voice: 'polly.Celine' }]);
39
+ }
40
+
41
+ // Customize based on caller info from the request body
42
+ const callerName = queryParams['name'] ?? (bodyParams['caller_name'] as string);
43
+ if (callerName) {
44
+ copy.setGlobalData({ caller_name: callerName });
45
+ copy.setPromptText(
46
+ `You are a helpful assistant. The caller's name is ${callerName}. Greet them by name.`,
47
+ );
48
+ }
49
+ });
50
+
51
+ agent.run();
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Multi-Agent Server Example
3
+ *
4
+ * Host multiple agents under a single HTTP server, each at its own route.
5
+ * Run: npx tsx examples/multi-agent.ts
6
+ * Test:
7
+ * curl http://user:pass@localhost:3000/support
8
+ * curl http://user:pass@localhost:3000/sales
9
+ * curl http://localhost:3000/ (agent listing)
10
+ * curl http://localhost:3000/health
11
+ */
12
+
13
+ import { AgentBase, AgentServer, SwaigFunctionResult } from '../src/index.js';
14
+
15
+ // --- Support Agent ---
16
+ const support = new AgentBase({
17
+ name: 'support',
18
+ route: '/support',
19
+ basicAuth: ['user', 'pass'],
20
+ });
21
+
22
+ support.setPromptText('You are a customer support agent. Help resolve issues quickly and politely.');
23
+ support.addLanguage({ name: 'English', code: 'en-US', voice: 'rachel' });
24
+
25
+ support.defineTool({
26
+ name: 'lookup_ticket',
27
+ description: 'Look up a support ticket by ID',
28
+ parameters: {
29
+ ticket_id: { type: 'string', description: 'The ticket ID' },
30
+ },
31
+ handler: (args) => {
32
+ return new SwaigFunctionResult(`Ticket ${args.ticket_id}: Status is "In Progress", assigned to Team B.`);
33
+ },
34
+ });
35
+
36
+ // --- Sales Agent ---
37
+ const sales = new AgentBase({
38
+ name: 'sales',
39
+ route: '/sales',
40
+ basicAuth: ['user', 'pass'],
41
+ });
42
+
43
+ sales.setPromptText('You are a sales agent. Help potential customers understand our products and pricing.');
44
+ sales.addLanguage({ name: 'English', code: 'en-US', voice: 'dave' });
45
+
46
+ sales.defineTool({
47
+ name: 'get_pricing',
48
+ description: 'Get pricing information for a product',
49
+ parameters: {
50
+ product: { type: 'string', description: 'Product name' },
51
+ },
52
+ handler: (args) => {
53
+ const prices: Record<string, string> = {
54
+ basic: '$29/mo',
55
+ pro: '$99/mo',
56
+ enterprise: 'Custom pricing - schedule a call',
57
+ };
58
+ const price = prices[args.product?.toLowerCase()] ?? 'Product not found';
59
+ return new SwaigFunctionResult(`Pricing for ${args.product}: ${price}`);
60
+ },
61
+ });
62
+
63
+ // --- Server ---
64
+ const server = new AgentServer({ port: 3000 });
65
+ server.register(support);
66
+ server.register(sales);
67
+ server.run();
@@ -0,0 +1,68 @@
1
+ /**
2
+ * POM (Prompt Object Model) Example
3
+ *
4
+ * Build structured prompts with sections, bullets, and subsections
5
+ * instead of raw text strings.
6
+ * Run: npx tsx examples/pom-prompt.ts
7
+ */
8
+
9
+ import { AgentBase, SwaigFunctionResult } from '../src/index.js';
10
+
11
+ const agent = new AgentBase({
12
+ name: 'support-agent',
13
+ route: '/',
14
+ basicAuth: ['user', 'pass'],
15
+ });
16
+
17
+ // Build a structured prompt with POM
18
+ agent.promptAddSection('Role', {
19
+ body: 'You are a technical support agent for Acme Corp.',
20
+ });
21
+
22
+ agent.promptAddSection('Capabilities', {
23
+ bullets: [
24
+ 'Answer questions about our products',
25
+ 'Help troubleshoot common issues',
26
+ 'Escalate complex problems to human agents',
27
+ ],
28
+ });
29
+
30
+ agent.promptAddSection('Guidelines', {
31
+ body: 'Always follow these rules when assisting customers:',
32
+ subsections: [
33
+ {
34
+ title: 'Tone',
35
+ body: 'Be professional, empathetic, and patient.',
36
+ },
37
+ {
38
+ title: 'Escalation',
39
+ body: 'If you cannot resolve the issue in 3 attempts, offer to transfer to a human agent.',
40
+ },
41
+ ],
42
+ });
43
+
44
+ agent.promptAddSection('Product Info', {
45
+ bullets: [
46
+ 'Widget Pro - Our flagship product, $99/mo',
47
+ 'Widget Lite - Basic tier, $29/mo',
48
+ 'Widget Enterprise - Custom pricing',
49
+ ],
50
+ numbered: true,
51
+ });
52
+
53
+ // Add a tool for transferring calls
54
+ agent.defineTool({
55
+ name: 'transfer_to_human',
56
+ description: 'Transfer the caller to a human support agent',
57
+ parameters: {
58
+ reason: { type: 'string', description: 'Reason for the transfer' },
59
+ },
60
+ handler: (_args) => {
61
+ return new SwaigFunctionResult('Transferring you to a human agent now.')
62
+ .connect('+15551234567');
63
+ },
64
+ });
65
+
66
+ agent.setPostPrompt('Summarize the support interaction including the issue and resolution.');
67
+
68
+ agent.run();
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Simple Agent Example
3
+ *
4
+ * A minimal AI voice agent that answers calls and responds to questions.
5
+ * Run: npx tsx examples/simple-agent.ts
6
+ * Test: curl http://user:pass@localhost:3000/
7
+ */
8
+
9
+ import { AgentBase, SwaigFunctionResult } from '../src/index.js';
10
+
11
+ const agent = new AgentBase({
12
+ name: 'simple-agent',
13
+ route: '/',
14
+ basicAuth: ['user', 'pass'],
15
+ });
16
+
17
+ agent.setPromptText('You are a friendly assistant named Siggy. Help callers with their questions.');
18
+
19
+ agent.addHints(['SignalWire', 'SWML', 'Siggy']);
20
+ agent.addLanguage({ name: 'English', code: 'en-US', voice: 'rachel' });
21
+
22
+ // Define a tool the AI can call
23
+ agent.defineTool({
24
+ name: 'get_time',
25
+ description: 'Get the current date and time',
26
+ parameters: {},
27
+ handler: () => {
28
+ const now = new Date().toLocaleString();
29
+ return new SwaigFunctionResult(`The current date and time is ${now}`);
30
+ },
31
+ });
32
+
33
+ agent.run();
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "signalwire-agents",
3
+ "version": "0.1.0",
4
+ "description": "SignalWire AI Agents SDK for TypeScript/Node.js",
5
+ "private": false,
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "bin": {
10
+ "swaig-test": "./dist/cli/swaig-test.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "test": "vitest run",
15
+ "test:watch": "vitest",
16
+ "dev": "tsc --watch",
17
+ "changeset": "changeset",
18
+ "version": "changeset version",
19
+ "release": "changeset publish"
20
+ },
21
+ "engines": {
22
+ "node": ">=18.0.0"
23
+ },
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@hono/node-server": "^1.11.0",
27
+ "hono": "^4.4.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.14.0",
31
+ "changeset": "^0.2.6",
32
+ "typescript": "^5.5.0",
33
+ "vitest": "^1.6.0"
34
+ }
35
+ }