@upstash/workflow 0.2.4 → 0.2.5-agents
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.
- package/agents.d.mts +5 -0
- package/agents.d.ts +5 -0
- package/agents.js +245 -0
- package/agents.mjs +12 -0
- package/astro.d.mts +4 -1
- package/astro.d.ts +4 -1
- package/astro.js +216 -0
- package/astro.mjs +2 -1
- package/chunk-PU5J4TNC.mjs +251 -0
- package/{chunk-ETDFMXER.mjs → chunk-RFX5YRRT.mjs} +9 -34
- package/cloudflare.d.mts +4 -1
- package/cloudflare.d.ts +4 -1
- package/cloudflare.js +216 -0
- package/cloudflare.mjs +2 -1
- package/express.d.mts +4 -1
- package/express.d.ts +4 -1
- package/express.js +216 -0
- package/express.mjs +5 -3
- package/h3.d.mts +4 -1
- package/h3.d.ts +4 -1
- package/h3.js +216 -0
- package/h3.mjs +2 -1
- package/hono.d.mts +4 -1
- package/hono.d.ts +4 -1
- package/hono.js +216 -0
- package/hono.mjs +2 -1
- package/index.d.mts +5 -2
- package/index.d.ts +5 -2
- package/index.js +216 -0
- package/index.mjs +2 -1
- package/nextjs.d.mts +4 -1
- package/nextjs.d.ts +4 -1
- package/nextjs.js +216 -0
- package/nextjs.mjs +2 -1
- package/package.json +1 -1
- package/solidjs.d.mts +4 -1
- package/solidjs.d.ts +4 -1
- package/solidjs.js +216 -0
- package/solidjs.mjs +2 -1
- package/svelte.d.mts +4 -1
- package/svelte.d.ts +4 -1
- package/svelte.js +216 -0
- package/svelte.mjs +2 -1
- package/{types-Bt4-paRy.d.mts → types-BEyIoCRe.d.mts} +76 -1
- package/{types-Bt4-paRy.d.ts → types-BEyIoCRe.d.ts} +76 -1
package/agents.d.mts
ADDED
package/agents.d.ts
ADDED
package/agents.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/agents/index.ts
|
|
21
|
+
var agents_exports = {};
|
|
22
|
+
__export(agents_exports, {
|
|
23
|
+
Agent: () => Agent,
|
|
24
|
+
ManagerAgent: () => ManagerAgent,
|
|
25
|
+
WorkflowAgents: () => WorkflowAgents,
|
|
26
|
+
createWorkflowOpenAI: () => createWorkflowOpenAI
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(agents_exports);
|
|
29
|
+
|
|
30
|
+
// src/agents/adapters.ts
|
|
31
|
+
var import_openai = require("@ai-sdk/openai");
|
|
32
|
+
var import_ai = require("ai");
|
|
33
|
+
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
34
|
+
var createWorkflowOpenAI = (context) => {
|
|
35
|
+
return (0, import_openai.createOpenAI)({
|
|
36
|
+
compatibility: "strict",
|
|
37
|
+
fetch: async (input, init) => {
|
|
38
|
+
try {
|
|
39
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
40
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
41
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
42
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
43
|
+
const responseInfo = await context.call(stepName, {
|
|
44
|
+
url: input.toString(),
|
|
45
|
+
method: init?.method,
|
|
46
|
+
headers,
|
|
47
|
+
body
|
|
48
|
+
});
|
|
49
|
+
const responseHeaders = new Headers(
|
|
50
|
+
Object.entries(responseInfo.header).reduce(
|
|
51
|
+
(acc, [key, values]) => {
|
|
52
|
+
acc[key] = values.join(", ");
|
|
53
|
+
return acc;
|
|
54
|
+
},
|
|
55
|
+
{}
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
59
|
+
status: responseInfo.status,
|
|
60
|
+
headers: responseHeaders
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
64
|
+
throw error;
|
|
65
|
+
} else {
|
|
66
|
+
console.error("Error in fetch implementation:", error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
var wrapTools = ({
|
|
74
|
+
context,
|
|
75
|
+
tools
|
|
76
|
+
}) => {
|
|
77
|
+
return Object.fromEntries(
|
|
78
|
+
Object.entries(tools).map((toolInfo) => {
|
|
79
|
+
const [toolName, tool3] = toolInfo;
|
|
80
|
+
const aiSDKTool = convertToAISDKTool(tool3);
|
|
81
|
+
const execute = aiSDKTool.execute;
|
|
82
|
+
if (execute) {
|
|
83
|
+
const wrappedExecute = (...params) => {
|
|
84
|
+
return context.run(`Run tool ${toolName}`, () => execute(...params));
|
|
85
|
+
};
|
|
86
|
+
aiSDKTool.execute = wrappedExecute;
|
|
87
|
+
}
|
|
88
|
+
return [toolName, aiSDKTool];
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
var convertToAISDKTool = (tool3) => {
|
|
93
|
+
const isLangchainTool = "invoke" in tool3;
|
|
94
|
+
return isLangchainTool ? convertLangchainTool(tool3) : tool3;
|
|
95
|
+
};
|
|
96
|
+
var convertLangchainTool = (langchainTool) => {
|
|
97
|
+
return (0, import_ai.tool)({
|
|
98
|
+
description: langchainTool.description,
|
|
99
|
+
parameters: langchainTool.schema,
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
execute: async (param) => langchainTool.invoke(param)
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/agents/agent.ts
|
|
106
|
+
var import_zod = require("zod");
|
|
107
|
+
var import_ai2 = require("ai");
|
|
108
|
+
var Agent = class {
|
|
109
|
+
name;
|
|
110
|
+
tools;
|
|
111
|
+
maxSteps;
|
|
112
|
+
background;
|
|
113
|
+
model;
|
|
114
|
+
constructor({ tools, maxSteps, background, name, model }) {
|
|
115
|
+
this.name = name;
|
|
116
|
+
this.tools = tools ?? {};
|
|
117
|
+
this.maxSteps = maxSteps;
|
|
118
|
+
this.background = background;
|
|
119
|
+
this.model = model;
|
|
120
|
+
}
|
|
121
|
+
async call({ prompt }) {
|
|
122
|
+
try {
|
|
123
|
+
return await (0, import_ai2.generateText)({
|
|
124
|
+
model: this.model,
|
|
125
|
+
tools: this.tools,
|
|
126
|
+
maxSteps: this.maxSteps,
|
|
127
|
+
system: this.background,
|
|
128
|
+
prompt,
|
|
129
|
+
headers: {
|
|
130
|
+
[AGENT_NAME_HEADER]: this.name
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof import_ai2.ToolExecutionError) {
|
|
135
|
+
if (error.cause instanceof Error && error.cause.name === "WorkflowAbort") {
|
|
136
|
+
throw error.cause;
|
|
137
|
+
} else if (error.cause instanceof import_ai2.ToolExecutionError && error.cause.cause instanceof Error && error.cause.cause.name === "WorkflowAbort") {
|
|
138
|
+
throw error.cause.cause;
|
|
139
|
+
} else {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
asTool() {
|
|
148
|
+
const toolDescriptions = Object.values(this.tools).map((tool3) => tool3.description).join("\n");
|
|
149
|
+
return (0, import_ai2.tool)({
|
|
150
|
+
parameters: import_zod.z.object({ prompt: import_zod.z.string() }),
|
|
151
|
+
execute: async ({ prompt }) => {
|
|
152
|
+
return await this.call({ prompt });
|
|
153
|
+
},
|
|
154
|
+
description: `An AI Agent with the following background: ${this.background}Has access to the following tools: ${toolDescriptions}`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var MANAGER_AGENT_PROMPT = `You are an AI agent who orchestrates other AI Agents.
|
|
159
|
+
These other agents have tools available to them.
|
|
160
|
+
Given a prompt, utilize these agents to address requests.
|
|
161
|
+
Don't always call all the agents provided to you at the same time. You can call one and use it's response to call another.
|
|
162
|
+
`;
|
|
163
|
+
var ManagerAgent = class extends Agent {
|
|
164
|
+
agents;
|
|
165
|
+
constructor({
|
|
166
|
+
maxSteps,
|
|
167
|
+
background = MANAGER_AGENT_PROMPT,
|
|
168
|
+
agents,
|
|
169
|
+
model,
|
|
170
|
+
name = "manager llm"
|
|
171
|
+
}) {
|
|
172
|
+
super({
|
|
173
|
+
background,
|
|
174
|
+
maxSteps,
|
|
175
|
+
tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
|
|
176
|
+
name,
|
|
177
|
+
model
|
|
178
|
+
});
|
|
179
|
+
this.agents = agents;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/agents/task.ts
|
|
184
|
+
var Task = class {
|
|
185
|
+
context;
|
|
186
|
+
taskParameters;
|
|
187
|
+
constructor({
|
|
188
|
+
context,
|
|
189
|
+
taskParameters
|
|
190
|
+
}) {
|
|
191
|
+
this.context = context;
|
|
192
|
+
this.taskParameters = taskParameters;
|
|
193
|
+
}
|
|
194
|
+
async run() {
|
|
195
|
+
const { prompt, ...otherParams } = this.taskParameters;
|
|
196
|
+
const safePrompt = await this.context.run("Get Prompt", () => prompt);
|
|
197
|
+
if ("agent" in otherParams) {
|
|
198
|
+
const agent = otherParams.agent;
|
|
199
|
+
const result = await agent.call({
|
|
200
|
+
prompt: safePrompt
|
|
201
|
+
});
|
|
202
|
+
return { text: result.text };
|
|
203
|
+
} else {
|
|
204
|
+
const { agents, maxSteps, model, background } = otherParams;
|
|
205
|
+
const managerAgent = new ManagerAgent({
|
|
206
|
+
model,
|
|
207
|
+
maxSteps,
|
|
208
|
+
agents,
|
|
209
|
+
name: "Manager LLM",
|
|
210
|
+
background
|
|
211
|
+
});
|
|
212
|
+
const result = await managerAgent.call({ prompt: safePrompt });
|
|
213
|
+
return { text: result.text };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/agents/index.ts
|
|
219
|
+
var WorkflowAgents = class {
|
|
220
|
+
context;
|
|
221
|
+
constructor({ context }) {
|
|
222
|
+
this.context = context;
|
|
223
|
+
}
|
|
224
|
+
agent(params) {
|
|
225
|
+
const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
|
|
226
|
+
return new Agent({
|
|
227
|
+
...params,
|
|
228
|
+
tools: wrappedTools
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
task(taskParameters) {
|
|
232
|
+
return new Task({ context: this.context, taskParameters });
|
|
233
|
+
}
|
|
234
|
+
openai(...params) {
|
|
235
|
+
const openai = createWorkflowOpenAI(this.context);
|
|
236
|
+
return openai(...params);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
240
|
+
0 && (module.exports = {
|
|
241
|
+
Agent,
|
|
242
|
+
ManagerAgent,
|
|
243
|
+
WorkflowAgents,
|
|
244
|
+
createWorkflowOpenAI
|
|
245
|
+
});
|
package/agents.mjs
ADDED
package/astro.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { b as WorkflowContext, j as PublicServeOptions } from './types-
|
|
2
|
+
import { b as WorkflowContext, j as PublicServeOptions } from './types-BEyIoCRe.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
|
+
import 'ai';
|
|
5
|
+
import '@ai-sdk/openai';
|
|
6
|
+
import 'langchain/tools';
|
|
4
7
|
|
|
5
8
|
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: PublicServeOptions<TInitialPayload>): {
|
|
6
9
|
POST: APIRoute;
|
package/astro.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { b as WorkflowContext, j as PublicServeOptions } from './types-
|
|
2
|
+
import { b as WorkflowContext, j as PublicServeOptions } from './types-BEyIoCRe.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
|
+
import 'ai';
|
|
5
|
+
import '@ai-sdk/openai';
|
|
6
|
+
import 'langchain/tools';
|
|
4
7
|
|
|
5
8
|
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: PublicServeOptions<TInitialPayload>): {
|
|
6
9
|
POST: APIRoute;
|
package/astro.js
CHANGED
|
@@ -1632,6 +1632,216 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1632
1632
|
}
|
|
1633
1633
|
};
|
|
1634
1634
|
|
|
1635
|
+
// src/agents/adapters.ts
|
|
1636
|
+
var import_openai2 = require("@ai-sdk/openai");
|
|
1637
|
+
var import_ai = require("ai");
|
|
1638
|
+
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1639
|
+
var createWorkflowOpenAI = (context) => {
|
|
1640
|
+
return (0, import_openai2.createOpenAI)({
|
|
1641
|
+
compatibility: "strict",
|
|
1642
|
+
fetch: async (input, init) => {
|
|
1643
|
+
try {
|
|
1644
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
1645
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
1646
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
1647
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
1648
|
+
const responseInfo = await context.call(stepName, {
|
|
1649
|
+
url: input.toString(),
|
|
1650
|
+
method: init?.method,
|
|
1651
|
+
headers,
|
|
1652
|
+
body
|
|
1653
|
+
});
|
|
1654
|
+
const responseHeaders = new Headers(
|
|
1655
|
+
Object.entries(responseInfo.header).reduce(
|
|
1656
|
+
(acc, [key, values]) => {
|
|
1657
|
+
acc[key] = values.join(", ");
|
|
1658
|
+
return acc;
|
|
1659
|
+
},
|
|
1660
|
+
{}
|
|
1661
|
+
)
|
|
1662
|
+
);
|
|
1663
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
1664
|
+
status: responseInfo.status,
|
|
1665
|
+
headers: responseHeaders
|
|
1666
|
+
});
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
1669
|
+
throw error;
|
|
1670
|
+
} else {
|
|
1671
|
+
console.error("Error in fetch implementation:", error);
|
|
1672
|
+
throw error;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
});
|
|
1677
|
+
};
|
|
1678
|
+
var wrapTools = ({
|
|
1679
|
+
context,
|
|
1680
|
+
tools
|
|
1681
|
+
}) => {
|
|
1682
|
+
return Object.fromEntries(
|
|
1683
|
+
Object.entries(tools).map((toolInfo) => {
|
|
1684
|
+
const [toolName, tool3] = toolInfo;
|
|
1685
|
+
const aiSDKTool = convertToAISDKTool(tool3);
|
|
1686
|
+
const execute = aiSDKTool.execute;
|
|
1687
|
+
if (execute) {
|
|
1688
|
+
const wrappedExecute = (...params) => {
|
|
1689
|
+
return context.run(`Run tool ${toolName}`, () => execute(...params));
|
|
1690
|
+
};
|
|
1691
|
+
aiSDKTool.execute = wrappedExecute;
|
|
1692
|
+
}
|
|
1693
|
+
return [toolName, aiSDKTool];
|
|
1694
|
+
})
|
|
1695
|
+
);
|
|
1696
|
+
};
|
|
1697
|
+
var convertToAISDKTool = (tool3) => {
|
|
1698
|
+
const isLangchainTool = "invoke" in tool3;
|
|
1699
|
+
return isLangchainTool ? convertLangchainTool(tool3) : tool3;
|
|
1700
|
+
};
|
|
1701
|
+
var convertLangchainTool = (langchainTool) => {
|
|
1702
|
+
return (0, import_ai.tool)({
|
|
1703
|
+
description: langchainTool.description,
|
|
1704
|
+
parameters: langchainTool.schema,
|
|
1705
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1706
|
+
execute: async (param) => langchainTool.invoke(param)
|
|
1707
|
+
});
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
// src/agents/agent.ts
|
|
1711
|
+
var import_zod = require("zod");
|
|
1712
|
+
var import_ai2 = require("ai");
|
|
1713
|
+
var Agent = class {
|
|
1714
|
+
name;
|
|
1715
|
+
tools;
|
|
1716
|
+
maxSteps;
|
|
1717
|
+
background;
|
|
1718
|
+
model;
|
|
1719
|
+
constructor({ tools, maxSteps, background, name, model }) {
|
|
1720
|
+
this.name = name;
|
|
1721
|
+
this.tools = tools ?? {};
|
|
1722
|
+
this.maxSteps = maxSteps;
|
|
1723
|
+
this.background = background;
|
|
1724
|
+
this.model = model;
|
|
1725
|
+
}
|
|
1726
|
+
async call({ prompt }) {
|
|
1727
|
+
try {
|
|
1728
|
+
return await (0, import_ai2.generateText)({
|
|
1729
|
+
model: this.model,
|
|
1730
|
+
tools: this.tools,
|
|
1731
|
+
maxSteps: this.maxSteps,
|
|
1732
|
+
system: this.background,
|
|
1733
|
+
prompt,
|
|
1734
|
+
headers: {
|
|
1735
|
+
[AGENT_NAME_HEADER]: this.name
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
if (error instanceof import_ai2.ToolExecutionError) {
|
|
1740
|
+
if (error.cause instanceof Error && error.cause.name === "WorkflowAbort") {
|
|
1741
|
+
throw error.cause;
|
|
1742
|
+
} else if (error.cause instanceof import_ai2.ToolExecutionError && error.cause.cause instanceof Error && error.cause.cause.name === "WorkflowAbort") {
|
|
1743
|
+
throw error.cause.cause;
|
|
1744
|
+
} else {
|
|
1745
|
+
throw error;
|
|
1746
|
+
}
|
|
1747
|
+
} else {
|
|
1748
|
+
throw error;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
asTool() {
|
|
1753
|
+
const toolDescriptions = Object.values(this.tools).map((tool3) => tool3.description).join("\n");
|
|
1754
|
+
return (0, import_ai2.tool)({
|
|
1755
|
+
parameters: import_zod.z.object({ prompt: import_zod.z.string() }),
|
|
1756
|
+
execute: async ({ prompt }) => {
|
|
1757
|
+
return await this.call({ prompt });
|
|
1758
|
+
},
|
|
1759
|
+
description: `An AI Agent with the following background: ${this.background}Has access to the following tools: ${toolDescriptions}`
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
var MANAGER_AGENT_PROMPT = `You are an AI agent who orchestrates other AI Agents.
|
|
1764
|
+
These other agents have tools available to them.
|
|
1765
|
+
Given a prompt, utilize these agents to address requests.
|
|
1766
|
+
Don't always call all the agents provided to you at the same time. You can call one and use it's response to call another.
|
|
1767
|
+
`;
|
|
1768
|
+
var ManagerAgent = class extends Agent {
|
|
1769
|
+
agents;
|
|
1770
|
+
constructor({
|
|
1771
|
+
maxSteps,
|
|
1772
|
+
background = MANAGER_AGENT_PROMPT,
|
|
1773
|
+
agents,
|
|
1774
|
+
model,
|
|
1775
|
+
name = "manager llm"
|
|
1776
|
+
}) {
|
|
1777
|
+
super({
|
|
1778
|
+
background,
|
|
1779
|
+
maxSteps,
|
|
1780
|
+
tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
|
|
1781
|
+
name,
|
|
1782
|
+
model
|
|
1783
|
+
});
|
|
1784
|
+
this.agents = agents;
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
// src/agents/task.ts
|
|
1789
|
+
var Task = class {
|
|
1790
|
+
context;
|
|
1791
|
+
taskParameters;
|
|
1792
|
+
constructor({
|
|
1793
|
+
context,
|
|
1794
|
+
taskParameters
|
|
1795
|
+
}) {
|
|
1796
|
+
this.context = context;
|
|
1797
|
+
this.taskParameters = taskParameters;
|
|
1798
|
+
}
|
|
1799
|
+
async run() {
|
|
1800
|
+
const { prompt, ...otherParams } = this.taskParameters;
|
|
1801
|
+
const safePrompt = await this.context.run("Get Prompt", () => prompt);
|
|
1802
|
+
if ("agent" in otherParams) {
|
|
1803
|
+
const agent = otherParams.agent;
|
|
1804
|
+
const result = await agent.call({
|
|
1805
|
+
prompt: safePrompt
|
|
1806
|
+
});
|
|
1807
|
+
return { text: result.text };
|
|
1808
|
+
} else {
|
|
1809
|
+
const { agents, maxSteps, model, background } = otherParams;
|
|
1810
|
+
const managerAgent = new ManagerAgent({
|
|
1811
|
+
model,
|
|
1812
|
+
maxSteps,
|
|
1813
|
+
agents,
|
|
1814
|
+
name: "Manager LLM",
|
|
1815
|
+
background
|
|
1816
|
+
});
|
|
1817
|
+
const result = await managerAgent.call({ prompt: safePrompt });
|
|
1818
|
+
return { text: result.text };
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
// src/agents/index.ts
|
|
1824
|
+
var WorkflowAgents = class {
|
|
1825
|
+
context;
|
|
1826
|
+
constructor({ context }) {
|
|
1827
|
+
this.context = context;
|
|
1828
|
+
}
|
|
1829
|
+
agent(params) {
|
|
1830
|
+
const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
|
|
1831
|
+
return new Agent({
|
|
1832
|
+
...params,
|
|
1833
|
+
tools: wrappedTools
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
task(taskParameters) {
|
|
1837
|
+
return new Task({ context: this.context, taskParameters });
|
|
1838
|
+
}
|
|
1839
|
+
openai(...params) {
|
|
1840
|
+
const openai2 = createWorkflowOpenAI(this.context);
|
|
1841
|
+
return openai2(...params);
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
|
|
1635
1845
|
// src/context/context.ts
|
|
1636
1846
|
var WorkflowContext = class {
|
|
1637
1847
|
executor;
|
|
@@ -2017,6 +2227,11 @@ var WorkflowContext = class {
|
|
|
2017
2227
|
context: this
|
|
2018
2228
|
});
|
|
2019
2229
|
}
|
|
2230
|
+
get agents() {
|
|
2231
|
+
return new WorkflowAgents({
|
|
2232
|
+
context: this
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2020
2235
|
};
|
|
2021
2236
|
|
|
2022
2237
|
// src/logger.ts
|
|
@@ -2221,6 +2436,7 @@ var checkIfLastOneIsDuplicate = async (steps, debug) => {
|
|
|
2221
2436
|
if (step.stepId === lastStepId && step.targetStep === lastTargetStepId) {
|
|
2222
2437
|
const message = `Upstash Workflow: The step '${step.stepName}' with id '${step.stepId}' has run twice during workflow execution. Rest of the workflow will continue running as usual.`;
|
|
2223
2438
|
await debug?.log("WARN", "RESPONSE_DEFAULT", message);
|
|
2439
|
+
console.log(steps);
|
|
2224
2440
|
console.warn(message);
|
|
2225
2441
|
return true;
|
|
2226
2442
|
}
|