@falai/agent 0.4.0 → 0.5.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 (285) hide show
  1. package/README.md +21 -74
  2. package/dist/cjs/core/Agent.d.ts +22 -29
  3. package/dist/cjs/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/core/Agent.js +465 -275
  5. package/dist/cjs/core/Agent.js.map +1 -1
  6. package/dist/cjs/core/Events.d.ts +10 -1
  7. package/dist/cjs/core/Events.d.ts.map +1 -1
  8. package/dist/cjs/core/Events.js +3 -2
  9. package/dist/cjs/core/Events.js.map +1 -1
  10. package/dist/cjs/core/PersistenceManager.d.ts +19 -0
  11. package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
  12. package/dist/cjs/core/PersistenceManager.js +57 -0
  13. package/dist/cjs/core/PersistenceManager.js.map +1 -1
  14. package/dist/cjs/core/PromptComposer.d.ts +24 -0
  15. package/dist/cjs/core/PromptComposer.d.ts.map +1 -0
  16. package/dist/cjs/core/PromptComposer.js +127 -0
  17. package/dist/cjs/core/PromptComposer.js.map +1 -0
  18. package/dist/cjs/core/ResponseEngine.d.ts +19 -0
  19. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -0
  20. package/dist/cjs/core/ResponseEngine.js +51 -0
  21. package/dist/cjs/core/ResponseEngine.js.map +1 -0
  22. package/dist/cjs/core/Route.d.ts +18 -12
  23. package/dist/cjs/core/Route.d.ts.map +1 -1
  24. package/dist/cjs/core/Route.js +15 -9
  25. package/dist/cjs/core/Route.js.map +1 -1
  26. package/dist/cjs/core/RoutingEngine.d.ts +38 -0
  27. package/dist/cjs/core/RoutingEngine.d.ts.map +1 -0
  28. package/dist/cjs/core/RoutingEngine.js +110 -0
  29. package/dist/cjs/core/RoutingEngine.js.map +1 -0
  30. package/dist/cjs/core/State.d.ts +15 -4
  31. package/dist/cjs/core/State.d.ts.map +1 -1
  32. package/dist/cjs/core/State.js +21 -2
  33. package/dist/cjs/core/State.js.map +1 -1
  34. package/dist/cjs/core/ToolExecutor.d.ts +29 -0
  35. package/dist/cjs/core/ToolExecutor.d.ts.map +1 -0
  36. package/dist/cjs/core/ToolExecutor.js +73 -0
  37. package/dist/cjs/core/ToolExecutor.js.map +1 -0
  38. package/dist/cjs/core/Transition.d.ts +5 -5
  39. package/dist/cjs/core/Transition.d.ts.map +1 -1
  40. package/dist/cjs/core/Transition.js.map +1 -1
  41. package/dist/cjs/index.d.ts +6 -8
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js +8 -10
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/providers/AnthropicProvider.d.ts.map +1 -1
  46. package/dist/cjs/providers/AnthropicProvider.js +10 -13
  47. package/dist/cjs/providers/AnthropicProvider.js.map +1 -1
  48. package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
  49. package/dist/cjs/providers/GeminiProvider.js +12 -8
  50. package/dist/cjs/providers/GeminiProvider.js.map +1 -1
  51. package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
  52. package/dist/cjs/providers/OpenAIProvider.js +10 -53
  53. package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
  54. package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
  55. package/dist/cjs/providers/OpenRouterProvider.js +10 -53
  56. package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
  57. package/dist/cjs/types/agent.d.ts +13 -9
  58. package/dist/cjs/types/agent.d.ts.map +1 -1
  59. package/dist/cjs/types/ai.d.ts +8 -2
  60. package/dist/cjs/types/ai.d.ts.map +1 -1
  61. package/dist/cjs/types/history.d.ts +8 -0
  62. package/dist/cjs/types/history.d.ts.map +1 -1
  63. package/dist/cjs/types/index.d.ts +0 -3
  64. package/dist/cjs/types/index.d.ts.map +1 -1
  65. package/dist/cjs/types/index.js +1 -3
  66. package/dist/cjs/types/index.js.map +1 -1
  67. package/dist/cjs/types/route.d.ts +39 -4
  68. package/dist/cjs/types/route.d.ts.map +1 -1
  69. package/dist/cjs/types/routing.d.ts +16 -0
  70. package/dist/cjs/types/routing.d.ts.map +1 -0
  71. package/dist/cjs/types/routing.js +3 -0
  72. package/dist/cjs/types/routing.js.map +1 -0
  73. package/dist/cjs/types/schema.d.ts +22 -0
  74. package/dist/cjs/types/schema.d.ts.map +1 -0
  75. package/dist/cjs/types/schema.js +3 -0
  76. package/dist/cjs/types/schema.js.map +1 -0
  77. package/dist/cjs/types/session.d.ts +72 -0
  78. package/dist/cjs/types/session.d.ts.map +1 -0
  79. package/dist/cjs/types/session.js +140 -0
  80. package/dist/cjs/types/session.js.map +1 -0
  81. package/dist/cjs/types/tool.d.ts +11 -5
  82. package/dist/cjs/types/tool.d.ts.map +1 -1
  83. package/dist/cjs/utils/id.d.ts +0 -5
  84. package/dist/cjs/utils/id.d.ts.map +1 -1
  85. package/dist/cjs/utils/id.js +0 -10
  86. package/dist/cjs/utils/id.js.map +1 -1
  87. package/dist/cjs/utils/schema.d.ts +17 -0
  88. package/dist/cjs/utils/schema.d.ts.map +1 -0
  89. package/dist/cjs/utils/schema.js +32 -0
  90. package/dist/cjs/utils/schema.js.map +1 -0
  91. package/dist/core/Agent.d.ts +22 -29
  92. package/dist/core/Agent.d.ts.map +1 -1
  93. package/dist/core/Agent.js +465 -275
  94. package/dist/core/Agent.js.map +1 -1
  95. package/dist/core/Events.d.ts +10 -1
  96. package/dist/core/Events.d.ts.map +1 -1
  97. package/dist/core/Events.js +3 -2
  98. package/dist/core/Events.js.map +1 -1
  99. package/dist/core/PersistenceManager.d.ts +19 -0
  100. package/dist/core/PersistenceManager.d.ts.map +1 -1
  101. package/dist/core/PersistenceManager.js +57 -0
  102. package/dist/core/PersistenceManager.js.map +1 -1
  103. package/dist/core/PromptComposer.d.ts +24 -0
  104. package/dist/core/PromptComposer.d.ts.map +1 -0
  105. package/dist/core/PromptComposer.js +123 -0
  106. package/dist/core/PromptComposer.js.map +1 -0
  107. package/dist/core/ResponseEngine.d.ts +19 -0
  108. package/dist/core/ResponseEngine.d.ts.map +1 -0
  109. package/dist/core/ResponseEngine.js +47 -0
  110. package/dist/core/ResponseEngine.js.map +1 -0
  111. package/dist/core/Route.d.ts +18 -12
  112. package/dist/core/Route.d.ts.map +1 -1
  113. package/dist/core/Route.js +15 -9
  114. package/dist/core/Route.js.map +1 -1
  115. package/dist/core/RoutingEngine.d.ts +38 -0
  116. package/dist/core/RoutingEngine.d.ts.map +1 -0
  117. package/dist/core/RoutingEngine.js +106 -0
  118. package/dist/core/RoutingEngine.js.map +1 -0
  119. package/dist/core/State.d.ts +15 -4
  120. package/dist/core/State.d.ts.map +1 -1
  121. package/dist/core/State.js +21 -2
  122. package/dist/core/State.js.map +1 -1
  123. package/dist/core/ToolExecutor.d.ts +29 -0
  124. package/dist/core/ToolExecutor.d.ts.map +1 -0
  125. package/dist/core/ToolExecutor.js +69 -0
  126. package/dist/core/ToolExecutor.js.map +1 -0
  127. package/dist/core/Transition.d.ts +5 -5
  128. package/dist/core/Transition.d.ts.map +1 -1
  129. package/dist/core/Transition.js.map +1 -1
  130. package/dist/index.d.ts +6 -8
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +3 -5
  133. package/dist/index.js.map +1 -1
  134. package/dist/providers/AnthropicProvider.d.ts.map +1 -1
  135. package/dist/providers/AnthropicProvider.js +10 -13
  136. package/dist/providers/AnthropicProvider.js.map +1 -1
  137. package/dist/providers/GeminiProvider.d.ts.map +1 -1
  138. package/dist/providers/GeminiProvider.js +12 -8
  139. package/dist/providers/GeminiProvider.js.map +1 -1
  140. package/dist/providers/OpenAIProvider.d.ts.map +1 -1
  141. package/dist/providers/OpenAIProvider.js +10 -53
  142. package/dist/providers/OpenAIProvider.js.map +1 -1
  143. package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
  144. package/dist/providers/OpenRouterProvider.js +10 -53
  145. package/dist/providers/OpenRouterProvider.js.map +1 -1
  146. package/dist/types/agent.d.ts +13 -9
  147. package/dist/types/agent.d.ts.map +1 -1
  148. package/dist/types/ai.d.ts +8 -2
  149. package/dist/types/ai.d.ts.map +1 -1
  150. package/dist/types/history.d.ts +8 -0
  151. package/dist/types/history.d.ts.map +1 -1
  152. package/dist/types/index.d.ts +0 -3
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/index.js +0 -1
  155. package/dist/types/index.js.map +1 -1
  156. package/dist/types/route.d.ts +39 -4
  157. package/dist/types/route.d.ts.map +1 -1
  158. package/dist/types/routing.d.ts +16 -0
  159. package/dist/types/routing.d.ts.map +1 -0
  160. package/dist/types/routing.js +2 -0
  161. package/dist/types/routing.js.map +1 -0
  162. package/dist/types/schema.d.ts +22 -0
  163. package/dist/types/schema.d.ts.map +1 -0
  164. package/dist/types/schema.js +2 -0
  165. package/dist/types/schema.js.map +1 -0
  166. package/dist/types/session.d.ts +72 -0
  167. package/dist/types/session.d.ts.map +1 -0
  168. package/dist/types/session.js +132 -0
  169. package/dist/types/session.js.map +1 -0
  170. package/dist/types/tool.d.ts +11 -5
  171. package/dist/types/tool.d.ts.map +1 -1
  172. package/dist/utils/id.d.ts +0 -5
  173. package/dist/utils/id.d.ts.map +1 -1
  174. package/dist/utils/id.js +0 -9
  175. package/dist/utils/id.js.map +1 -1
  176. package/dist/utils/schema.d.ts +17 -0
  177. package/dist/utils/schema.d.ts.map +1 -0
  178. package/dist/utils/schema.js +27 -0
  179. package/dist/utils/schema.js.map +1 -0
  180. package/docs/ADAPTERS.md +83 -3
  181. package/docs/API_REFERENCE.md +95 -104
  182. package/docs/ARCHITECTURE.md +284 -286
  183. package/docs/CONSTRUCTOR_OPTIONS.md +192 -135
  184. package/docs/CONTEXT_MANAGEMENT.md +311 -28
  185. package/docs/CONTRIBUTING.md +1 -1
  186. package/docs/DOMAINS.md +61 -0
  187. package/docs/GETTING_STARTED.md +177 -88
  188. package/docs/PERSISTENCE.md +170 -23
  189. package/docs/README.md +7 -10
  190. package/examples/business-onboarding.ts +21 -9
  191. package/examples/company-qna-agent.ts +508 -0
  192. package/examples/declarative-agent.ts +143 -26
  193. package/examples/domain-scoping.ts +31 -10
  194. package/examples/extracted-data-modification.ts +415 -0
  195. package/examples/healthcare-agent.ts +194 -90
  196. package/examples/openai-agent.ts +67 -25
  197. package/examples/opensearch-persistence.ts +455 -151
  198. package/examples/persistent-onboarding.ts +162 -96
  199. package/examples/prisma-persistence.ts +371 -125
  200. package/examples/redis-persistence.ts +393 -23
  201. package/examples/rules-prohibitions.ts +32 -11
  202. package/examples/streaming-agent.ts +61 -13
  203. package/examples/travel-agent.ts +266 -133
  204. package/package.json +1 -1
  205. package/src/core/Agent.ts +679 -332
  206. package/src/core/Events.ts +12 -2
  207. package/src/core/PersistenceManager.ts +83 -0
  208. package/src/core/PromptComposer.ts +143 -0
  209. package/src/core/ResponseEngine.ts +82 -0
  210. package/src/core/Route.ts +32 -17
  211. package/src/core/RoutingEngine.ts +165 -0
  212. package/src/core/State.ts +55 -15
  213. package/src/core/ToolExecutor.ts +117 -0
  214. package/src/core/Transition.ts +5 -5
  215. package/src/index.ts +12 -21
  216. package/src/providers/AnthropicProvider.ts +10 -13
  217. package/src/providers/GeminiProvider.ts +12 -8
  218. package/src/providers/OpenAIProvider.ts +10 -56
  219. package/src/providers/OpenRouterProvider.ts +10 -56
  220. package/src/types/agent.ts +16 -10
  221. package/src/types/ai.ts +6 -2
  222. package/src/types/history.ts +8 -0
  223. package/src/types/index.ts +0 -11
  224. package/src/types/route.ts +41 -5
  225. package/src/types/routing.ts +18 -0
  226. package/src/types/schema.ts +23 -0
  227. package/src/types/session.ts +207 -0
  228. package/src/types/tool.ts +29 -7
  229. package/src/utils/id.ts +0 -10
  230. package/src/utils/schema.ts +32 -0
  231. package/dist/cjs/core/ConditionEvaluator.d.ts +0 -72
  232. package/dist/cjs/core/ConditionEvaluator.d.ts.map +0 -1
  233. package/dist/cjs/core/ConditionEvaluator.js +0 -272
  234. package/dist/cjs/core/ConditionEvaluator.js.map +0 -1
  235. package/dist/cjs/core/Observation.d.ts +0 -24
  236. package/dist/cjs/core/Observation.d.ts.map +0 -1
  237. package/dist/cjs/core/Observation.js +0 -39
  238. package/dist/cjs/core/Observation.js.map +0 -1
  239. package/dist/cjs/core/PreparationEngine.d.ts +0 -105
  240. package/dist/cjs/core/PreparationEngine.d.ts.map +0 -1
  241. package/dist/cjs/core/PreparationEngine.js +0 -320
  242. package/dist/cjs/core/PreparationEngine.js.map +0 -1
  243. package/dist/cjs/core/PromptBuilder.d.ts +0 -136
  244. package/dist/cjs/core/PromptBuilder.d.ts.map +0 -1
  245. package/dist/cjs/core/PromptBuilder.js +0 -421
  246. package/dist/cjs/core/PromptBuilder.js.map +0 -1
  247. package/dist/cjs/types/observation.d.ts +0 -27
  248. package/dist/cjs/types/observation.d.ts.map +0 -1
  249. package/dist/cjs/types/observation.js +0 -6
  250. package/dist/cjs/types/observation.js.map +0 -1
  251. package/dist/cjs/types/prompt.d.ts +0 -46
  252. package/dist/cjs/types/prompt.d.ts.map +0 -1
  253. package/dist/cjs/types/prompt.js +0 -19
  254. package/dist/cjs/types/prompt.js.map +0 -1
  255. package/dist/core/ConditionEvaluator.d.ts +0 -72
  256. package/dist/core/ConditionEvaluator.d.ts.map +0 -1
  257. package/dist/core/ConditionEvaluator.js +0 -268
  258. package/dist/core/ConditionEvaluator.js.map +0 -1
  259. package/dist/core/Observation.d.ts +0 -24
  260. package/dist/core/Observation.d.ts.map +0 -1
  261. package/dist/core/Observation.js +0 -35
  262. package/dist/core/Observation.js.map +0 -1
  263. package/dist/core/PreparationEngine.d.ts +0 -105
  264. package/dist/core/PreparationEngine.d.ts.map +0 -1
  265. package/dist/core/PreparationEngine.js +0 -316
  266. package/dist/core/PreparationEngine.js.map +0 -1
  267. package/dist/core/PromptBuilder.d.ts +0 -136
  268. package/dist/core/PromptBuilder.d.ts.map +0 -1
  269. package/dist/core/PromptBuilder.js +0 -417
  270. package/dist/core/PromptBuilder.js.map +0 -1
  271. package/dist/types/observation.d.ts +0 -27
  272. package/dist/types/observation.d.ts.map +0 -1
  273. package/dist/types/observation.js +0 -5
  274. package/dist/types/observation.js.map +0 -1
  275. package/dist/types/prompt.d.ts +0 -46
  276. package/dist/types/prompt.d.ts.map +0 -1
  277. package/dist/types/prompt.js +0 -16
  278. package/dist/types/prompt.js.map +0 -1
  279. package/docs/STRUCTURE.md +0 -58
  280. package/src/core/ConditionEvaluator.ts +0 -381
  281. package/src/core/Observation.ts +0 -47
  282. package/src/core/PreparationEngine.ts +0 -500
  283. package/src/core/PromptBuilder.ts +0 -617
  284. package/src/types/observation.ts +0 -29
  285. package/src/types/prompt.ts +0 -49
@@ -1,417 +0,0 @@
1
- /**
2
- * Prompt construction and management
3
- */
4
- import { EventKind, EventSource } from "../types/history";
5
- import { SectionStatus } from "../types/prompt";
6
- import { adaptEvent } from "./Events";
7
- /**
8
- * Built-in section identifiers
9
- */
10
- export var BuiltInSection;
11
- (function (BuiltInSection) {
12
- BuiltInSection["AGENT_IDENTITY"] = "agent_identity";
13
- BuiltInSection["CUSTOMER_IDENTITY"] = "customer_identity";
14
- BuiltInSection["INTERACTION_HISTORY"] = "interaction_history";
15
- BuiltInSection["CONTEXT_VARIABLES"] = "context_variables";
16
- BuiltInSection["GLOSSARY"] = "glossary";
17
- BuiltInSection["GUIDELINE_DESCRIPTIONS"] = "guideline_descriptions";
18
- BuiltInSection["GUIDELINES"] = "guidelines";
19
- BuiltInSection["STAGED_EVENTS"] = "staged_events";
20
- BuiltInSection["ROUTES"] = "routes";
21
- BuiltInSection["OBSERVATIONS"] = "observations";
22
- BuiltInSection["CAPABILITIES"] = "capabilities";
23
- BuiltInSection["ACTIVE_ROUTES"] = "active_routes";
24
- BuiltInSection["DOMAINS"] = "domains";
25
- })(BuiltInSection || (BuiltInSection = {}));
26
- /**
27
- * Builds prompts from composable sections
28
- */
29
- export class PromptBuilder {
30
- constructor(onBuild) {
31
- this.sections = new Map();
32
- this.cachedResults = new Set();
33
- this.onBuild = onBuild;
34
- }
35
- /**
36
- * Build the final prompt from all sections
37
- */
38
- build() {
39
- const parts = [];
40
- for (const section of this.sections.values()) {
41
- try {
42
- const formatted = this.formatTemplate(section.template, section.props);
43
- parts.push(formatted);
44
- }
45
- catch (error) {
46
- throw new Error(`Error formatting section: ${error instanceof Error ? error.message : "Unknown error"}`);
47
- }
48
- }
49
- const prompt = parts.join("\n\n").trim();
50
- if (this.onBuild && !this.cachedResults.has(prompt)) {
51
- this.onBuild(prompt);
52
- this.cachedResults.add(prompt);
53
- }
54
- return prompt;
55
- }
56
- /**
57
- * Add a section to the prompt
58
- */
59
- addSection(name, template, props = {}, status) {
60
- if (this.sections.has(name)) {
61
- throw new Error(`Section '${String(name)}' already exists`);
62
- }
63
- this.sections.set(name, {
64
- template,
65
- props,
66
- status,
67
- });
68
- return this;
69
- }
70
- /**
71
- * Edit an existing section
72
- */
73
- editSection(name, editor) {
74
- const section = this.sections.get(name);
75
- if (section) {
76
- this.sections.set(name, editor(section));
77
- }
78
- return this;
79
- }
80
- /**
81
- * Get section status
82
- */
83
- sectionStatus(name) {
84
- const section = this.sections.get(name);
85
- return section?.status || SectionStatus.NONE;
86
- }
87
- /**
88
- * Add agent identity section
89
- */
90
- addAgentIdentity(agent) {
91
- if (agent.description) {
92
- this.addSection(BuiltInSection.AGENT_IDENTITY, `You are an AI agent named {agent_name}.
93
-
94
- The following is a description of your background and personality: ###
95
- {agent_description}
96
- ###`, {
97
- agent_name: agent.name,
98
- agent_description: agent.description,
99
- }, SectionStatus.ACTIVE);
100
- }
101
- return this;
102
- }
103
- /**
104
- * Add customer identity section
105
- */
106
- addCustomerIdentity(customer) {
107
- this.addSection(BuiltInSection.CUSTOMER_IDENTITY, `The user you're interacting with is called {customer_name}.`, { customer_name: customer.name }, SectionStatus.ACTIVE);
108
- return this;
109
- }
110
- /**
111
- * Add interaction history section
112
- */
113
- addInteractionHistory(events, stagedEvents = []) {
114
- if (events.length === 0 && stagedEvents.length === 0) {
115
- this.addSection(BuiltInSection.INTERACTION_HISTORY, `Your interaction with the user has just began, and no events have been recorded yet.
116
- Proceed with your task accordingly.`, {}, SectionStatus.PASSIVE);
117
- }
118
- else {
119
- const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
120
- this.addSection(BuiltInSection.INTERACTION_HISTORY, `The following is a list of events describing a back-and-forth
121
- interaction between you and a user: ###
122
- {interaction_events}
123
- ###`, { interaction_events: interactionEvents.join("\n") }, SectionStatus.ACTIVE);
124
- }
125
- return this;
126
- }
127
- /**
128
- * Add interaction history with special handling for message generation
129
- */
130
- addInteractionHistoryForMessageGeneration(events, stagedEvents = []) {
131
- if (events.length === 0 && stagedEvents.length === 0) {
132
- return this.addInteractionHistory(events, stagedEvents);
133
- }
134
- const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
135
- const lastEventNote = this.lastAgentMessageNote(events);
136
- let template = `The following is a list of events describing a back-and-forth
137
- interaction between you and a user: ###
138
- {interaction_events}
139
- ###`;
140
- const props = {
141
- interaction_events: interactionEvents.join("\n"),
142
- };
143
- if (lastEventNote) {
144
- template += "\n\n{last_event_note}";
145
- props.last_event_note = lastEventNote;
146
- }
147
- this.addSection(BuiltInSection.INTERACTION_HISTORY, template, props, SectionStatus.ACTIVE);
148
- return this;
149
- }
150
- /**
151
- * Add context variables section
152
- */
153
- addContextVariables(variables) {
154
- if (variables.length > 0) {
155
- const contextValues = this.contextVariablesToJson(variables);
156
- this.addSection(BuiltInSection.CONTEXT_VARIABLES, `The following is information that you're given about the user and context of the interaction: ###
157
- {context_values}
158
- ###`, { context_values: contextValues }, SectionStatus.ACTIVE);
159
- }
160
- return this;
161
- }
162
- /**
163
- * Add glossary section
164
- */
165
- addGlossary(terms) {
166
- if (terms.length > 0) {
167
- const termsString = terms
168
- .map((t, i) => {
169
- const synonyms = t.synonyms?.length
170
- ? ` (synonyms: ${t.synonyms.join(", ")})`
171
- : "";
172
- return `${i + 1}) ${t.name}${synonyms}: ${t.description}`;
173
- })
174
- .join("\n");
175
- this.addSection(BuiltInSection.GLOSSARY, `The following is a glossary of the business.
176
- Understanding these terms, as they apply to the business, is critical for your task.
177
- When encountering any of these terms, prioritize the interpretation provided here over any definitions you may already know.
178
- Please be tolerant of possible typos by the user with regards to these terms,
179
- and let the user know if/when you assume they meant a term by their typo: ###
180
- {terms_string}
181
- ###`, { terms_string: termsString }, SectionStatus.ACTIVE);
182
- }
183
- return this;
184
- }
185
- /**
186
- * Add staged tool events section
187
- */
188
- addStagedToolEvents(events) {
189
- const toolEvents = events.filter((e) => e.kind === EventKind.TOOL);
190
- if (toolEvents.length > 0) {
191
- const stagedEventsAsDict = toolEvents.map((e) => adaptEvent(e));
192
- this.addSection(BuiltInSection.STAGED_EVENTS, `Here are the most recent staged events for your reference.
193
- They represent interactions with external tools that perform actions or provide information.
194
- Prioritize their data over any other sources and use their details to complete your task: ###
195
- {staged_events_as_dict}
196
- ###`, { staged_events_as_dict: stagedEventsAsDict.join("\n") }, SectionStatus.ACTIVE);
197
- }
198
- return this;
199
- }
200
- /**
201
- * Add guidelines for message generation
202
- */
203
- addGuidelinesForMessageGeneration(guidelines) {
204
- if (guidelines.length === 0) {
205
- this.addSection(BuiltInSection.GUIDELINE_DESCRIPTIONS, `In formulating your reply, you are normally required to follow a number of behavioral guidelines.
206
- However, in this case, no special behavioral guidelines were provided. Therefore, when generating revisions,
207
- you don't need to specifically double-check if you followed or broke any guidelines.`, {}, SectionStatus.PASSIVE);
208
- return this;
209
- }
210
- const guidelineList = guidelines
211
- .map((g, i) => {
212
- const num = i + 1;
213
- let text = g.guideline.condition
214
- ? `Guideline #${num}) When ${g.guideline.condition}, then ${g.guideline.action}`
215
- : `Guideline #${num}) ${g.guideline.action}`;
216
- if (g.rationale) {
217
- text += `\n - Rationale: ${g.rationale}`;
218
- }
219
- return text;
220
- })
221
- .join("\n");
222
- this.addSection(BuiltInSection.GUIDELINE_DESCRIPTIONS, `When crafting your reply, you must follow the behavioral guidelines provided below, which have been identified as relevant to the current state of the interaction.
223
-
224
- - **Guidelines**:
225
- {guideline_list}
226
-
227
- You may choose not to follow a guideline only in the following cases:
228
- - It conflicts with a previous customer request.
229
- - It is clearly inappropriate given the current context of the conversation.
230
- - It lacks sufficient context or data to apply reliably.
231
- - It conflicts with an insight.
232
-
233
- In all other situations, you are expected to adhere to the guidelines.
234
- These guidelines have already been pre-filtered based on the interaction's context and other considerations outside your scope.`, { guideline_list: guidelineList }, SectionStatus.ACTIVE);
235
- return this;
236
- }
237
- /**
238
- * Add capabilities section for message generation
239
- */
240
- addCapabilitiesForMessageGeneration(capabilities) {
241
- if (capabilities.length > 0) {
242
- const capabilitiesString = capabilities
243
- .map((c, i) => `Supported Capability ${i + 1}: ${c.title}
244
- ${c.description}`)
245
- .join("\n\n");
246
- this.addSection(BuiltInSection.CAPABILITIES, `Below are the capabilities available to you as an agent.
247
- You may inform the customer that you can assist them using these capabilities.
248
- If you choose to use any of them, additional details will be provided in your next response.
249
- Always prefer adhering to guidelines, before offering capabilities - only offer capabilities if you have no other instruction that's relevant for the current stage of the interaction.
250
- Be proactive and offer the most relevant capabilities—but only if they are likely to move the conversation forward.
251
- If multiple capabilities are appropriate, aim to present them all to the customer.
252
- If none of the capabilities address the current request of the customer - DO NOT MENTION THEM.
253
- ###
254
- {capabilities_string}
255
- ###`, { capabilities_string: capabilitiesString }, SectionStatus.ACTIVE);
256
- }
257
- return this;
258
- }
259
- /**
260
- * Add observations for disambiguation
261
- */
262
- addObservations(observations) {
263
- if (observations.length > 0) {
264
- const observationsString = observations
265
- .map((obs, i) => {
266
- const routeTitles = obs.routes.map((r) => `"${r.title}"`).join(", ");
267
- return `${i + 1}) "${obs.description}" → Can lead to routes: ${routeTitles}`;
268
- })
269
- .join("\n");
270
- this.addSection(BuiltInSection.OBSERVATIONS, `The following observations may help you understand the user's intent and choose the appropriate response path:
271
- ###
272
- {observations_string}
273
- ###
274
-
275
- When you detect any of these situations, consider which route would be most appropriate based on the user's actual need.`, { observations_string: observationsString }, SectionStatus.ACTIVE);
276
- }
277
- return this;
278
- }
279
- /**
280
- * Add active routes information
281
- */
282
- addActiveRoutes(routes) {
283
- if (routes.length > 0) {
284
- const routesString = routes
285
- .map((route, i) => {
286
- const conditions = route.conditions.length > 0
287
- ? `\n Triggered when: ${route.conditions.join(" OR ")}`
288
- : "";
289
- const desc = route.description ? `\n ${route.description}` : "";
290
- let domainInfo = "";
291
- if (route.domains !== undefined) {
292
- if (route.domains.length === 0) {
293
- domainInfo = "\n Available tools: None (conversation only)";
294
- }
295
- else {
296
- domainInfo = `\n Available tools: ${route.domains.join(", ")}`;
297
- }
298
- }
299
- let rulesInfo = "";
300
- if (route.rules && route.rules.length > 0) {
301
- const rulesList = route.rules
302
- .map((r, idx) => `${idx + 1}. ${r}`)
303
- .join("; ");
304
- rulesInfo = `\n RULES: ${rulesList}`;
305
- }
306
- let prohibitionsInfo = "";
307
- if (route.prohibitions && route.prohibitions.length > 0) {
308
- const prohibitionsList = route.prohibitions
309
- .map((p, idx) => `${idx + 1}. ${p}`)
310
- .join("; ");
311
- prohibitionsInfo = `\n PROHIBITIONS: ${prohibitionsList}`;
312
- }
313
- return `${i + 1}) ${route.title}${desc}${conditions}${domainInfo}${rulesInfo}${prohibitionsInfo}`;
314
- })
315
- .join("\n\n");
316
- this.addSection(BuiltInSection.ACTIVE_ROUTES, `Available conversation routes:
317
- ###
318
- {routes_string}
319
- ###
320
-
321
- These routes represent different paths the conversation can take. Choose the most appropriate route based on the user's needs.
322
- IMPORTANT:
323
- - If a route specifies available tools, you can ONLY call tools from those domains when following that route.
324
- - If a route has RULES, you MUST follow them when you choose that route.
325
- - If a route has PROHIBITIONS, you MUST NEVER do those things when you choose that route.`, { routes_string: routesString }, SectionStatus.ACTIVE);
326
- }
327
- return this;
328
- }
329
- /**
330
- * Add domains (tools) information
331
- */
332
- addDomains(domains) {
333
- const domainNames = Object.keys(domains);
334
- if (domainNames.length > 0) {
335
- const domainsString = domainNames
336
- .map((name, i) => {
337
- const toolNames = Object.keys(domains[name]);
338
- const tools = toolNames.join(", ");
339
- return `${i + 1}) Domain "${name}": ${tools}`;
340
- })
341
- .join("\n");
342
- this.addSection(BuiltInSection.DOMAINS, `Available tool domains:
343
- ###
344
- {domains_string}
345
- ###
346
-
347
- These are the tool domains registered in the system. Each domain contains specific tools/methods.
348
- When calling tools, use the format: domain.toolName (e.g., "payment.processPayment").`, { domains_string: domainsString }, SectionStatus.ACTIVE);
349
- }
350
- return this;
351
- }
352
- /**
353
- * Add JSON response schema instructions
354
- *
355
- * NOTE: toolCalls are NOT included. Tools execute automatically based on
356
- * state transitions and guideline matching, NOT based on AI decisions.
357
- */
358
- addJsonResponseSchema() {
359
- const schema = {
360
- message: "The actual message to send to the user",
361
- route: "The title of the route you chose (or null if no specific route)",
362
- state: "The current state within the chosen route (or null if not in a route)",
363
- reasoning: "Optional: Your internal reasoning for this response",
364
- };
365
- this.addSection("json_response_format", `IMPORTANT: You must respond with valid JSON in the following format:
366
-
367
- \`\`\`json
368
- ${JSON.stringify(schema, null, 2)}
369
- \`\`\`
370
-
371
- Instructions:
372
- - "message": The actual message to send to the user (required)
373
- - "route": If you chose a specific conversation route, provide its exact title. If not in a route, use null.
374
- - "state": The current state within the chosen route. If not in a route or at initial state, use null.
375
- - "reasoning": Optional field for your internal thinking process.
376
-
377
- Your entire response must be valid JSON. Do not include any text before or after the JSON object.`, {}, SectionStatus.ACTIVE);
378
- return this;
379
- }
380
- // Helper methods
381
- formatTemplate(template, props) {
382
- return template.replace(/\{(\w+)\}/g, (match, key) => {
383
- if (key in props) {
384
- return String(props[key]);
385
- }
386
- return match;
387
- });
388
- }
389
- gatherInteractionEvents(events, stagedEvents) {
390
- const combined = [...events, ...stagedEvents];
391
- return combined
392
- .filter((e) => e.kind !== EventKind.STATUS)
393
- .map((e) => adaptEvent(e));
394
- }
395
- lastAgentMessageNote(events) {
396
- const lastMessageEvent = [...events]
397
- .reverse()
398
- .find((e) => e.kind === EventKind.MESSAGE);
399
- if (!lastMessageEvent || lastMessageEvent.source !== EventSource.AI_AGENT) {
400
- return null;
401
- }
402
- const lastMessage = lastMessageEvent.data.message;
403
- return `IMPORTANT: Please note that the last message was sent by you, the AI agent (likely as a preamble). Your last message was: ###
404
- ${lastMessage}
405
- ###
406
-
407
- You must keep that in mind when responding to the user, to continue the last message naturally (without repeating anything similar in your last message - make sure you don't repeat something like this in your next message - it was already said!).`;
408
- }
409
- contextVariablesToJson(variables) {
410
- const obj = {};
411
- for (const v of variables) {
412
- obj[v.variable.name] = v.value;
413
- }
414
- return JSON.stringify(obj, null, 2);
415
- }
416
- }
417
- //# sourceMappingURL=PromptBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromptBuilder.js","sourceRoot":"","sources":["../../src/core/PromptBuilder.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAN,IAAY,cAcX;AAdD,WAAY,cAAc;IACxB,mDAAiC,CAAA;IACjC,yDAAuC,CAAA;IACvC,6DAA2C,CAAA;IAC3C,yDAAuC,CAAA;IACvC,uCAAqB,CAAA;IACrB,mEAAiD,CAAA;IACjD,2CAAyB,CAAA;IACzB,iDAA+B,CAAA;IAC/B,mCAAiB,CAAA;IACjB,+CAA6B,CAAA;IAC7B,+CAA6B,CAAA;IAC7B,iDAA+B,CAAA;IAC/B,qCAAmB,CAAA;AACrB,CAAC,EAdW,cAAc,KAAd,cAAc,QAczB;AAkBD;;GAEG;AACH,MAAM,OAAO,aAAa;IAKxB,YAAY,OAAkC;QAJtC,aAAQ,GAAgD,IAAI,GAAG,EAAE,CAAC;QAElE,kBAAa,GAAG,IAAI,GAAG,EAAU,CAAC;QAGxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,K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,GAAG,CAAC,GAAG,MAAM,CAAC;aACjC,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAI,gBAAgB,CAAC,IAAyB,CAAC,OAAO,CAAC;QACxE,OAAO;EACT,WAAW;;;uPAG0O,CAAC;IACtP,CAAC;IAEO,sBAAsB,CAAC,SAAiC;QAC9D,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;YAC1B,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Observation types for disambiguation
3
- */
4
- import type { RouteRef } from "./route";
5
- /**
6
- * An observation that can disambiguate between multiple routes
7
- */
8
- export interface Observation {
9
- /** Unique identifier */
10
- id: string;
11
- /** The observation description */
12
- description: string;
13
- /** Routes this observation can disambiguate between */
14
- routes?: RouteRef[];
15
- }
16
- /**
17
- * Options for creating an observation
18
- */
19
- export interface ObservationOptions {
20
- /** Custom ID for the observation (optional - will generate deterministic ID from description if not provided) */
21
- id?: string;
22
- /** The observation description */
23
- description: string;
24
- /** Route IDs or titles to disambiguate between (can be set later with disambiguate()) */
25
- routeRefs?: string[];
26
- }
27
- //# sourceMappingURL=observation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../../src/types/observation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iHAAiH;IACjH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Observation types for disambiguation
3
- */
4
- export {};
5
- //# sourceMappingURL=observation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observation.js","sourceRoot":"","sources":["../../src/types/observation.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Prompt building types
3
- */
4
- /**
5
- * Status of a prompt section
6
- */
7
- export declare enum SectionStatus {
8
- /** Section has active information */
9
- ACTIVE = "active",
10
- /** Section is inactive but may have empty-state text */
11
- PASSIVE = "passive",
12
- /** Section is not included */
13
- NONE = "none"
14
- }
15
- /**
16
- * A section within a prompt
17
- */
18
- export interface PromptSection {
19
- /** Template string (may contain placeholders) */
20
- template: string;
21
- /** Properties to fill template placeholders */
22
- props: Record<string, unknown>;
23
- /** Status of this section */
24
- status?: SectionStatus;
25
- }
26
- /**
27
- * Context variable with value
28
- */
29
- export interface ContextVariable {
30
- /** Variable name */
31
- name: string;
32
- /** Variable description */
33
- description?: string;
34
- /** Variable type */
35
- type?: string;
36
- }
37
- /**
38
- * Value for a context variable
39
- */
40
- export interface ContextVariableValue {
41
- /** The variable definition */
42
- variable: ContextVariable;
43
- /** The current value */
44
- value: unknown;
45
- }
46
- //# sourceMappingURL=prompt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/types/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,aAAa;IACvB,qCAAqC;IACrC,MAAM,WAAW;IACjB,wDAAwD;IACxD,OAAO,YAAY;IACnB,8BAA8B;IAC9B,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,6BAA6B;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8BAA8B;IAC9B,QAAQ,EAAE,eAAe,CAAC;IAC1B,wBAAwB;IACxB,KAAK,EAAE,OAAO,CAAC;CAChB"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Prompt building types
3
- */
4
- /**
5
- * Status of a prompt section
6
- */
7
- export var SectionStatus;
8
- (function (SectionStatus) {
9
- /** Section has active information */
10
- SectionStatus["ACTIVE"] = "active";
11
- /** Section is inactive but may have empty-state text */
12
- SectionStatus["PASSIVE"] = "passive";
13
- /** Section is not included */
14
- SectionStatus["NONE"] = "none";
15
- })(SectionStatus || (SectionStatus = {}));
16
- //# sourceMappingURL=prompt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/types/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,qCAAqC;IACrC,kCAAiB,CAAA;IACjB,wDAAwD;IACxD,oCAAmB,CAAA;IACnB,8BAA8B;IAC9B,8BAAa,CAAA;AACf,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB"}
package/docs/STRUCTURE.md DELETED
@@ -1,58 +0,0 @@
1
- # Package Structure
2
-
3
- ```
4
- src/
5
- ├── types/ # Type definitions (interfaces, types, enums)
6
- │ ├── agent.ts # Agent types and configuration
7
- │ ├── ai.ts # AI provider interfaces
8
- │ ├── history.ts # Event and message history types
9
- │ ├── observation.ts # Observation and disambiguation types
10
- │ ├── persistence.ts # Persistence adapter interfaces
11
- │ ├── prompt.ts # Prompt building types
12
- │ ├── route.ts # Route and state types
13
- │ ├── tool.ts # Tool definition types
14
- │ └── index.ts # Type exports
15
- ├── core/ # Core framework classes
16
- │ ├── Agent.ts # Main agent class
17
- │ ├── Route.ts # Route/Journey DSL
18
- │ ├── State.ts # State management
19
- │ ├── Transition.ts # State transitions
20
- │ ├── Observation.ts # Disambiguation
21
- │ ├── Tool.ts # Tool definitions
22
- │ ├── PromptBuilder.ts # Prompt construction
23
- │ ├── Events.ts # Event history
24
- │ ├── DomainRegistry.ts # Domain organization
25
- │ └── PersistenceManager.ts # Persistence lifecycle management
26
- ├── providers/ # AI provider implementations
27
- │ ├── AnthropicProvider.ts # Claude (Anthropic)
28
- │ ├── GeminiProvider.ts # Google Gemini
29
- │ ├── OpenAIProvider.ts # OpenAI GPT
30
- │ ├── OpenRouterProvider.ts # OpenRouter (200+ models)
31
- │ └── index.ts # Provider exports
32
- ├── adapters/ # Database persistence adapters
33
- │ ├── MemoryAdapter.ts # In-memory (testing/dev)
34
- │ ├── PrismaAdapter.ts # Prisma ORM
35
- │ ├── RedisAdapter.ts # Redis
36
- │ ├── MongoAdapter.ts # MongoDB
37
- │ ├── PostgreSQLAdapter.ts # PostgreSQL
38
- │ ├── SQLiteAdapter.ts # SQLite
39
- │ ├── OpenSearchAdapter.ts # OpenSearch/Elasticsearch
40
- │ └── index.ts # Adapter exports
41
- ├── utils/ # Utility functions
42
- │ ├── retry.ts # Retry/timeout logic
43
- │ └── id.ts # Deterministic ID generation
44
- ├── constants/ # Constants and symbols
45
- │ └── index.ts # END_ROUTE, EventSource, etc.
46
- └── index.ts # Public API exports
47
- ```
48
-
49
- ## Design Principles
50
-
51
- 1. **Flat, organized structure** - Clear separation by purpose
52
- 2. **Types-first** - All types in dedicated folder
53
- 3. **Core logic isolated** - Business logic in \`core/\`
54
- 4. **Provider pattern** - Pluggable AI backends and database adapters
55
- 5. **Optional persistence** - Multiple database adapters following the same pattern
56
- 6. **Extensibility** - Easy to add new providers, adapters, and tools
57
- 7. **Path aliases** - Clean imports with \`@/types\`, \`@/core\`, etc.
58
- 8. **Fluent API** - Methods return \`this\` for chaining