mojentic 1.0.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +459 -0
  3. package/dist/agents/async-aggregator-agent.d.ts +101 -0
  4. package/dist/agents/async-aggregator-agent.d.ts.map +1 -0
  5. package/dist/agents/async-aggregator-agent.js +160 -0
  6. package/dist/agents/async-aggregator-agent.js.map +1 -0
  7. package/dist/agents/async-dispatcher.d.ts +98 -0
  8. package/dist/agents/async-dispatcher.d.ts.map +1 -0
  9. package/dist/agents/async-dispatcher.js +173 -0
  10. package/dist/agents/async-dispatcher.js.map +1 -0
  11. package/dist/agents/async-llm-agent-with-memory.d.ts +95 -0
  12. package/dist/agents/async-llm-agent-with-memory.d.ts.map +1 -0
  13. package/dist/agents/async-llm-agent-with-memory.js +136 -0
  14. package/dist/agents/async-llm-agent-with-memory.js.map +1 -0
  15. package/dist/agents/async-llm-agent.d.ts +85 -0
  16. package/dist/agents/async-llm-agent.d.ts.map +1 -0
  17. package/dist/agents/async-llm-agent.js +87 -0
  18. package/dist/agents/async-llm-agent.js.map +1 -0
  19. package/dist/agents/base-agent.d.ts +59 -0
  20. package/dist/agents/base-agent.d.ts.map +1 -0
  21. package/dist/agents/base-agent.js +24 -0
  22. package/dist/agents/base-agent.js.map +1 -0
  23. package/dist/agents/base-async-agent.d.ts +42 -0
  24. package/dist/agents/base-async-agent.d.ts.map +1 -0
  25. package/dist/agents/base-async-agent.js +6 -0
  26. package/dist/agents/base-async-agent.js.map +1 -0
  27. package/dist/agents/event.d.ts +26 -0
  28. package/dist/agents/event.d.ts.map +1 -0
  29. package/dist/agents/event.js +13 -0
  30. package/dist/agents/event.js.map +1 -0
  31. package/dist/agents/index.d.ts +14 -0
  32. package/dist/agents/index.d.ts.map +1 -0
  33. package/dist/agents/index.js +30 -0
  34. package/dist/agents/index.js.map +1 -0
  35. package/dist/agents/iterative-problem-solver.d.ts +83 -0
  36. package/dist/agents/iterative-problem-solver.d.ts.map +1 -0
  37. package/dist/agents/iterative-problem-solver.js +120 -0
  38. package/dist/agents/iterative-problem-solver.js.map +1 -0
  39. package/dist/agents/router.d.ts +44 -0
  40. package/dist/agents/router.d.ts.map +1 -0
  41. package/dist/agents/router.js +53 -0
  42. package/dist/agents/router.js.map +1 -0
  43. package/dist/agents/simple-recursive-agent.d.ts +182 -0
  44. package/dist/agents/simple-recursive-agent.d.ts.map +1 -0
  45. package/dist/agents/simple-recursive-agent.js +272 -0
  46. package/dist/agents/simple-recursive-agent.js.map +1 -0
  47. package/dist/context/index.d.ts +5 -0
  48. package/dist/context/index.d.ts.map +1 -0
  49. package/dist/context/index.js +21 -0
  50. package/dist/context/index.js.map +1 -0
  51. package/dist/context/shared-working-memory.d.ts +76 -0
  52. package/dist/context/shared-working-memory.d.ts.map +1 -0
  53. package/dist/context/shared-working-memory.js +121 -0
  54. package/dist/context/shared-working-memory.js.map +1 -0
  55. package/dist/error.d.ts +93 -0
  56. package/dist/error.d.ts.map +1 -0
  57. package/dist/error.js +149 -0
  58. package/dist/error.js.map +1 -0
  59. package/dist/examples/react/decisioning-agent.d.ts +48 -0
  60. package/dist/examples/react/decisioning-agent.d.ts.map +1 -0
  61. package/dist/examples/react/decisioning-agent.js +204 -0
  62. package/dist/examples/react/decisioning-agent.js.map +1 -0
  63. package/dist/examples/react/events.d.ts +77 -0
  64. package/dist/examples/react/events.d.ts.map +1 -0
  65. package/dist/examples/react/events.js +9 -0
  66. package/dist/examples/react/events.js.map +1 -0
  67. package/dist/examples/react/formatters.d.ts +23 -0
  68. package/dist/examples/react/formatters.d.ts.map +1 -0
  69. package/dist/examples/react/formatters.js +68 -0
  70. package/dist/examples/react/formatters.js.map +1 -0
  71. package/dist/examples/react/index.d.ts +12 -0
  72. package/dist/examples/react/index.d.ts.map +1 -0
  73. package/dist/examples/react/index.js +28 -0
  74. package/dist/examples/react/index.js.map +1 -0
  75. package/dist/examples/react/models.d.ts +57 -0
  76. package/dist/examples/react/models.d.ts.map +1 -0
  77. package/dist/examples/react/models.js +19 -0
  78. package/dist/examples/react/models.js.map +1 -0
  79. package/dist/examples/react/output-agent.d.ts +23 -0
  80. package/dist/examples/react/output-agent.d.ts.map +1 -0
  81. package/dist/examples/react/output-agent.js +28 -0
  82. package/dist/examples/react/output-agent.js.map +1 -0
  83. package/dist/examples/react/summarization-agent.d.ts +46 -0
  84. package/dist/examples/react/summarization-agent.d.ts.map +1 -0
  85. package/dist/examples/react/summarization-agent.js +102 -0
  86. package/dist/examples/react/summarization-agent.js.map +1 -0
  87. package/dist/examples/react/thinking-agent.d.ts +47 -0
  88. package/dist/examples/react/thinking-agent.d.ts.map +1 -0
  89. package/dist/examples/react/thinking-agent.js +127 -0
  90. package/dist/examples/react/thinking-agent.js.map +1 -0
  91. package/dist/examples/react/tool-call-agent.d.ts +25 -0
  92. package/dist/examples/react/tool-call-agent.d.ts.map +1 -0
  93. package/dist/examples/react/tool-call-agent.js +83 -0
  94. package/dist/examples/react/tool-call-agent.js.map +1 -0
  95. package/dist/index.d.ts +10 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +28 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/llm/agent.d.ts +68 -0
  100. package/dist/llm/agent.d.ts.map +1 -0
  101. package/dist/llm/agent.js +85 -0
  102. package/dist/llm/agent.js.map +1 -0
  103. package/dist/llm/broker.d.ts +150 -0
  104. package/dist/llm/broker.d.ts.map +1 -0
  105. package/dist/llm/broker.js +355 -0
  106. package/dist/llm/broker.js.map +1 -0
  107. package/dist/llm/chat-session.d.ts +98 -0
  108. package/dist/llm/chat-session.d.ts.map +1 -0
  109. package/dist/llm/chat-session.js +156 -0
  110. package/dist/llm/chat-session.js.map +1 -0
  111. package/dist/llm/gateway.d.ts +28 -0
  112. package/dist/llm/gateway.d.ts.map +1 -0
  113. package/dist/llm/gateway.js +6 -0
  114. package/dist/llm/gateway.js.map +1 -0
  115. package/dist/llm/gateways/index.d.ts +9 -0
  116. package/dist/llm/gateways/index.d.ts.map +1 -0
  117. package/dist/llm/gateways/index.js +25 -0
  118. package/dist/llm/gateways/index.js.map +1 -0
  119. package/dist/llm/gateways/ollama.d.ts +30 -0
  120. package/dist/llm/gateways/ollama.d.ts.map +1 -0
  121. package/dist/llm/gateways/ollama.js +322 -0
  122. package/dist/llm/gateways/ollama.js.map +1 -0
  123. package/dist/llm/gateways/openai-messages-adapter.d.ts +29 -0
  124. package/dist/llm/gateways/openai-messages-adapter.d.ts.map +1 -0
  125. package/dist/llm/gateways/openai-messages-adapter.js +188 -0
  126. package/dist/llm/gateways/openai-messages-adapter.js.map +1 -0
  127. package/dist/llm/gateways/openai-model-registry.d.ts +82 -0
  128. package/dist/llm/gateways/openai-model-registry.d.ts.map +1 -0
  129. package/dist/llm/gateways/openai-model-registry.js +352 -0
  130. package/dist/llm/gateways/openai-model-registry.js.map +1 -0
  131. package/dist/llm/gateways/openai.d.ts +40 -0
  132. package/dist/llm/gateways/openai.d.ts.map +1 -0
  133. package/dist/llm/gateways/openai.js +469 -0
  134. package/dist/llm/gateways/openai.js.map +1 -0
  135. package/dist/llm/gateways/tokenizerGateway.d.ts +61 -0
  136. package/dist/llm/gateways/tokenizerGateway.d.ts.map +1 -0
  137. package/dist/llm/gateways/tokenizerGateway.js +75 -0
  138. package/dist/llm/gateways/tokenizerGateway.js.map +1 -0
  139. package/dist/llm/index.d.ts +11 -0
  140. package/dist/llm/index.d.ts.map +1 -0
  141. package/dist/llm/index.js +27 -0
  142. package/dist/llm/index.js.map +1 -0
  143. package/dist/llm/models.d.ts +95 -0
  144. package/dist/llm/models.d.ts.map +1 -0
  145. package/dist/llm/models.js +50 -0
  146. package/dist/llm/models.js.map +1 -0
  147. package/dist/llm/tools/ask-user.d.ts +39 -0
  148. package/dist/llm/tools/ask-user.d.ts.map +1 -0
  149. package/dist/llm/tools/ask-user.js +111 -0
  150. package/dist/llm/tools/ask-user.js.map +1 -0
  151. package/dist/llm/tools/current-datetime.d.ts +17 -0
  152. package/dist/llm/tools/current-datetime.d.ts.map +1 -0
  153. package/dist/llm/tools/current-datetime.js +76 -0
  154. package/dist/llm/tools/current-datetime.js.map +1 -0
  155. package/dist/llm/tools/date-resolver.d.ts +17 -0
  156. package/dist/llm/tools/date-resolver.d.ts.map +1 -0
  157. package/dist/llm/tools/date-resolver.js +135 -0
  158. package/dist/llm/tools/date-resolver.js.map +1 -0
  159. package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts +13 -0
  160. package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts.map +1 -0
  161. package/dist/llm/tools/ephemeral-task-manager/append-task.js +54 -0
  162. package/dist/llm/tools/ephemeral-task-manager/append-task.js.map +1 -0
  163. package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts +13 -0
  164. package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts.map +1 -0
  165. package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js +37 -0
  166. package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js.map +1 -0
  167. package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts +15 -0
  168. package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts.map +1 -0
  169. package/dist/llm/tools/ephemeral-task-manager/complete-task.js +56 -0
  170. package/dist/llm/tools/ephemeral-task-manager/complete-task.js.map +1 -0
  171. package/dist/llm/tools/ephemeral-task-manager/index.d.ts +44 -0
  172. package/dist/llm/tools/ephemeral-task-manager/index.d.ts.map +1 -0
  173. package/dist/llm/tools/ephemeral-task-manager/index.js +73 -0
  174. package/dist/llm/tools/ephemeral-task-manager/index.js.map +1 -0
  175. package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts +13 -0
  176. package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts.map +1 -0
  177. package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js +59 -0
  178. package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js.map +1 -0
  179. package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts +14 -0
  180. package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts.map +1 -0
  181. package/dist/llm/tools/ephemeral-task-manager/list-tasks.js +45 -0
  182. package/dist/llm/tools/ephemeral-task-manager/list-tasks.js.map +1 -0
  183. package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts +13 -0
  184. package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts.map +1 -0
  185. package/dist/llm/tools/ephemeral-task-manager/prepend-task.js +54 -0
  186. package/dist/llm/tools/ephemeral-task-manager/prepend-task.js.map +1 -0
  187. package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts +15 -0
  188. package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts.map +1 -0
  189. package/dist/llm/tools/ephemeral-task-manager/start-task.js +56 -0
  190. package/dist/llm/tools/ephemeral-task-manager/start-task.js.map +1 -0
  191. package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts +68 -0
  192. package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts.map +1 -0
  193. package/dist/llm/tools/ephemeral-task-manager/task-list.js +120 -0
  194. package/dist/llm/tools/ephemeral-task-manager/task-list.js.map +1 -0
  195. package/dist/llm/tools/ephemeral-task-manager/task.d.ts +21 -0
  196. package/dist/llm/tools/ephemeral-task-manager/task.d.ts.map +1 -0
  197. package/dist/llm/tools/ephemeral-task-manager/task.js +24 -0
  198. package/dist/llm/tools/ephemeral-task-manager/task.js.map +1 -0
  199. package/dist/llm/tools/file-manager.d.ts +127 -0
  200. package/dist/llm/tools/file-manager.d.ts.map +1 -0
  201. package/dist/llm/tools/file-manager.js +598 -0
  202. package/dist/llm/tools/file-manager.js.map +1 -0
  203. package/dist/llm/tools/index.d.ts +11 -0
  204. package/dist/llm/tools/index.d.ts.map +1 -0
  205. package/dist/llm/tools/index.js +27 -0
  206. package/dist/llm/tools/index.js.map +1 -0
  207. package/dist/llm/tools/tell-user.d.ts +31 -0
  208. package/dist/llm/tools/tell-user.d.ts.map +1 -0
  209. package/dist/llm/tools/tell-user.js +57 -0
  210. package/dist/llm/tools/tell-user.js.map +1 -0
  211. package/dist/llm/tools/tool-wrapper.d.ts +54 -0
  212. package/dist/llm/tools/tool-wrapper.d.ts.map +1 -0
  213. package/dist/llm/tools/tool-wrapper.js +91 -0
  214. package/dist/llm/tools/tool-wrapper.js.map +1 -0
  215. package/dist/llm/tools/tool.d.ts +70 -0
  216. package/dist/llm/tools/tool.d.ts.map +1 -0
  217. package/dist/llm/tools/tool.js +19 -0
  218. package/dist/llm/tools/tool.js.map +1 -0
  219. package/dist/llm/tools/web-search-tool.d.ts +35 -0
  220. package/dist/llm/tools/web-search-tool.d.ts.map +1 -0
  221. package/dist/llm/tools/web-search-tool.js +105 -0
  222. package/dist/llm/tools/web-search-tool.js.map +1 -0
  223. package/dist/llm/utils/image.d.ts +30 -0
  224. package/dist/llm/utils/image.d.ts.map +1 -0
  225. package/dist/llm/utils/image.js +65 -0
  226. package/dist/llm/utils/image.js.map +1 -0
  227. package/dist/tracer/eventStore.d.ts +101 -0
  228. package/dist/tracer/eventStore.d.ts.map +1 -0
  229. package/dist/tracer/eventStore.js +120 -0
  230. package/dist/tracer/eventStore.js.map +1 -0
  231. package/dist/tracer/index.d.ts +8 -0
  232. package/dist/tracer/index.d.ts.map +1 -0
  233. package/dist/tracer/index.js +24 -0
  234. package/dist/tracer/index.js.map +1 -0
  235. package/dist/tracer/nullTracer.d.ts +127 -0
  236. package/dist/tracer/nullTracer.d.ts.map +1 -0
  237. package/dist/tracer/nullTracer.js +148 -0
  238. package/dist/tracer/nullTracer.js.map +1 -0
  239. package/dist/tracer/tracerEvents.d.ts +209 -0
  240. package/dist/tracer/tracerEvents.d.ts.map +1 -0
  241. package/dist/tracer/tracerEvents.js +312 -0
  242. package/dist/tracer/tracerEvents.js.map +1 -0
  243. package/dist/tracer/tracerSystem.d.ts +149 -0
  244. package/dist/tracer/tracerSystem.d.ts.map +1 -0
  245. package/dist/tracer/tracerSystem.js +196 -0
  246. package/dist/tracer/tracerSystem.js.map +1 -0
  247. package/package.json +87 -0
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ /**
3
+ * Decision-making agent for the ReAct pattern.
4
+ *
5
+ * This agent evaluates the current context and decides on the next action to take.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DecisioningAgent = void 0;
9
+ const error_1 = require("../../error");
10
+ const models_1 = require("../../llm/models");
11
+ const date_resolver_1 = require("../../llm/tools/date-resolver");
12
+ const models_2 = require("./models");
13
+ const formatters_1 = require("./formatters");
14
+ /**
15
+ * Agent responsible for deciding the next action in the ReAct loop.
16
+ *
17
+ * This agent evaluates the current context, plan, and history to determine
18
+ * whether to continue planning, take an action, or finish and summarize.
19
+ */
20
+ class DecisioningAgent {
21
+ llm;
22
+ static MAX_ITERATIONS = 10;
23
+ tools;
24
+ /**
25
+ * Initialize the decisioning agent.
26
+ *
27
+ * @param llm - The LLM broker to use for generating decisions
28
+ */
29
+ constructor(llm) {
30
+ this.llm = llm;
31
+ this.tools = [new date_resolver_1.DateResolverTool()];
32
+ }
33
+ /**
34
+ * Process a decisioning event and determine the next action.
35
+ *
36
+ * @param event - The decisioning event containing current context
37
+ * @returns Result containing one of: InvokeToolCall, FinishAndSummarize, InvokeThinking, or FailureOccurred event
38
+ */
39
+ async receiveEventAsync(event) {
40
+ if (event.type !== 'InvokeDecisioning') {
41
+ return (0, error_1.Ok)([]);
42
+ }
43
+ const decisioningEvent = event;
44
+ // Check iteration limit
45
+ if (decisioningEvent.context.iteration >= DecisioningAgent.MAX_ITERATIONS) {
46
+ return (0, error_1.Ok)([
47
+ {
48
+ type: 'FailureOccurred',
49
+ source: 'DecisioningAgent',
50
+ context: decisioningEvent.context,
51
+ reason: `Maximum iterations (${DecisioningAgent.MAX_ITERATIONS}) exceeded`,
52
+ correlationId: event.correlationId,
53
+ },
54
+ ]);
55
+ }
56
+ // Increment iteration counter
57
+ decisioningEvent.context.iteration += 1;
58
+ const prompt = this.buildPrompt(decisioningEvent);
59
+ console.log(this.formatBlock(prompt));
60
+ try {
61
+ // Define schema for DecisionResponse
62
+ const schema = {
63
+ type: 'object',
64
+ properties: {
65
+ thought: {
66
+ type: 'string',
67
+ description: 'The reasoning behind the decision',
68
+ },
69
+ nextAction: {
70
+ type: 'string',
71
+ description: 'What should happen next: PLAN, ACT, or FINISH',
72
+ enum: ['PLAN', 'ACT', 'FINISH'],
73
+ },
74
+ toolName: {
75
+ type: 'string',
76
+ description: 'Name of tool to use if nextAction is ACT',
77
+ },
78
+ toolArguments: {
79
+ type: 'object',
80
+ description: 'Arguments for the tool if nextAction is ACT. IMPORTANT: Use the exact parameter names from the tool descriptor. For resolve_date, use "date_string" not "relative_date_found".',
81
+ },
82
+ },
83
+ required: ['thought', 'nextAction'],
84
+ };
85
+ const result = await this.llm.generateObject([models_1.Message.user(prompt)], schema);
86
+ if (!result.ok) {
87
+ return (0, error_1.Ok)([
88
+ {
89
+ type: 'FailureOccurred',
90
+ source: 'DecisioningAgent',
91
+ context: decisioningEvent.context,
92
+ reason: `Error during decision making: ${result.error.message}`,
93
+ correlationId: event.correlationId,
94
+ },
95
+ ]);
96
+ }
97
+ const decision = result.value;
98
+ console.log(this.formatBlock(`Decision: ${JSON.stringify(decision, null, 2)}`));
99
+ // Route based on decision
100
+ if (decision.nextAction === models_2.NextAction.FINISH) {
101
+ return (0, error_1.Ok)([
102
+ {
103
+ type: 'FinishAndSummarize',
104
+ source: 'DecisioningAgent',
105
+ context: decisioningEvent.context,
106
+ thought: decision.thought,
107
+ correlationId: event.correlationId,
108
+ },
109
+ ]);
110
+ }
111
+ if (decision.nextAction === models_2.NextAction.ACT) {
112
+ if (!decision.toolName) {
113
+ return (0, error_1.Ok)([
114
+ {
115
+ type: 'FailureOccurred',
116
+ source: 'DecisioningAgent',
117
+ context: decisioningEvent.context,
118
+ reason: 'ACT decision made but no tool specified',
119
+ correlationId: event.correlationId,
120
+ },
121
+ ]);
122
+ }
123
+ // Find the requested tool
124
+ const tool = this.tools.find((t) => t.descriptor().function.name === decision.toolName);
125
+ if (!tool) {
126
+ return (0, error_1.Ok)([
127
+ {
128
+ type: 'FailureOccurred',
129
+ source: 'DecisioningAgent',
130
+ context: decisioningEvent.context,
131
+ reason: `Tool '${decision.toolName}' not found`,
132
+ correlationId: event.correlationId,
133
+ },
134
+ ]);
135
+ }
136
+ return (0, error_1.Ok)([
137
+ {
138
+ type: 'InvokeToolCall',
139
+ source: 'DecisioningAgent',
140
+ context: decisioningEvent.context,
141
+ thought: decision.thought,
142
+ action: models_2.NextAction.ACT,
143
+ tool,
144
+ toolArguments: decision.toolArguments || {},
145
+ correlationId: event.correlationId,
146
+ },
147
+ ]);
148
+ }
149
+ // PLAN action - go back to thinking
150
+ return (0, error_1.Ok)([
151
+ {
152
+ type: 'InvokeThinking',
153
+ source: 'DecisioningAgent',
154
+ context: decisioningEvent.context,
155
+ correlationId: event.correlationId,
156
+ },
157
+ ]);
158
+ }
159
+ catch (error) {
160
+ return (0, error_1.Ok)([
161
+ {
162
+ type: 'FailureOccurred',
163
+ source: 'DecisioningAgent',
164
+ context: decisioningEvent.context,
165
+ reason: `Error during decision making: ${error instanceof Error ? error.message : String(error)}`,
166
+ correlationId: event.correlationId,
167
+ },
168
+ ]);
169
+ }
170
+ }
171
+ /**
172
+ * Generate the prompt for the decision-making LLM.
173
+ *
174
+ * @param event - The decisioning event containing current context
175
+ * @returns The formatted prompt string
176
+ */
177
+ buildPrompt(event) {
178
+ return `You are to solve a problem by reasoning and acting on the information you have. Here is the current context:
179
+
180
+ ${(0, formatters_1.formatCurrentContext)(event.context)}
181
+ ${(0, formatters_1.formatAvailableTools)(this.tools)}
182
+
183
+ Your Instructions:
184
+ Review the current plan and history. Decide what to do next:
185
+
186
+ 1. PLAN - If the plan is incomplete or needs refinement
187
+ 2. ACT - If you should take an action using one of the available tools
188
+ 3. FINISH - If you have enough information to answer the user's query
189
+
190
+ If you choose ACT, specify which tool to use and what arguments to pass.
191
+ Think carefully about whether each step in the plan has been completed.`;
192
+ }
193
+ /**
194
+ * Format a text block with separators for visual clarity.
195
+ *
196
+ * @param text - The text to format
197
+ * @returns Formatted text with separator lines
198
+ */
199
+ formatBlock(text) {
200
+ return `\n${'='.repeat(80)}\n${text}\n${'='.repeat(80)}\n`;
201
+ }
202
+ }
203
+ exports.DecisioningAgent = DecisioningAgent;
204
+ //# sourceMappingURL=decisioning-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisioning-agent.js","sourceRoot":"","sources":["../../../src/examples/react/decisioning-agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,uCAAyC;AAEzC,6CAA2C;AAC3C,iEAAiE;AAQjE,qCAAsC;AACtC,6CAA0E;AAiB1E;;;;;GAKG;AACH,MAAa,gBAAgB;IASE;IARrB,MAAM,CAAU,cAAc,GAAG,EAAE,CAAC;IAC3B,KAAK,CAAY;IAElC;;;;OAIG;IACH,YAA6B,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;QACzC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,gCAAgB,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY;QAClC,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACvC,OAAO,IAAA,UAAE,EAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,gBAAgB,GAAG,KAA0B,CAAC;QAEpD,wBAAwB;QACxB,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,IAAI,gBAAgB,CAAC,cAAc,EAAE,CAAC;YAC1E,OAAO,IAAA,UAAE,EAAC;gBACR;oBACE,IAAI,EAAE,iBAAiB;oBACvB,MAAM,EAAE,kBAAkB;oBAC1B,OAAO,EAAE,gBAAgB,CAAC,OAAO;oBACjC,MAAM,EAAE,uBAAuB,gBAAgB,CAAC,cAAc,YAAY;oBAC1E,aA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;EACnC,IAAA,iCAAoB,EAAC,IAAI,CAAC,KAAK,CAAC;;;;;;;;;;wEAUsC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACK,WAAW,CAAC,IAAY;QAC9B,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IAC7D,CAAC;;AAxMH,4CAyMC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Event definitions for the ReAct pattern.
3
+ *
4
+ * This module defines all event types used to coordinate the ReAct loop,
5
+ * including thinking, decisioning, tool calls, completion, and failure events.
6
+ */
7
+ import { Event } from '../../agents/event';
8
+ import { CurrentContext, NextAction } from './models';
9
+ import { LlmTool } from '../../llm/tools';
10
+ /**
11
+ * Event to trigger the thinking/planning phase.
12
+ *
13
+ * This event initiates the planning process where the agent creates
14
+ * or refines a plan for answering the user's query.
15
+ */
16
+ export interface InvokeThinking extends Event {
17
+ type: 'InvokeThinking';
18
+ /** The current context as we work through our response */
19
+ context: CurrentContext;
20
+ }
21
+ /**
22
+ * Event to trigger the decision-making phase.
23
+ *
24
+ * This event initiates the decision process where the agent evaluates
25
+ * the current plan and history to decide on the next action.
26
+ */
27
+ export interface InvokeDecisioning extends Event {
28
+ type: 'InvokeDecisioning';
29
+ /** The current context as we work through our response */
30
+ context: CurrentContext;
31
+ }
32
+ /**
33
+ * Event to trigger a tool invocation.
34
+ *
35
+ * This event carries the information needed to execute a specific tool
36
+ * with given arguments, along with the reasoning behind the decision.
37
+ */
38
+ export interface InvokeToolCall extends Event {
39
+ type: 'InvokeToolCall';
40
+ /** The current context as we work through our response */
41
+ context: CurrentContext;
42
+ /** The reasoning behind the decision */
43
+ thought: string;
44
+ /** The next action type */
45
+ action: NextAction;
46
+ /** The tool instance to invoke */
47
+ tool: LlmTool;
48
+ /** Arguments to pass to the tool */
49
+ toolArguments: Record<string, unknown>;
50
+ }
51
+ /**
52
+ * Event to trigger the completion and summarization phase.
53
+ *
54
+ * This event indicates that the agent has gathered sufficient information
55
+ * to answer the user's query and should generate a final response.
56
+ */
57
+ export interface FinishAndSummarize extends Event {
58
+ type: 'FinishAndSummarize';
59
+ /** The current context as we work through our response */
60
+ context: CurrentContext;
61
+ /** The reasoning behind the decision */
62
+ thought: string;
63
+ }
64
+ /**
65
+ * Event to signal a failure in the ReAct loop.
66
+ *
67
+ * This event captures errors or unrecoverable situations that prevent
68
+ * the agent from continuing to process the user's query.
69
+ */
70
+ export interface FailureOccurred extends Event {
71
+ type: 'FailureOccurred';
72
+ /** The current context as we work through our response */
73
+ context: CurrentContext;
74
+ /** The reason for the failure */
75
+ reason: string;
76
+ }
77
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/examples/react/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,IAAI,EAAE,gBAAgB,CAAC;IACvB,0DAA0D;IAC1D,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAkB,SAAQ,KAAK;IAC9C,IAAI,EAAE,mBAAmB,CAAC;IAC1B,0DAA0D;IAC1D,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,IAAI,EAAE,gBAAgB,CAAC;IACvB,0DAA0D;IAC1D,OAAO,EAAE,cAAc,CAAC;IACxB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,kCAAkC;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAmB,SAAQ,KAAK;IAC/C,IAAI,EAAE,oBAAoB,CAAC;IAC3B,0DAA0D;IAC1D,OAAO,EAAE,cAAc,CAAC;IACxB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAgB,SAAQ,KAAK;IAC5C,IAAI,EAAE,iBAAiB,CAAC;IACxB,0DAA0D;IAC1D,OAAO,EAAE,cAAc,CAAC;IACxB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Event definitions for the ReAct pattern.
4
+ *
5
+ * This module defines all event types used to coordinate the ReAct loop,
6
+ * including thinking, decisioning, tool calls, completion, and failure events.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/examples/react/events.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Formatting utilities for the ReAct pattern implementation.
3
+ *
4
+ * This module provides helper functions for formatting context and tool information
5
+ * into human-readable strings for LLM prompts.
6
+ */
7
+ import { CurrentContext } from './models';
8
+ import { LlmTool } from '../../llm/tools';
9
+ /**
10
+ * Format the current context into a readable string.
11
+ *
12
+ * @param context - The current context containing query, plan, and history
13
+ * @returns A formatted multi-line string describing the current context
14
+ */
15
+ export declare function formatCurrentContext(context: CurrentContext): string;
16
+ /**
17
+ * Format the available tools into a readable list.
18
+ *
19
+ * @param tools - A list of tool objects with descriptor methods
20
+ * @returns A formatted string listing available tools and their descriptions
21
+ */
22
+ export declare function formatAvailableTools(tools: LlmTool[]): string;
23
+ //# sourceMappingURL=formatters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../src/examples/react/formatters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAuBpE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAgC7D"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * Formatting utilities for the ReAct pattern implementation.
4
+ *
5
+ * This module provides helper functions for formatting context and tool information
6
+ * into human-readable strings for LLM prompts.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.formatCurrentContext = formatCurrentContext;
10
+ exports.formatAvailableTools = formatAvailableTools;
11
+ /**
12
+ * Format the current context into a readable string.
13
+ *
14
+ * @param context - The current context containing query, plan, and history
15
+ * @returns A formatted multi-line string describing the current context
16
+ */
17
+ function formatCurrentContext(context) {
18
+ const userQuery = `The user has asked us to answer the following query:\n> ${context.userQuery}\n`;
19
+ let plan = 'You have not yet made a plan.\n';
20
+ if (context.plan.steps.length > 0) {
21
+ plan = 'Current plan:\n';
22
+ plan += context.plan.steps.map((step) => `- ${step}`).join('\n');
23
+ plan += '\n';
24
+ }
25
+ let history = 'No steps have yet been taken.\n';
26
+ if (context.history.length > 0) {
27
+ history = "What's been done so far:\n";
28
+ history += context.history
29
+ .map((step, i) => `${i + 1}.\n Thought: ${step.thought}\n Action: ${step.action}\n Observation: ${step.observation}`)
30
+ .join('\n');
31
+ history += '\n';
32
+ }
33
+ return `Current Context:\n${userQuery}${plan}${history}\n`;
34
+ }
35
+ /**
36
+ * Format the available tools into a readable list.
37
+ *
38
+ * @param tools - A list of tool objects with descriptor methods
39
+ * @returns A formatted string listing available tools and their descriptions
40
+ */
41
+ function formatAvailableTools(tools) {
42
+ let output = '';
43
+ if (tools.length > 0) {
44
+ output += 'Tools available:\n';
45
+ for (const tool of tools) {
46
+ const descriptor = tool.descriptor();
47
+ const funcDescriptor = descriptor.function;
48
+ output += `- ${funcDescriptor.name}: ${funcDescriptor.description}\n`;
49
+ // Add parameter information
50
+ if (funcDescriptor.parameters) {
51
+ const params = funcDescriptor.parameters;
52
+ if (params.properties) {
53
+ output += ' Parameters:\n';
54
+ const properties = params.properties;
55
+ const required = params.required || [];
56
+ for (const [paramName, paramInfo] of Object.entries(properties)) {
57
+ const paramDesc = paramInfo.description || '';
58
+ const isRequired = required.includes(paramName);
59
+ const reqStr = isRequired ? ' (required)' : ' (optional)';
60
+ output += ` - ${paramName}${reqStr}: ${paramDesc}\n`;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+ return output;
67
+ }
68
+ //# sourceMappingURL=formatters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../src/examples/react/formatters.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAWH,oDAuBC;AAQD,oDAgCC;AArED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,OAAuB;IAC1D,MAAM,SAAS,GAAG,2DAA2D,OAAO,CAAC,SAAS,IAAI,CAAC;IAEnG,IAAI,IAAI,GAAG,iCAAiC,CAAC;IAC7C,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,IAAI,GAAG,iBAAiB,CAAC;QACzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI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AAC;oBAErD,KAAK,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;wBAChE,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,IAAI,EAAE,CAAC;wBAC9C,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;wBAChD,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;wBAC1D,MAAM,IAAI,SAAS,SAAS,GAAG,MAAM,KAAK,SAAS,IAAI,CAAC;oBAC1D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * ReAct Pattern Example - Module exports
3
+ */
4
+ export * from './models';
5
+ export * from './events';
6
+ export * from './formatters';
7
+ export * from './thinking-agent';
8
+ export * from './decisioning-agent';
9
+ export * from './tool-call-agent';
10
+ export * from './summarization-agent';
11
+ export * from './output-agent';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/examples/react/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * ReAct Pattern Example - Module exports
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./models"), exports);
21
+ __exportStar(require("./events"), exports);
22
+ __exportStar(require("./formatters"), exports);
23
+ __exportStar(require("./thinking-agent"), exports);
24
+ __exportStar(require("./decisioning-agent"), exports);
25
+ __exportStar(require("./tool-call-agent"), exports);
26
+ __exportStar(require("./summarization-agent"), exports);
27
+ __exportStar(require("./output-agent"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/examples/react/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,2CAAyB;AACzB,+CAA6B;AAC7B,mDAAiC;AACjC,sDAAoC;AACpC,oDAAkC;AAClC,wDAAsC;AACtC,iDAA+B"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Base data models for the ReAct pattern.
3
+ *
4
+ * This module defines the core data structures used throughout the ReAct
5
+ * implementation, including actions, plans, observations, and context.
6
+ */
7
+ /**
8
+ * Enumeration of possible next actions in the ReAct loop.
9
+ */
10
+ export declare enum NextAction {
11
+ PLAN = "PLAN",
12
+ ACT = "ACT",
13
+ FINISH = "FINISH"
14
+ }
15
+ /**
16
+ * A single step in the ReAct loop capturing thought, action, and observation.
17
+ *
18
+ * This model represents one iteration of the ReAct pattern where the agent:
19
+ * 1. Thinks about what to do
20
+ * 2. Takes an action
21
+ * 3. Observes the result
22
+ */
23
+ export interface ThoughtActionObservation {
24
+ /** The thought process behind the action taken in the current context */
25
+ thought: string;
26
+ /** The action taken in the current context */
27
+ action: string;
28
+ /** The observation made after the action taken in the current context */
29
+ observation: string;
30
+ }
31
+ /**
32
+ * A structured plan for solving a user query.
33
+ *
34
+ * Contains a list of steps that outline how to approach answering the query.
35
+ */
36
+ export interface Plan {
37
+ /** How to answer the query, step by step, each step outlining an action to take */
38
+ steps: string[];
39
+ }
40
+ /**
41
+ * The complete context for a ReAct session.
42
+ *
43
+ * This model tracks everything needed to maintain state throughout the
44
+ * reasoning and acting loop, including the user's query, the plan,
45
+ * the history of actions, and the iteration count.
46
+ */
47
+ export interface CurrentContext {
48
+ /** The user query to which we are responding */
49
+ userQuery: string;
50
+ /** The current plan of action for the current context */
51
+ plan: Plan;
52
+ /** The history of actions taken and observations made in the current context */
53
+ history: ThoughtActionObservation[];
54
+ /** The number of iterations taken in the current context */
55
+ iteration: number;
56
+ }
57
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/examples/react/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB,mFAAmF;IACnF,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,IAAI,EAAE,IAAI,CAAC;IACX,gFAAgF;IAChF,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Base data models for the ReAct pattern.
4
+ *
5
+ * This module defines the core data structures used throughout the ReAct
6
+ * implementation, including actions, plans, observations, and context.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.NextAction = void 0;
10
+ /**
11
+ * Enumeration of possible next actions in the ReAct loop.
12
+ */
13
+ var NextAction;
14
+ (function (NextAction) {
15
+ NextAction["PLAN"] = "PLAN";
16
+ NextAction["ACT"] = "ACT";
17
+ NextAction["FINISH"] = "FINISH";
18
+ })(NextAction || (exports.NextAction = NextAction = {}));
19
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/examples/react/models.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;GAEG;AACH,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;AACnB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Simple output agent for displaying events in the ReAct pattern.
3
+ *
4
+ * This agent logs event information for debugging and monitoring purposes.
5
+ */
6
+ import { BaseAsyncAgent } from '../../agents/base-async-agent';
7
+ import { Event } from '../../agents/event';
8
+ import { Result } from '../../error';
9
+ /**
10
+ * Agent responsible for outputting event information.
11
+ *
12
+ * This agent receives all events and logs them for monitoring the ReAct workflow.
13
+ */
14
+ export declare class OutputAgent implements BaseAsyncAgent {
15
+ /**
16
+ * Process an event and log its information.
17
+ *
18
+ * @param event - The event to process
19
+ * @returns Empty array (this agent doesn't produce new events)
20
+ */
21
+ receiveEventAsync(event: Event): Promise<Result<Event[], Error>>;
22
+ }
23
+ //# sourceMappingURL=output-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-agent.d.ts","sourceRoot":"","sources":["../../../src/examples/react/output-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAM,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD;;;;;OAKG;IACG,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;CAIvE"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * Simple output agent for displaying events in the ReAct pattern.
4
+ *
5
+ * This agent logs event information for debugging and monitoring purposes.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OutputAgent = void 0;
9
+ const error_1 = require("../../error");
10
+ /**
11
+ * Agent responsible for outputting event information.
12
+ *
13
+ * This agent receives all events and logs them for monitoring the ReAct workflow.
14
+ */
15
+ class OutputAgent {
16
+ /**
17
+ * Process an event and log its information.
18
+ *
19
+ * @param event - The event to process
20
+ * @returns Empty array (this agent doesn't produce new events)
21
+ */
22
+ async receiveEventAsync(event) {
23
+ console.log(`\n[Event: ${event.type}] Source: ${event.source}`);
24
+ return (0, error_1.Ok)([]);
25
+ }
26
+ }
27
+ exports.OutputAgent = OutputAgent;
28
+ //# sourceMappingURL=output-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-agent.js","sourceRoot":"","sources":["../../../src/examples/react/output-agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,uCAAyC;AAEzC;;;;GAIG;AACH,MAAa,WAAW;IACtB;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY;QAClC,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAChE,OAAO,IAAA,UAAE,EAAC,EAAE,CAAC,CAAC;IAChB,CAAC;CACF;AAXD,kCAWC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Summarization agent for the ReAct pattern.
3
+ *
4
+ * This agent generates the final answer based on accumulated context.
5
+ */
6
+ import { BaseAsyncAgent } from '../../agents/base-async-agent';
7
+ import { Event } from '../../agents/event';
8
+ import { Result } from '../../error';
9
+ import { LlmBroker } from '../../llm/broker';
10
+ /**
11
+ * Agent responsible for generating the final answer.
12
+ *
13
+ * This agent reviews the context, plan, and history to synthesize
14
+ * a complete answer to the user's original query.
15
+ */
16
+ export declare class SummarizationAgent implements BaseAsyncAgent {
17
+ private readonly llm;
18
+ /**
19
+ * Initialize the summarization agent.
20
+ *
21
+ * @param llm - The LLM broker to use for generating summaries
22
+ */
23
+ constructor(llm: LlmBroker);
24
+ /**
25
+ * Generate a final answer based on the context.
26
+ *
27
+ * @param event - The finish event containing the complete context
28
+ * @returns Empty array (terminal event) or array with FailureOccurred on error
29
+ */
30
+ receiveEventAsync(event: Event): Promise<Result<Event[], Error>>;
31
+ /**
32
+ * Generate the prompt for the summarization LLM.
33
+ *
34
+ * @param event - The finish event containing the complete context
35
+ * @returns The formatted prompt string
36
+ */
37
+ private buildPrompt;
38
+ /**
39
+ * Format a text block with separators for visual clarity.
40
+ *
41
+ * @param text - The text to format
42
+ * @returns Formatted text with separator lines
43
+ */
44
+ private formatBlock;
45
+ }
46
+ //# sourceMappingURL=summarization-agent.d.ts.map