@mastra/core 0.19.1 → 0.20.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 (179) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/dist/agent/agent.d.ts +17 -31
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +2 -2
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +11 -11
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/input-processor/index.cjs +6 -6
  9. package/dist/agent/input-processor/index.js +1 -1
  10. package/dist/agent/types.d.ts +1 -6
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/agent/workflows/prepare-stream/index.d.ts +3 -3
  13. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  14. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +3 -3
  15. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  16. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +1 -1
  17. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  18. package/dist/agent/workflows/prepare-stream/schema.d.ts +2 -2
  19. package/dist/ai-tracing/index.cjs +32 -32
  20. package/dist/ai-tracing/index.js +1 -1
  21. package/dist/{chunk-QFKTSGBI.js → chunk-2DVGQK2L.js} +4 -4
  22. package/dist/chunk-2DVGQK2L.js.map +1 -0
  23. package/dist/{chunk-HJQ7ANDX.cjs → chunk-2JUDZXVI.cjs} +4 -4
  24. package/dist/chunk-2JUDZXVI.cjs.map +1 -0
  25. package/dist/{chunk-SZD4WTRW.cjs → chunk-2SH5WPUA.cjs} +27 -22
  26. package/dist/chunk-2SH5WPUA.cjs.map +1 -0
  27. package/dist/{chunk-QMDJVXFQ.cjs → chunk-3NNB72OL.cjs} +15 -15
  28. package/dist/{chunk-QMDJVXFQ.cjs.map → chunk-3NNB72OL.cjs.map} +1 -1
  29. package/dist/{chunk-D2ZPF2AK.js → chunk-42VT5WOB.js} +3 -3
  30. package/dist/{chunk-D2ZPF2AK.js.map → chunk-42VT5WOB.js.map} +1 -1
  31. package/dist/{chunk-5QUE7HZF.js → chunk-6R46VE63.js} +5 -5
  32. package/dist/{chunk-5QUE7HZF.js.map → chunk-6R46VE63.js.map} +1 -1
  33. package/dist/{chunk-K3UPABLX.cjs → chunk-7EUC32F3.cjs} +16 -34
  34. package/dist/chunk-7EUC32F3.cjs.map +1 -0
  35. package/dist/{chunk-62I4SVWU.cjs → chunk-7HUKQ6SZ.cjs} +4 -4
  36. package/dist/{chunk-62I4SVWU.cjs.map → chunk-7HUKQ6SZ.cjs.map} +1 -1
  37. package/dist/{chunk-NLBX7Q47.cjs → chunk-7QC3MHP7.cjs} +4 -4
  38. package/dist/{chunk-NLBX7Q47.cjs.map → chunk-7QC3MHP7.cjs.map} +1 -1
  39. package/dist/{chunk-X6PLOE2T.js → chunk-AND6J5LG.js} +27 -22
  40. package/dist/chunk-AND6J5LG.js.map +1 -0
  41. package/dist/{chunk-TJHEGJNW.js → chunk-BOJNXNRV.js} +3 -3
  42. package/dist/{chunk-TJHEGJNW.js.map → chunk-BOJNXNRV.js.map} +1 -1
  43. package/dist/{chunk-NVMKTP4N.js → chunk-CJDOU6WP.js} +3 -3
  44. package/dist/chunk-CJDOU6WP.js.map +1 -0
  45. package/dist/{chunk-7CJKBCDL.js → chunk-COYTVUIL.js} +6 -24
  46. package/dist/chunk-COYTVUIL.js.map +1 -0
  47. package/dist/{chunk-2EMOWXLL.js → chunk-DQISKQDE.js} +86 -77
  48. package/dist/chunk-DQISKQDE.js.map +1 -0
  49. package/dist/{chunk-BBTR6DPH.cjs → chunk-DVHBWEYY.cjs} +3 -3
  50. package/dist/chunk-DVHBWEYY.cjs.map +1 -0
  51. package/dist/{chunk-T2CUZA2P.js → chunk-EF6Y74CN.js} +3 -3
  52. package/dist/{chunk-T2CUZA2P.js.map → chunk-EF6Y74CN.js.map} +1 -1
  53. package/dist/{chunk-57UPIDGK.cjs → chunk-I6TOPBP6.cjs} +14 -14
  54. package/dist/{chunk-57UPIDGK.cjs.map → chunk-I6TOPBP6.cjs.map} +1 -1
  55. package/dist/{chunk-M24QFL6S.js → chunk-KGBDRSMX.js} +8 -4
  56. package/dist/chunk-KGBDRSMX.js.map +1 -0
  57. package/dist/{chunk-CC4KO56Z.cjs → chunk-LCJP7LWN.cjs} +6 -6
  58. package/dist/{chunk-CC4KO56Z.cjs.map → chunk-LCJP7LWN.cjs.map} +1 -1
  59. package/dist/{chunk-2F4RLQ5V.cjs → chunk-NEWEONKX.cjs} +4 -4
  60. package/dist/{chunk-2F4RLQ5V.cjs.map → chunk-NEWEONKX.cjs.map} +1 -1
  61. package/dist/{chunk-3I3NRXSD.cjs → chunk-OKIHIKXV.cjs} +6 -6
  62. package/dist/{chunk-3I3NRXSD.cjs.map → chunk-OKIHIKXV.cjs.map} +1 -1
  63. package/dist/{chunk-M635OK6I.js → chunk-OXLN4CWA.js} +3 -3
  64. package/dist/{chunk-M635OK6I.js.map → chunk-OXLN4CWA.js.map} +1 -1
  65. package/dist/{chunk-LYRPXSHB.js → chunk-QR5VZWWT.js} +11 -11
  66. package/dist/{chunk-LYRPXSHB.js.map → chunk-QR5VZWWT.js.map} +1 -1
  67. package/dist/{chunk-WMGV4CS3.cjs → chunk-T4H33PBR.cjs} +115 -106
  68. package/dist/chunk-T4H33PBR.cjs.map +1 -0
  69. package/dist/{chunk-A7REAXWA.js → chunk-WP2KQXPV.js} +3 -3
  70. package/dist/{chunk-A7REAXWA.js.map → chunk-WP2KQXPV.js.map} +1 -1
  71. package/dist/{chunk-HV5ND4KF.cjs → chunk-YEEAHLAK.cjs} +4 -4
  72. package/dist/{chunk-HV5ND4KF.cjs.map → chunk-YEEAHLAK.cjs.map} +1 -1
  73. package/dist/{chunk-BMBWTBCL.js → chunk-ZJ2UFCTS.js} +5 -5
  74. package/dist/{chunk-BMBWTBCL.js.map → chunk-ZJ2UFCTS.js.map} +1 -1
  75. package/dist/{chunk-2C5AQMP5.cjs → chunk-ZNK5RN5D.cjs} +10 -6
  76. package/dist/chunk-ZNK5RN5D.cjs.map +1 -0
  77. package/dist/index.cjs +54 -54
  78. package/dist/index.js +10 -10
  79. package/dist/llm/index.cjs +5 -5
  80. package/dist/llm/index.js +1 -1
  81. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  82. package/dist/llm/model/provider-registry.generated.d.ts +4 -4
  83. package/dist/llm/model/provider-registry.generated.d.ts.map +1 -1
  84. package/dist/loop/index.cjs +2 -2
  85. package/dist/loop/index.js +1 -1
  86. package/dist/loop/loop.d.ts.map +1 -1
  87. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  88. package/dist/loop/types.d.ts +7 -6
  89. package/dist/loop/types.d.ts.map +1 -1
  90. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +1 -1
  91. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  92. package/dist/loop/workflows/agentic-loop/index.d.ts +2 -2
  93. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  94. package/dist/loop/workflows/schema.d.ts +5 -3
  95. package/dist/loop/workflows/schema.d.ts.map +1 -1
  96. package/dist/loop/workflows/stream.d.ts +1 -1
  97. package/dist/loop/workflows/stream.d.ts.map +1 -1
  98. package/dist/mastra/index.cjs +2 -2
  99. package/dist/mastra/index.d.ts +3 -7
  100. package/dist/mastra/index.d.ts.map +1 -1
  101. package/dist/mastra/index.js +1 -1
  102. package/dist/memory/index.cjs +4 -4
  103. package/dist/memory/index.js +1 -1
  104. package/dist/memory/memory.d.ts +7 -2
  105. package/dist/memory/memory.d.ts.map +1 -1
  106. package/dist/memory/types.d.ts +256 -8
  107. package/dist/memory/types.d.ts.map +1 -1
  108. package/dist/processors/index.cjs +14 -10
  109. package/dist/processors/index.d.ts +1 -0
  110. package/dist/processors/index.d.ts.map +1 -1
  111. package/dist/processors/index.js +1 -1
  112. package/dist/processors/processors/structured-output.d.ts +15 -7
  113. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  114. package/dist/processors/runner.d.ts +0 -1
  115. package/dist/processors/runner.d.ts.map +1 -1
  116. package/dist/relevance/index.cjs +4 -4
  117. package/dist/relevance/index.js +1 -1
  118. package/dist/scores/index.cjs +9 -9
  119. package/dist/scores/index.js +2 -2
  120. package/dist/scores/scoreTraces/index.cjs +8 -8
  121. package/dist/scores/scoreTraces/index.js +3 -3
  122. package/dist/server/index.cjs +2 -2
  123. package/dist/server/index.js +1 -1
  124. package/dist/storage/index.cjs +3 -3
  125. package/dist/storage/index.js +1 -1
  126. package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -1
  127. package/dist/stream/aisdk/v5/output.d.ts +6 -6
  128. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  129. package/dist/stream/aisdk/v5/transform.d.ts +5 -4
  130. package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
  131. package/dist/stream/base/output-format-handlers.d.ts +3 -7
  132. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  133. package/dist/stream/base/output.d.ts +12 -6
  134. package/dist/stream/base/output.d.ts.map +1 -1
  135. package/dist/stream/index.cjs +4 -4
  136. package/dist/stream/index.js +1 -1
  137. package/dist/stream/types.d.ts +16 -5
  138. package/dist/stream/types.d.ts.map +1 -1
  139. package/dist/telemetry/index.cjs +7 -7
  140. package/dist/telemetry/index.js +1 -1
  141. package/dist/test-utils/llm-mock.cjs +2 -2
  142. package/dist/test-utils/llm-mock.js +1 -1
  143. package/dist/tts/index.cjs +2 -2
  144. package/dist/tts/index.js +1 -1
  145. package/dist/utils.cjs +17 -17
  146. package/dist/utils.d.ts +1 -1
  147. package/dist/utils.d.ts.map +1 -1
  148. package/dist/utils.js +1 -1
  149. package/dist/voice/index.cjs +4 -4
  150. package/dist/voice/index.js +1 -1
  151. package/dist/workflows/evented/index.cjs +10 -10
  152. package/dist/workflows/evented/index.js +1 -1
  153. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  154. package/dist/workflows/index.cjs +12 -12
  155. package/dist/workflows/index.js +1 -1
  156. package/dist/workflows/legacy/index.cjs +22 -22
  157. package/dist/workflows/legacy/index.js +1 -1
  158. package/dist/workflows/workflow.d.ts +8 -8
  159. package/dist/workflows/workflow.d.ts.map +1 -1
  160. package/package.json +3 -3
  161. package/dist/chunk-2C5AQMP5.cjs.map +0 -1
  162. package/dist/chunk-2EMOWXLL.js.map +0 -1
  163. package/dist/chunk-7CJKBCDL.js.map +0 -1
  164. package/dist/chunk-BBTR6DPH.cjs.map +0 -1
  165. package/dist/chunk-HJQ7ANDX.cjs.map +0 -1
  166. package/dist/chunk-K3UPABLX.cjs.map +0 -1
  167. package/dist/chunk-M24QFL6S.js.map +0 -1
  168. package/dist/chunk-NVMKTP4N.js.map +0 -1
  169. package/dist/chunk-QFKTSGBI.js.map +0 -1
  170. package/dist/chunk-SZD4WTRW.cjs.map +0 -1
  171. package/dist/chunk-WMGV4CS3.cjs.map +0 -1
  172. package/dist/chunk-X6PLOE2T.js.map +0 -1
  173. package/dist/network/vNext/index.cjs +0 -990
  174. package/dist/network/vNext/index.cjs.map +0 -1
  175. package/dist/network/vNext/index.d.ts +0 -331
  176. package/dist/network/vNext/index.d.ts.map +0 -1
  177. package/dist/network/vNext/index.js +0 -988
  178. package/dist/network/vNext/index.js.map +0 -1
  179. package/network/vNext.d.ts +0 -1
@@ -1,990 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkWMGV4CS3_cjs = require('../../chunk-WMGV4CS3.cjs');
4
- var chunkABJOUEVA_cjs = require('../../chunk-ABJOUEVA.cjs');
5
- var chunk62I4SVWU_cjs = require('../../chunk-62I4SVWU.cjs');
6
- var chunkGPWMM745_cjs = require('../../chunk-GPWMM745.cjs');
7
- var chunk4L3P3PCP_cjs = require('../../chunk-4L3P3PCP.cjs');
8
- var chunkWVCEJBDR_cjs = require('../../chunk-WVCEJBDR.cjs');
9
- var crypto = require('crypto');
10
- var zodToJson = require('@mastra/schema-compat/zod-to-json');
11
- var zod = require('zod');
12
-
13
- var NewAgentNetwork = class extends chunk4L3P3PCP_cjs.MastraBase {
14
- id;
15
- name;
16
- #instructions;
17
- #model;
18
- #agents;
19
- #defaultAgent;
20
- #workflows;
21
- #tools;
22
- #memory;
23
- #mastra;
24
- constructor({
25
- id,
26
- name,
27
- instructions,
28
- model,
29
- agents,
30
- workflows,
31
- memory,
32
- tools,
33
- defaultAgent
34
- }) {
35
- super({
36
- component: chunkWVCEJBDR_cjs.RegisteredLogger.NETWORK,
37
- name: name || "NewAgentNetwork"
38
- });
39
- console.warn(
40
- `\u26A0\uFE0F DEPRECATION WARNING: AgentNetwork vNext will be deprecated the week of September 30th, 2025 and will be removed in a future version. Please use agent.network() instead.`
41
- );
42
- this.id = id;
43
- this.name = name;
44
- this.#instructions = instructions;
45
- this.#model = model;
46
- this.#agents = agents;
47
- this.#workflows = workflows;
48
- this.#memory = memory;
49
- this.#tools = tools;
50
- this.#defaultAgent = defaultAgent;
51
- }
52
- __registerMastra(mastra) {
53
- this.#mastra = mastra;
54
- }
55
- getLastMessage(messages) {
56
- let message = "";
57
- if (typeof messages === "string") {
58
- message = messages;
59
- } else {
60
- const lastMessage = Array.isArray(messages) ? messages[messages.length - 1] : messages;
61
- if (typeof lastMessage === "string") {
62
- message = lastMessage;
63
- } else if (lastMessage && `content` in lastMessage && lastMessage?.content) {
64
- const lastMessageContent = lastMessage.content;
65
- if (typeof lastMessageContent === "string") {
66
- message = lastMessageContent;
67
- } else if (Array.isArray(lastMessageContent)) {
68
- const lastPart = lastMessageContent[lastMessageContent.length - 1];
69
- if (lastPart?.type === "text") {
70
- message = lastPart.text;
71
- }
72
- }
73
- }
74
- }
75
- return message;
76
- }
77
- async beforeRun({
78
- runtimeContext,
79
- threadId,
80
- resourceId,
81
- messages
82
- }) {
83
- const memory = await this.getMemory({ runtimeContext });
84
- let thread = await memory?.getThreadById({ threadId });
85
- if (!thread) {
86
- thread = await memory?.createThread({
87
- threadId,
88
- title: "",
89
- resourceId
90
- });
91
- }
92
- if (typeof messages === "string") {
93
- await memory?.saveMessages({
94
- messages: [
95
- {
96
- id: this.#mastra?.generateId() || crypto.randomUUID(),
97
- type: "text",
98
- role: "user",
99
- content: { parts: [{ type: "text", text: messages }], format: 2 },
100
- createdAt: /* @__PURE__ */ new Date(),
101
- threadId: thread?.id,
102
- resourceId: thread?.resourceId
103
- }
104
- ],
105
- format: "v2"
106
- });
107
- } else {
108
- const messageList = new chunk62I4SVWU_cjs.MessageList({
109
- threadId: thread?.id,
110
- resourceId: thread?.resourceId
111
- });
112
- messageList.add(messages, "user");
113
- const messagesToSave = messageList.get.all.v2();
114
- await memory?.saveMessages({
115
- messages: messagesToSave,
116
- format: "v2"
117
- });
118
- }
119
- return thread;
120
- }
121
- async getAgents({ runtimeContext }) {
122
- let agentsToUse;
123
- if (typeof this.#agents === "function") {
124
- agentsToUse = await this.#agents({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
125
- } else {
126
- agentsToUse = this.#agents;
127
- }
128
- return agentsToUse;
129
- }
130
- async getWorkflows({ runtimeContext }) {
131
- let workflowsToUse;
132
- if (typeof this.#workflows === "function") {
133
- workflowsToUse = await this.#workflows({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
134
- } else {
135
- workflowsToUse = this.#workflows || {};
136
- }
137
- return workflowsToUse;
138
- }
139
- async getTools({ runtimeContext }) {
140
- let toolsToUse;
141
- if (typeof this.#tools === "function") {
142
- toolsToUse = await this.#tools({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
143
- } else {
144
- toolsToUse = this.#tools || {};
145
- }
146
- return toolsToUse;
147
- }
148
- async getMemory({ runtimeContext }) {
149
- let memoryToUse;
150
- if (!this.#memory) {
151
- return;
152
- }
153
- if (typeof this.#memory === "function") {
154
- memoryToUse = await this.#memory({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
155
- } else {
156
- memoryToUse = this.#memory;
157
- }
158
- return memoryToUse;
159
- }
160
- async getInstructions({ runtimeContext }) {
161
- let instructionsToUse = this.#instructions;
162
- if (typeof instructionsToUse === "function") {
163
- instructionsToUse = await instructionsToUse({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
164
- }
165
- return instructionsToUse;
166
- }
167
- async getRoutingAgent({ runtimeContext }) {
168
- const instructionsToUse = await this.getInstructions({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
169
- const memoryToUse = await this.getMemory({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
170
- const agentsToUse = await this.getAgents({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
171
- const workflowsToUse = await this.getWorkflows({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
172
- const toolsToUse = await this.getTools({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
173
- const agentList = Object.entries(agentsToUse).map(([name, agent]) => {
174
- return ` - **${name}**: ${agent.getDescription()}`;
175
- }).join("\n");
176
- const workflowList = Object.entries(workflowsToUse).map(([name, workflow]) => {
177
- return ` - **${name}**: ${workflow.description}, input schema: ${JSON.stringify(
178
- zodToJson.zodToJsonSchema(workflow.inputSchema)
179
- )}`;
180
- }).join("\n");
181
- const toolList = Object.entries(toolsToUse).map(([name, tool]) => {
182
- return ` - **${name}**: ${tool.description}, input schema: ${JSON.stringify(
183
- zodToJson.zodToJsonSchema(tool.inputSchema || zod.z.object({}))
184
- )}`;
185
- }).join("\n");
186
- const instructions = `
187
- You are a router in a network of specialized AI agents.
188
- Your job is to decide which agent should handle each step of a task.
189
-
190
- If asking for completion of a task, make sure to follow system instructions closely.
191
-
192
- ## System Instructions
193
- ${instructionsToUse}
194
-
195
- You can only pick agents and workflows that are available in the lists below. Never call any agents or workflows that are not available in the lists below.
196
-
197
- ## Available Agents in Network
198
- ${agentList}
199
-
200
- ## Available Workflows in Network (make sure to use inputs corresponding to the input schema when calling a workflow)
201
- ${workflowList}
202
-
203
- ## Available Tools in Network (make sure to use inputs corresponding to the input schema when calling a tool)
204
- ${toolList}
205
-
206
- ${this.#defaultAgent ? `If none of the agents or workflows are appropriate, call the default agent: ${this.#defaultAgent.name}.This should not be done lightly. You should only do this if you have exhausted all other options.` : ""}
207
-
208
- If you have multiple entries that need to be called with a workflow or agent, call them separately with each input.
209
- When calling a workflow, the prompt should be a JSON value that corresponds to the input schema of the workflow. The JSON value is stringified.
210
- When calling a tool, the prompt should be a JSON value that corresponds to the input schema of the tool. The JSON value is stringified.
211
- When calling an agent, the prompt should be a text value, like you would call an LLM in a chat interface.
212
-
213
- Keep in mind that the user only sees the final result of the task. When reviewing completion, you should know that the user will not see the intermediate results.
214
- `;
215
- return new chunkWMGV4CS3_cjs.Agent({
216
- name: "routing-agent",
217
- instructions,
218
- model: this.#model,
219
- memory: memoryToUse,
220
- // @ts-ignore
221
- _agentNetworkAppend: true
222
- });
223
- }
224
- async loop(messages, {
225
- runtimeContext,
226
- maxIterations,
227
- threadId,
228
- resourceId
229
- }) {
230
- const networkWorkflow = this.createWorkflow({ runtimeContext });
231
- const finalStep = chunkWMGV4CS3_cjs.createStep({
232
- id: "final-step",
233
- inputSchema: networkWorkflow.outputSchema,
234
- outputSchema: networkWorkflow.outputSchema,
235
- execute: async ({ inputData }) => {
236
- if (maxIterations && inputData.iteration >= maxIterations) {
237
- return {
238
- ...inputData,
239
- completionReason: `Max iterations reached: ${maxIterations}`
240
- };
241
- }
242
- return inputData;
243
- }
244
- });
245
- const mainWorkflow = chunkWMGV4CS3_cjs.createWorkflow({
246
- id: "Agent-Network-Main-Workflow",
247
- inputSchema: zod.z.object({
248
- iteration: zod.z.number(),
249
- task: zod.z.string(),
250
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
251
- threadId: zod.z.string().optional(),
252
- threadResourceId: zod.z.string().optional()
253
- }),
254
- outputSchema: networkWorkflow.outputSchema
255
- }).dountil(networkWorkflow, async ({ inputData }) => {
256
- return inputData.isComplete || maxIterations && inputData.iteration >= maxIterations;
257
- }).then(finalStep).commit();
258
- const run = await mainWorkflow.createRunAsync();
259
- const thread = await this.beforeRun({
260
- runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
261
- threadId: threadId || run.runId,
262
- resourceId: resourceId || this.name,
263
- messages
264
- });
265
- const message = this.getLastMessage(messages);
266
- const result = await run.start({
267
- inputData: {
268
- task: message,
269
- resourceType: "none",
270
- iteration: 0,
271
- threadResourceId: thread?.resourceId,
272
- threadId: thread?.id
273
- }
274
- });
275
- if (result.status === "failed") {
276
- throw result.error;
277
- }
278
- if (result.status === "suspended") {
279
- throw new Error("Workflow suspended");
280
- }
281
- return result;
282
- }
283
- async loopStream(messages, {
284
- runtimeContext,
285
- maxIterations,
286
- threadId,
287
- resourceId
288
- }) {
289
- const networkWorkflow = this.createWorkflow({ runtimeContext });
290
- const finalStep = chunkWMGV4CS3_cjs.createStep({
291
- id: "final-step",
292
- inputSchema: networkWorkflow.outputSchema,
293
- outputSchema: networkWorkflow.outputSchema,
294
- execute: async ({ inputData }) => {
295
- if (maxIterations && inputData.iteration >= maxIterations) {
296
- return {
297
- ...inputData,
298
- completionReason: `Max iterations reached: ${maxIterations}`
299
- };
300
- }
301
- return inputData;
302
- }
303
- });
304
- const mainWorkflow = chunkWMGV4CS3_cjs.createWorkflow({
305
- id: "Agent-Network-Main-Workflow",
306
- inputSchema: zod.z.object({
307
- iteration: zod.z.number(),
308
- task: zod.z.string(),
309
- resourceId: zod.z.string(),
310
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
311
- result: zod.z.string().optional(),
312
- threadId: zod.z.string().optional(),
313
- threadResourceId: zod.z.string().optional(),
314
- isOneOff: zod.z.boolean(),
315
- verboseIntrospection: zod.z.boolean()
316
- }),
317
- outputSchema: zod.z.object({
318
- task: zod.z.string(),
319
- resourceId: zod.z.string(),
320
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
321
- prompt: zod.z.string(),
322
- result: zod.z.string(),
323
- isComplete: zod.z.boolean().optional(),
324
- completionReason: zod.z.string().optional(),
325
- iteration: zod.z.number()
326
- })
327
- }).dountil(networkWorkflow, async ({ inputData }) => {
328
- return inputData.isComplete || maxIterations && inputData.iteration >= maxIterations;
329
- }).then(finalStep).commit();
330
- const run = await mainWorkflow.createRunAsync();
331
- const thread = await this.beforeRun({
332
- runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
333
- threadId: threadId || run.runId,
334
- resourceId: resourceId || this.name,
335
- messages
336
- });
337
- const message = this.getLastMessage(messages);
338
- return run.stream({
339
- inputData: {
340
- task: message,
341
- resourceId: "",
342
- resourceType: "none",
343
- iteration: 0,
344
- threadResourceId: thread?.resourceId,
345
- threadId: thread?.id,
346
- isOneOff: false,
347
- verboseIntrospection: true
348
- }
349
- });
350
- }
351
- createWorkflow({ runtimeContext }) {
352
- const runId = this.#mastra?.generateId() || crypto.randomUUID();
353
- const runtimeContextToUse = runtimeContext || new chunkGPWMM745_cjs.RuntimeContext();
354
- const routingStep = chunkWMGV4CS3_cjs.createStep({
355
- id: "routing-step",
356
- inputSchema: zod.z.object({
357
- task: zod.z.string(),
358
- resourceId: zod.z.string(),
359
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
360
- result: zod.z.string().optional(),
361
- iteration: zod.z.number(),
362
- threadId: zod.z.string().optional(),
363
- threadResourceId: zod.z.string().optional(),
364
- isOneOff: zod.z.boolean(),
365
- verboseIntrospection: zod.z.boolean()
366
- }),
367
- outputSchema: zod.z.object({
368
- task: zod.z.string(),
369
- resourceId: zod.z.string(),
370
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
371
- prompt: zod.z.string(),
372
- result: zod.z.string(),
373
- isComplete: zod.z.boolean().optional(),
374
- selectionReason: zod.z.string(),
375
- iteration: zod.z.number()
376
- }),
377
- execute: async ({ inputData, getInitData }) => {
378
- const initData = await getInitData();
379
- const routingAgent = await this.getRoutingAgent({ runtimeContext: runtimeContextToUse });
380
- const model = await routingAgent.getModel();
381
- const completionSchema = zod.z.object({
382
- isComplete: zod.z.boolean(),
383
- finalResult: zod.z.string(),
384
- completionReason: zod.z.string()
385
- });
386
- let completionResult;
387
- if (inputData.resourceType !== "none" && inputData?.result) {
388
- const completionPrompt = `
389
- The ${inputData.resourceType} ${inputData.resourceId} has contributed to the task.
390
- This is the result from the agent: ${inputData.result}
391
-
392
- You need to evaluate that our task is complete. Pay very close attention to the SYSTEM INSTRUCTIONS for when the task is considered complete. Only return true if the task is complete according to the system instructions. Pay close attention to the finalResult and completionReason.
393
- Original task: ${inputData.task}
394
-
395
- {
396
- "isComplete": boolean,
397
- "completionReason": string,
398
- "finalResult": string
399
- }
400
- `;
401
- if (model.specificationVersion === "v2") {
402
- completionResult = await routingAgent.generateVNext([{ role: "assistant", content: completionPrompt }], {
403
- output: completionSchema,
404
- threadId: initData?.threadId ?? runId,
405
- resourceId: initData?.threadResourceId ?? this.name,
406
- runtimeContext: runtimeContextToUse
407
- });
408
- } else {
409
- completionResult = await routingAgent.generate([{ role: "assistant", content: completionPrompt }], {
410
- output: completionSchema,
411
- threadId: initData?.threadId ?? runId,
412
- resourceId: initData?.threadResourceId ?? this.name,
413
- runtimeContext: runtimeContextToUse
414
- });
415
- }
416
- if (completionResult.object.isComplete) {
417
- return {
418
- task: inputData.task,
419
- resourceId: "",
420
- resourceType: "none",
421
- prompt: "",
422
- result: completionResult.object.finalResult,
423
- isComplete: true,
424
- selectionReason: completionResult.object.completionReason,
425
- iteration: inputData.iteration + 1
426
- };
427
- }
428
- }
429
- let result;
430
- const prompt = [
431
- {
432
- role: "assistant",
433
- content: `
434
- ${inputData.isOneOff ? "You are executing just one primitive based on the user task. Make sure to pick the primitive that is the best suited to accomplish the whole task. Primitives that execute only part of the task should be avoided." : "You will be calling just *one* primitive at a time to accomplish the user task, every call to you is one decision in the process of accomplishing the user task. Make sure to pick primitives that are the best suited to accomplish the whole task. Completeness is the highest priority."}
435
-
436
- The user has given you the following task:
437
- ${inputData.task}
438
- ${completionResult ? `
439
-
440
- ${completionResult.object.finalResult}` : ""}
441
-
442
- Please select the most appropriate primitive to handle this task and the prompt to be sent to the primitive.
443
- If you are calling the same agent again, make sure to adjust the prompt to be more specific.
444
-
445
- {
446
- "resourceId": string,
447
- "resourceType": "agent" | "workflow" | "tool",
448
- "prompt": string,
449
- "selectionReason": string
450
- }
451
-
452
- The 'selectionReason' property should explain why you picked the primitive${inputData.verboseIntrospection ? ", as well as why the other primitives were not picked." : "."}
453
- `
454
- }
455
- ];
456
- const options = {
457
- output: zod.z.object({
458
- resourceId: zod.z.string(),
459
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
460
- prompt: zod.z.string(),
461
- selectionReason: zod.z.string()
462
- }),
463
- threadId: initData?.threadId ?? runId,
464
- resourceId: initData?.threadResourceId ?? this.name,
465
- runtimeContext: runtimeContextToUse
466
- };
467
- if (model.specificationVersion === "v2") {
468
- result = await routingAgent.generateVNext(prompt, options);
469
- } else {
470
- result = await routingAgent.generate(prompt, options);
471
- }
472
- return {
473
- task: inputData.task,
474
- result: "",
475
- resourceId: result.object.resourceId,
476
- resourceType: result.object.resourceType,
477
- prompt: result.object.prompt,
478
- isComplete: result.object.resourceId === "none" && result.object.resourceType === "none" ? true : false,
479
- selectionReason: result.object.selectionReason,
480
- iteration: inputData.iteration + 1
481
- };
482
- }
483
- });
484
- const agentStep = chunkWMGV4CS3_cjs.createStep({
485
- id: "agent-step",
486
- inputSchema: zod.z.object({
487
- task: zod.z.string(),
488
- resourceId: zod.z.string(),
489
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
490
- prompt: zod.z.string(),
491
- result: zod.z.string(),
492
- isComplete: zod.z.boolean().optional(),
493
- selectionReason: zod.z.string(),
494
- iteration: zod.z.number()
495
- }),
496
- outputSchema: zod.z.object({
497
- task: zod.z.string(),
498
- resourceId: zod.z.string(),
499
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
500
- result: zod.z.string(),
501
- isComplete: zod.z.boolean().optional(),
502
- iteration: zod.z.number()
503
- }),
504
- execute: async ({ inputData, [chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter, getInitData }) => {
505
- const agentsMap = await this.getAgents({ runtimeContext: runtimeContextToUse });
506
- const agentId = inputData.resourceId;
507
- const agent = agentsMap[inputData.resourceId];
508
- if (!agent) {
509
- throw new Error(`Agent ${agentId} not found`);
510
- }
511
- let streamPromise = {};
512
- streamPromise.promise = new Promise((resolve, reject) => {
513
- streamPromise.resolve = resolve;
514
- streamPromise.reject = reject;
515
- });
516
- const toolData = {
517
- name: agent.name,
518
- args: inputData
519
- };
520
- await emitter.emit("watch-v2", {
521
- type: "tool-call-streaming-start",
522
- ...toolData
523
- });
524
- const model = await agent.getModel();
525
- let result;
526
- if (model.specificationVersion === "v2") {
527
- result = await agent.streamVNext(inputData.prompt, {
528
- // resourceId: inputData.resourceId,
529
- // threadId: inputData.threadId,
530
- runtimeContext: runtimeContextToUse,
531
- onFinish: (result2) => {
532
- streamPromise.resolve(result2.text);
533
- }
534
- });
535
- for await (const chunk of result.fullStream) {
536
- switch (chunk.type) {
537
- case "text-delta":
538
- await emitter.emit("watch-v2", {
539
- type: "tool-call-delta",
540
- ...toolData,
541
- argsTextDelta: chunk.payload.text
542
- });
543
- break;
544
- case "step-start":
545
- case "step-finish":
546
- case "finish":
547
- case "tool-call":
548
- case "tool-result":
549
- case "tool-call-input-streaming-start":
550
- case "tool-call-delta":
551
- break;
552
- case "source":
553
- case "file":
554
- default:
555
- await emitter.emit("watch-v2", chunk);
556
- break;
557
- }
558
- }
559
- } else {
560
- result = await agent.stream(inputData.prompt, {
561
- // resourceId: inputData.resourceId,
562
- // threadId: inputData.threadId,
563
- runtimeContext: runtimeContextToUse,
564
- onFinish: (result2) => {
565
- streamPromise.resolve(result2.text);
566
- }
567
- });
568
- for await (const chunk of result.fullStream) {
569
- switch (chunk.type) {
570
- case "text-delta":
571
- await emitter.emit("watch-v2", {
572
- type: "tool-call-delta",
573
- ...toolData,
574
- argsTextDelta: chunk.textDelta
575
- });
576
- break;
577
- case "step-start":
578
- case "step-finish":
579
- case "finish":
580
- case "tool-call":
581
- case "tool-result":
582
- case "tool-call-streaming-start":
583
- case "tool-call-delta":
584
- break;
585
- case "source":
586
- case "file":
587
- default:
588
- await emitter.emit("watch-v2", chunk);
589
- break;
590
- }
591
- }
592
- }
593
- const finalResult = await streamPromise.promise;
594
- const memory = await this.getMemory({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
595
- const initData = await getInitData();
596
- await memory?.saveMessages({
597
- messages: [
598
- {
599
- id: this.#mastra?.generateId() || crypto.randomUUID(),
600
- type: "text",
601
- role: "assistant",
602
- content: { parts: [{ type: "text", text: finalResult }], format: 2 },
603
- createdAt: /* @__PURE__ */ new Date(),
604
- threadId: initData.threadId || runId,
605
- resourceId: initData.threadResourceId || this.name
606
- }
607
- ],
608
- format: "v2"
609
- });
610
- return {
611
- task: inputData.task,
612
- resourceId: inputData.resourceId,
613
- resourceType: inputData.resourceType,
614
- result: finalResult,
615
- isComplete: false,
616
- iteration: inputData.iteration
617
- };
618
- }
619
- });
620
- const workflowStep = chunkWMGV4CS3_cjs.createStep({
621
- id: "workflow-step",
622
- inputSchema: zod.z.object({
623
- task: zod.z.string(),
624
- resourceId: zod.z.string(),
625
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
626
- prompt: zod.z.string(),
627
- result: zod.z.string(),
628
- isComplete: zod.z.boolean().optional(),
629
- selectionReason: zod.z.string(),
630
- iteration: zod.z.number()
631
- }),
632
- outputSchema: zod.z.object({
633
- task: zod.z.string(),
634
- resourceId: zod.z.string(),
635
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
636
- result: zod.z.string(),
637
- isComplete: zod.z.boolean().optional(),
638
- iteration: zod.z.number()
639
- }),
640
- execute: async ({ inputData, [chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter, getInitData }) => {
641
- const workflowsMap = await this.getWorkflows({ runtimeContext: runtimeContextToUse });
642
- const wf = workflowsMap[inputData.resourceId];
643
- if (!wf) {
644
- throw new Error(`Workflow ${inputData.resourceId} not found`);
645
- }
646
- let input;
647
- try {
648
- input = JSON.parse(inputData.prompt);
649
- } catch (e) {
650
- console.error(e);
651
- throw new Error(`Invalid task input: ${inputData.task}`);
652
- }
653
- let streamPromise = {};
654
- streamPromise.promise = new Promise((resolve, reject) => {
655
- streamPromise.resolve = resolve;
656
- streamPromise.reject = reject;
657
- });
658
- const toolData = {
659
- name: wf.name,
660
- args: inputData
661
- };
662
- await emitter.emit("watch-v2", {
663
- type: "tool-call-streaming-start",
664
- ...toolData
665
- });
666
- const run = await wf.createRunAsync();
667
- const { stream, getWorkflowState } = run.stream({
668
- inputData: input,
669
- runtimeContext: runtimeContextToUse
670
- });
671
- let result;
672
- for await (const chunk of stream) {
673
- const c = chunk;
674
- switch (c.type) {
675
- case "text-delta":
676
- await emitter.emit("watch-v2", {
677
- type: "tool-call-delta",
678
- ...toolData,
679
- argsTextDelta: c.textDelta
680
- });
681
- break;
682
- case "step-result":
683
- if (c?.payload?.output) {
684
- result = c?.payload?.output;
685
- }
686
- await emitter.emit("watch-v2", c);
687
- break;
688
- case "finish":
689
- streamPromise.resolve(result);
690
- break;
691
- case "start":
692
- case "step-start":
693
- case "step-finish":
694
- case "tool-call":
695
- case "tool-result":
696
- case "tool-call-streaming-start":
697
- case "tool-call-delta":
698
- case "source":
699
- case "file":
700
- default:
701
- await emitter.emit("watch-v2", c);
702
- break;
703
- }
704
- }
705
- let runSuccess = true;
706
- const runResult = await streamPromise.promise;
707
- const workflowState = await getWorkflowState();
708
- if (workflowState.status === "failed") {
709
- runSuccess = false;
710
- }
711
- const finalResult = JSON.stringify({
712
- runId: run.runId,
713
- runResult,
714
- runSuccess
715
- });
716
- const memory = await this.getMemory({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
717
- const initData = await getInitData();
718
- await memory?.saveMessages({
719
- messages: [
720
- {
721
- id: this.#mastra?.generateId() || crypto.randomUUID(),
722
- type: "text",
723
- role: "assistant",
724
- content: { parts: [{ type: "text", text: finalResult }], format: 2 },
725
- createdAt: /* @__PURE__ */ new Date(),
726
- threadId: initData.threadId || runId,
727
- resourceId: initData.threadResourceId || this.name
728
- }
729
- ],
730
- format: "v2"
731
- });
732
- return {
733
- result: finalResult || "",
734
- task: inputData.task,
735
- resourceId: inputData.resourceId,
736
- resourceType: inputData.resourceType,
737
- isComplete: false,
738
- iteration: inputData.iteration
739
- };
740
- }
741
- });
742
- const toolStep = chunkWMGV4CS3_cjs.createStep({
743
- id: "toolStep",
744
- inputSchema: zod.z.object({
745
- task: zod.z.string(),
746
- resourceId: zod.z.string(),
747
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
748
- prompt: zod.z.string(),
749
- result: zod.z.string(),
750
- isComplete: zod.z.boolean().optional(),
751
- selectionReason: zod.z.string(),
752
- iteration: zod.z.number()
753
- }),
754
- outputSchema: zod.z.object({
755
- task: zod.z.string(),
756
- resourceId: zod.z.string(),
757
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
758
- result: zod.z.string(),
759
- isComplete: zod.z.boolean().optional(),
760
- iteration: zod.z.number()
761
- }),
762
- execute: async ({ inputData, getInitData }) => {
763
- const toolsMap = await this.getTools({ runtimeContext: runtimeContextToUse });
764
- const tool = toolsMap[inputData.resourceId];
765
- if (!tool) {
766
- throw new Error(`Tool ${inputData.resourceId} not found`);
767
- }
768
- if (!tool.execute) {
769
- throw new Error(`Tool ${inputData.resourceId} does not have an execute function`);
770
- }
771
- let inputDataToUse;
772
- try {
773
- inputDataToUse = JSON.parse(inputData.prompt);
774
- } catch (e) {
775
- console.error(e);
776
- throw new Error(`Invalid task input: ${inputData.task}`);
777
- }
778
- const finalResult = await tool.execute({
779
- runtimeContext: runtimeContextToUse,
780
- mastra: this.#mastra,
781
- resourceId: inputData.resourceId,
782
- threadId: runId,
783
- runId,
784
- context: inputDataToUse,
785
- // TODO: Pass proper tracing context when network supports tracing
786
- tracingContext: { currentSpan: void 0 },
787
- suspend: async () => {
788
- }
789
- // TODO
790
- });
791
- const memory = await this.getMemory({ runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext() });
792
- const initData = await getInitData();
793
- await memory?.saveMessages({
794
- messages: [
795
- {
796
- id: this.#mastra?.generateId() || crypto.randomUUID(),
797
- type: "text",
798
- role: "assistant",
799
- content: { parts: [{ type: "text", text: JSON.stringify(finalResult) }], format: 2 },
800
- createdAt: /* @__PURE__ */ new Date(),
801
- threadId: initData.threadId || runId,
802
- resourceId: initData.threadResourceId || this.name
803
- }
804
- ],
805
- format: "v2"
806
- });
807
- return {
808
- task: inputData.task,
809
- resourceId: inputData.resourceId,
810
- resourceType: inputData.resourceType,
811
- result: finalResult,
812
- isComplete: false,
813
- iteration: inputData.iteration
814
- };
815
- }
816
- });
817
- const finishStep = chunkWMGV4CS3_cjs.createStep({
818
- id: "finish-step",
819
- inputSchema: zod.z.object({
820
- task: zod.z.string(),
821
- resourceId: zod.z.string(),
822
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
823
- prompt: zod.z.string(),
824
- result: zod.z.string(),
825
- isComplete: zod.z.boolean().optional(),
826
- selectionReason: zod.z.string(),
827
- iteration: zod.z.number()
828
- }),
829
- outputSchema: zod.z.object({
830
- task: zod.z.string(),
831
- result: zod.z.string(),
832
- isComplete: zod.z.boolean(),
833
- iteration: zod.z.number()
834
- }),
835
- execute: async ({ inputData }) => {
836
- return {
837
- task: inputData.task,
838
- result: inputData.result,
839
- isComplete: !!inputData.isComplete,
840
- iteration: inputData.iteration
841
- };
842
- }
843
- });
844
- const networkWorkflow = chunkWMGV4CS3_cjs.createWorkflow({
845
- id: "Agent-Network-Outer-Workflow",
846
- inputSchema: zod.z.object({
847
- task: zod.z.string(),
848
- resourceId: zod.z.string(),
849
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
850
- result: zod.z.string().optional(),
851
- iteration: zod.z.number(),
852
- threadId: zod.z.string().optional(),
853
- threadResourceId: zod.z.string().optional(),
854
- isOneOff: zod.z.boolean(),
855
- verboseIntrospection: zod.z.boolean()
856
- }),
857
- outputSchema: zod.z.object({
858
- task: zod.z.string(),
859
- resourceId: zod.z.string(),
860
- resourceType: chunkWMGV4CS3_cjs.PRIMITIVE_TYPES,
861
- prompt: zod.z.string(),
862
- result: zod.z.string(),
863
- isComplete: zod.z.boolean().optional(),
864
- completionReason: zod.z.string().optional(),
865
- iteration: zod.z.number(),
866
- threadId: zod.z.string().optional(),
867
- threadResourceId: zod.z.string().optional(),
868
- isOneOff: zod.z.boolean()
869
- })
870
- });
871
- networkWorkflow.then(routingStep).branch([
872
- [async ({ inputData }) => !inputData.isComplete && inputData.resourceType === "agent", agentStep],
873
- [async ({ inputData }) => !inputData.isComplete && inputData.resourceType === "workflow", workflowStep],
874
- [async ({ inputData }) => !inputData.isComplete && inputData.resourceType === "tool", toolStep],
875
- [async ({ inputData }) => inputData.isComplete, finishStep]
876
- ]).map({
877
- task: {
878
- step: [routingStep, agentStep, workflowStep, toolStep],
879
- path: "task"
880
- },
881
- isComplete: {
882
- step: [agentStep, workflowStep, toolStep, finishStep],
883
- path: "isComplete"
884
- },
885
- completionReason: {
886
- step: [routingStep, agentStep, workflowStep, toolStep, finishStep],
887
- path: "completionReason"
888
- },
889
- result: {
890
- step: [agentStep, workflowStep, toolStep, finishStep],
891
- path: "result"
892
- },
893
- resourceId: {
894
- step: [routingStep, agentStep, workflowStep, toolStep],
895
- path: "resourceId"
896
- },
897
- resourceType: {
898
- step: [routingStep, agentStep, workflowStep, toolStep],
899
- path: "resourceType"
900
- },
901
- iteration: {
902
- step: [routingStep, agentStep, workflowStep, toolStep],
903
- path: "iteration"
904
- },
905
- isOneOff: {
906
- initData: networkWorkflow,
907
- path: "isOneOff"
908
- },
909
- threadId: {
910
- initData: networkWorkflow,
911
- path: "threadId"
912
- },
913
- threadResourceId: {
914
- initData: networkWorkflow,
915
- path: "threadResourceId"
916
- }
917
- }).commit();
918
- return networkWorkflow;
919
- }
920
- async generate(messages, {
921
- runtimeContext,
922
- threadId,
923
- resourceId
924
- }) {
925
- const networkWorkflow = this.createWorkflow({ runtimeContext });
926
- const run = await networkWorkflow.createRunAsync();
927
- const thread = await this.beforeRun({
928
- runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
929
- threadId: threadId || run.runId,
930
- resourceId: resourceId || this.name,
931
- messages
932
- });
933
- const message = this.getLastMessage(messages);
934
- const result = await run.start({
935
- inputData: {
936
- task: message,
937
- resourceId: "",
938
- resourceType: "none",
939
- iteration: 0,
940
- threadId: thread?.id,
941
- threadResourceId: thread?.resourceId,
942
- isOneOff: true,
943
- verboseIntrospection: true
944
- }
945
- });
946
- if (result.status === "failed") {
947
- throw result.error;
948
- }
949
- if (result.status === "suspended") {
950
- throw new Error("Workflow suspended");
951
- }
952
- return {
953
- task: result.result.task,
954
- result: result.result.result,
955
- resourceId: result.result.resourceId,
956
- resourceType: result.result.resourceType
957
- };
958
- }
959
- async stream(messages, {
960
- runtimeContext,
961
- threadId,
962
- resourceId
963
- }) {
964
- const networkWorkflow = this.createWorkflow({ runtimeContext });
965
- const run = await networkWorkflow.createRunAsync();
966
- const thread = await this.beforeRun({
967
- runtimeContext: runtimeContext || new chunkGPWMM745_cjs.RuntimeContext(),
968
- threadId: threadId || run.runId,
969
- resourceId: resourceId || this.name,
970
- messages
971
- });
972
- const message = this.getLastMessage(messages);
973
- return run.stream({
974
- inputData: {
975
- task: `You are executing just one primitive based on the following: ${message}`,
976
- resourceId: "",
977
- resourceType: "none",
978
- iteration: 0,
979
- threadResourceId: thread?.resourceId,
980
- threadId: thread?.id,
981
- isOneOff: true,
982
- verboseIntrospection: true
983
- }
984
- });
985
- }
986
- };
987
-
988
- exports.NewAgentNetwork = NewAgentNetwork;
989
- //# sourceMappingURL=index.cjs.map
990
- //# sourceMappingURL=index.cjs.map