@upstash/workflow 0.2.5-agents → 0.2.5-agents-2
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/astro.d.mts +1 -2
- package/astro.d.ts +1 -2
- package/astro.js +89 -36
- package/astro.mjs +1 -2
- package/{chunk-RFX5YRRT.mjs → chunk-VOM3CFYZ.mjs} +321 -27
- package/cloudflare.d.mts +1 -2
- package/cloudflare.d.ts +1 -2
- package/cloudflare.js +89 -36
- package/cloudflare.mjs +1 -2
- package/express.d.mts +1 -2
- package/express.d.ts +1 -2
- package/express.js +89 -36
- package/express.mjs +3 -5
- package/h3.d.mts +1 -2
- package/h3.d.ts +1 -2
- package/h3.js +89 -36
- package/h3.mjs +1 -2
- package/hono.d.mts +1 -2
- package/hono.d.ts +1 -2
- package/hono.js +89 -36
- package/hono.mjs +1 -2
- package/index.d.mts +2 -3
- package/index.d.ts +2 -3
- package/index.js +89 -36
- package/index.mjs +1 -2
- package/nextjs.d.mts +1 -2
- package/nextjs.d.ts +1 -2
- package/nextjs.js +89 -36
- package/nextjs.mjs +1 -2
- package/package.json +1 -1
- package/solidjs.d.mts +1 -2
- package/solidjs.d.ts +1 -2
- package/solidjs.js +89 -36
- package/solidjs.mjs +1 -2
- package/svelte.d.mts +1 -2
- package/svelte.d.ts +1 -2
- package/svelte.js +89 -36
- package/svelte.mjs +1 -2
- package/{types-BEyIoCRe.d.mts → types-D9gwTj2n.d.mts} +175 -13
- package/{types-BEyIoCRe.d.ts → types-D9gwTj2n.d.ts} +175 -13
- package/agents.d.mts +0 -5
- package/agents.d.ts +0 -5
- package/agents.js +0 -245
- package/agents.mjs +0 -12
- package/chunk-PU5J4TNC.mjs +0 -251
package/index.js
CHANGED
|
@@ -839,29 +839,16 @@ var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
|
839
839
|
await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
|
|
840
840
|
deletedWorkflowRunId: workflowContext.workflowRunId
|
|
841
841
|
});
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
);
|
|
853
|
-
return { deleted: true };
|
|
854
|
-
} catch (error) {
|
|
855
|
-
if (error instanceof import_qstash3.QstashError && error.status === 404) {
|
|
856
|
-
await debug?.log("WARN", "SUBMIT_CLEANUP", {
|
|
857
|
-
message: `Failed to remove workflow run ${workflowContext.workflowRunId} as it doesn't exist.`,
|
|
858
|
-
name: error.name,
|
|
859
|
-
errorMessage: error.message
|
|
860
|
-
});
|
|
861
|
-
return { deleted: false };
|
|
862
|
-
}
|
|
863
|
-
throw error;
|
|
864
|
-
}
|
|
842
|
+
await workflowContext.qstashClient.http.request({
|
|
843
|
+
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
844
|
+
method: "DELETE",
|
|
845
|
+
parseResponseAsJson: false
|
|
846
|
+
});
|
|
847
|
+
await debug?.log(
|
|
848
|
+
"SUBMIT",
|
|
849
|
+
"SUBMIT_CLEANUP",
|
|
850
|
+
`workflow run ${workflowContext.workflowRunId} deleted.`
|
|
851
|
+
);
|
|
865
852
|
};
|
|
866
853
|
var recreateUserHeaders = (headers) => {
|
|
867
854
|
const filteredHeaders = new Headers();
|
|
@@ -1648,7 +1635,22 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1648
1635
|
// src/agents/adapters.ts
|
|
1649
1636
|
var import_openai2 = require("@ai-sdk/openai");
|
|
1650
1637
|
var import_ai = require("ai");
|
|
1638
|
+
|
|
1639
|
+
// src/agents/constants.ts
|
|
1651
1640
|
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1641
|
+
var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
|
|
1642
|
+
|
|
1643
|
+
These other agents have tools available to them.
|
|
1644
|
+
|
|
1645
|
+
Given a prompt, utilize these agents to address requests.
|
|
1646
|
+
|
|
1647
|
+
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.
|
|
1648
|
+
|
|
1649
|
+
Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
|
|
1650
|
+
you need from that agent.
|
|
1651
|
+
`;
|
|
1652
|
+
|
|
1653
|
+
// src/agents/adapters.ts
|
|
1652
1654
|
var createWorkflowOpenAI = (context) => {
|
|
1653
1655
|
return (0, import_openai2.createOpenAI)({
|
|
1654
1656
|
compatibility: "strict",
|
|
@@ -1715,8 +1717,7 @@ var convertLangchainTool = (langchainTool) => {
|
|
|
1715
1717
|
return (0, import_ai.tool)({
|
|
1716
1718
|
description: langchainTool.description,
|
|
1717
1719
|
parameters: langchainTool.schema,
|
|
1718
|
-
|
|
1719
|
-
execute: async (param) => langchainTool.invoke(param)
|
|
1720
|
+
execute: async (...param) => langchainTool.invoke(...param)
|
|
1720
1721
|
});
|
|
1721
1722
|
};
|
|
1722
1723
|
|
|
@@ -1729,16 +1730,24 @@ var Agent = class {
|
|
|
1729
1730
|
maxSteps;
|
|
1730
1731
|
background;
|
|
1731
1732
|
model;
|
|
1732
|
-
|
|
1733
|
+
temparature;
|
|
1734
|
+
constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }) {
|
|
1733
1735
|
this.name = name;
|
|
1734
1736
|
this.tools = tools ?? {};
|
|
1735
1737
|
this.maxSteps = maxSteps;
|
|
1736
1738
|
this.background = background;
|
|
1737
1739
|
this.model = model;
|
|
1740
|
+
this.temparature = temparature;
|
|
1738
1741
|
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Trigger the agent by passing a prompt
|
|
1744
|
+
*
|
|
1745
|
+
* @param prompt task to assign to the agent
|
|
1746
|
+
* @returns Response as `{ text: string }`
|
|
1747
|
+
*/
|
|
1739
1748
|
async call({ prompt }) {
|
|
1740
1749
|
try {
|
|
1741
|
-
|
|
1750
|
+
const result = await (0, import_ai2.generateText)({
|
|
1742
1751
|
model: this.model,
|
|
1743
1752
|
tools: this.tools,
|
|
1744
1753
|
maxSteps: this.maxSteps,
|
|
@@ -1746,8 +1755,10 @@ var Agent = class {
|
|
|
1746
1755
|
prompt,
|
|
1747
1756
|
headers: {
|
|
1748
1757
|
[AGENT_NAME_HEADER]: this.name
|
|
1749
|
-
}
|
|
1758
|
+
},
|
|
1759
|
+
temperature: this.temparature
|
|
1750
1760
|
});
|
|
1761
|
+
return { text: result.text };
|
|
1751
1762
|
} catch (error) {
|
|
1752
1763
|
if (error instanceof import_ai2.ToolExecutionError) {
|
|
1753
1764
|
if (error.cause instanceof Error && error.cause.name === "WorkflowAbort") {
|
|
@@ -1762,6 +1773,11 @@ var Agent = class {
|
|
|
1762
1773
|
}
|
|
1763
1774
|
}
|
|
1764
1775
|
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Convert the agent to a tool which can be used by other agents.
|
|
1778
|
+
*
|
|
1779
|
+
* @returns the agent as a tool
|
|
1780
|
+
*/
|
|
1765
1781
|
asTool() {
|
|
1766
1782
|
const toolDescriptions = Object.values(this.tools).map((tool3) => tool3.description).join("\n");
|
|
1767
1783
|
return (0, import_ai2.tool)({
|
|
@@ -1773,18 +1789,25 @@ var Agent = class {
|
|
|
1773
1789
|
});
|
|
1774
1790
|
}
|
|
1775
1791
|
};
|
|
1776
|
-
var MANAGER_AGENT_PROMPT = `You are an AI agent who orchestrates other AI Agents.
|
|
1777
|
-
These other agents have tools available to them.
|
|
1778
|
-
Given a prompt, utilize these agents to address requests.
|
|
1779
|
-
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.
|
|
1780
|
-
`;
|
|
1781
1792
|
var ManagerAgent = class extends Agent {
|
|
1782
1793
|
agents;
|
|
1794
|
+
/**
|
|
1795
|
+
* A manager agent which coordinates agents available to it to achieve a
|
|
1796
|
+
* given task
|
|
1797
|
+
*
|
|
1798
|
+
* @param name Name of the agent
|
|
1799
|
+
* @param background Background of the agent. If not passed, default will be used.
|
|
1800
|
+
* @param model LLM model to use
|
|
1801
|
+
* @param agents: List of agents available to the agent
|
|
1802
|
+
* @param maxSteps number of times the manager agent can call the LLM at most.
|
|
1803
|
+
* If the agent abruptly stops execution after calling other agents, you may
|
|
1804
|
+
* need to increase maxSteps
|
|
1805
|
+
*/
|
|
1783
1806
|
constructor({
|
|
1784
|
-
maxSteps,
|
|
1785
|
-
background = MANAGER_AGENT_PROMPT,
|
|
1786
1807
|
agents,
|
|
1808
|
+
background = MANAGER_AGENT_PROMPT,
|
|
1787
1809
|
model,
|
|
1810
|
+
maxSteps,
|
|
1788
1811
|
name = "manager llm"
|
|
1789
1812
|
}) {
|
|
1790
1813
|
super({
|
|
@@ -1809,6 +1832,11 @@ var Task = class {
|
|
|
1809
1832
|
this.context = context;
|
|
1810
1833
|
this.taskParameters = taskParameters;
|
|
1811
1834
|
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Run the agents to complete the task
|
|
1837
|
+
*
|
|
1838
|
+
* @returns Result of the task as { text: string }
|
|
1839
|
+
*/
|
|
1812
1840
|
async run() {
|
|
1813
1841
|
const { prompt, ...otherParams } = this.taskParameters;
|
|
1814
1842
|
const safePrompt = await this.context.run("Get Prompt", () => prompt);
|
|
@@ -1839,6 +1867,29 @@ var WorkflowAgents = class {
|
|
|
1839
1867
|
constructor({ context }) {
|
|
1840
1868
|
this.context = context;
|
|
1841
1869
|
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Defines an agent
|
|
1872
|
+
*
|
|
1873
|
+
* ```ts
|
|
1874
|
+
* const researcherAgent = context.agents.agent({
|
|
1875
|
+
* model,
|
|
1876
|
+
* name: 'academic',
|
|
1877
|
+
* maxSteps: 2,
|
|
1878
|
+
* tools: {
|
|
1879
|
+
* wikiTool: new WikipediaQueryRun({
|
|
1880
|
+
* topKResults: 1,
|
|
1881
|
+
* maxDocContentLength: 500,
|
|
1882
|
+
* })
|
|
1883
|
+
* },
|
|
1884
|
+
* background:
|
|
1885
|
+
* 'You are researcher agent with access to Wikipedia. ' +
|
|
1886
|
+
* 'Utilize Wikipedia as much as possible for correct information',
|
|
1887
|
+
* });
|
|
1888
|
+
* ```
|
|
1889
|
+
*
|
|
1890
|
+
* @param params agent parameters
|
|
1891
|
+
* @returns
|
|
1892
|
+
*/
|
|
1842
1893
|
agent(params) {
|
|
1843
1894
|
const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
|
|
1844
1895
|
return new Agent({
|
|
@@ -1849,6 +1900,9 @@ var WorkflowAgents = class {
|
|
|
1849
1900
|
task(taskParameters) {
|
|
1850
1901
|
return new Task({ context: this.context, taskParameters });
|
|
1851
1902
|
}
|
|
1903
|
+
/**
|
|
1904
|
+
* creates an openai model for agents
|
|
1905
|
+
*/
|
|
1852
1906
|
openai(...params) {
|
|
1853
1907
|
const openai2 = createWorkflowOpenAI(this.context);
|
|
1854
1908
|
return openai2(...params);
|
|
@@ -2449,7 +2503,6 @@ var checkIfLastOneIsDuplicate = async (steps, debug) => {
|
|
|
2449
2503
|
if (step.stepId === lastStepId && step.targetStep === lastTargetStepId) {
|
|
2450
2504
|
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.`;
|
|
2451
2505
|
await debug?.log("WARN", "RESPONSE_DEFAULT", message);
|
|
2452
|
-
console.log(steps);
|
|
2453
2506
|
console.warn(message);
|
|
2454
2507
|
return true;
|
|
2455
2508
|
}
|
package/index.mjs
CHANGED
package/nextjs.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'ai';
|
|
5
5
|
import '@ai-sdk/openai';
|
|
6
|
-
import 'langchain/tools';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Serve method to serve a Upstash Workflow in a Nextjs project
|
package/nextjs.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'ai';
|
|
5
5
|
import '@ai-sdk/openai';
|
|
6
|
-
import 'langchain/tools';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Serve method to serve a Upstash Workflow in a Nextjs project
|
package/nextjs.js
CHANGED
|
@@ -827,29 +827,16 @@ var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
|
827
827
|
await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
|
|
828
828
|
deletedWorkflowRunId: workflowContext.workflowRunId
|
|
829
829
|
});
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
);
|
|
841
|
-
return { deleted: true };
|
|
842
|
-
} catch (error) {
|
|
843
|
-
if (error instanceof import_qstash3.QstashError && error.status === 404) {
|
|
844
|
-
await debug?.log("WARN", "SUBMIT_CLEANUP", {
|
|
845
|
-
message: `Failed to remove workflow run ${workflowContext.workflowRunId} as it doesn't exist.`,
|
|
846
|
-
name: error.name,
|
|
847
|
-
errorMessage: error.message
|
|
848
|
-
});
|
|
849
|
-
return { deleted: false };
|
|
850
|
-
}
|
|
851
|
-
throw error;
|
|
852
|
-
}
|
|
830
|
+
await workflowContext.qstashClient.http.request({
|
|
831
|
+
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
832
|
+
method: "DELETE",
|
|
833
|
+
parseResponseAsJson: false
|
|
834
|
+
});
|
|
835
|
+
await debug?.log(
|
|
836
|
+
"SUBMIT",
|
|
837
|
+
"SUBMIT_CLEANUP",
|
|
838
|
+
`workflow run ${workflowContext.workflowRunId} deleted.`
|
|
839
|
+
);
|
|
853
840
|
};
|
|
854
841
|
var recreateUserHeaders = (headers) => {
|
|
855
842
|
const filteredHeaders = new Headers();
|
|
@@ -1636,7 +1623,22 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1636
1623
|
// src/agents/adapters.ts
|
|
1637
1624
|
var import_openai2 = require("@ai-sdk/openai");
|
|
1638
1625
|
var import_ai = require("ai");
|
|
1626
|
+
|
|
1627
|
+
// src/agents/constants.ts
|
|
1639
1628
|
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1629
|
+
var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
|
|
1630
|
+
|
|
1631
|
+
These other agents have tools available to them.
|
|
1632
|
+
|
|
1633
|
+
Given a prompt, utilize these agents to address requests.
|
|
1634
|
+
|
|
1635
|
+
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.
|
|
1636
|
+
|
|
1637
|
+
Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
|
|
1638
|
+
you need from that agent.
|
|
1639
|
+
`;
|
|
1640
|
+
|
|
1641
|
+
// src/agents/adapters.ts
|
|
1640
1642
|
var createWorkflowOpenAI = (context) => {
|
|
1641
1643
|
return (0, import_openai2.createOpenAI)({
|
|
1642
1644
|
compatibility: "strict",
|
|
@@ -1703,8 +1705,7 @@ var convertLangchainTool = (langchainTool) => {
|
|
|
1703
1705
|
return (0, import_ai.tool)({
|
|
1704
1706
|
description: langchainTool.description,
|
|
1705
1707
|
parameters: langchainTool.schema,
|
|
1706
|
-
|
|
1707
|
-
execute: async (param) => langchainTool.invoke(param)
|
|
1708
|
+
execute: async (...param) => langchainTool.invoke(...param)
|
|
1708
1709
|
});
|
|
1709
1710
|
};
|
|
1710
1711
|
|
|
@@ -1717,16 +1718,24 @@ var Agent = class {
|
|
|
1717
1718
|
maxSteps;
|
|
1718
1719
|
background;
|
|
1719
1720
|
model;
|
|
1720
|
-
|
|
1721
|
+
temparature;
|
|
1722
|
+
constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }) {
|
|
1721
1723
|
this.name = name;
|
|
1722
1724
|
this.tools = tools ?? {};
|
|
1723
1725
|
this.maxSteps = maxSteps;
|
|
1724
1726
|
this.background = background;
|
|
1725
1727
|
this.model = model;
|
|
1728
|
+
this.temparature = temparature;
|
|
1726
1729
|
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Trigger the agent by passing a prompt
|
|
1732
|
+
*
|
|
1733
|
+
* @param prompt task to assign to the agent
|
|
1734
|
+
* @returns Response as `{ text: string }`
|
|
1735
|
+
*/
|
|
1727
1736
|
async call({ prompt }) {
|
|
1728
1737
|
try {
|
|
1729
|
-
|
|
1738
|
+
const result = await (0, import_ai2.generateText)({
|
|
1730
1739
|
model: this.model,
|
|
1731
1740
|
tools: this.tools,
|
|
1732
1741
|
maxSteps: this.maxSteps,
|
|
@@ -1734,8 +1743,10 @@ var Agent = class {
|
|
|
1734
1743
|
prompt,
|
|
1735
1744
|
headers: {
|
|
1736
1745
|
[AGENT_NAME_HEADER]: this.name
|
|
1737
|
-
}
|
|
1746
|
+
},
|
|
1747
|
+
temperature: this.temparature
|
|
1738
1748
|
});
|
|
1749
|
+
return { text: result.text };
|
|
1739
1750
|
} catch (error) {
|
|
1740
1751
|
if (error instanceof import_ai2.ToolExecutionError) {
|
|
1741
1752
|
if (error.cause instanceof Error && error.cause.name === "WorkflowAbort") {
|
|
@@ -1750,6 +1761,11 @@ var Agent = class {
|
|
|
1750
1761
|
}
|
|
1751
1762
|
}
|
|
1752
1763
|
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Convert the agent to a tool which can be used by other agents.
|
|
1766
|
+
*
|
|
1767
|
+
* @returns the agent as a tool
|
|
1768
|
+
*/
|
|
1753
1769
|
asTool() {
|
|
1754
1770
|
const toolDescriptions = Object.values(this.tools).map((tool3) => tool3.description).join("\n");
|
|
1755
1771
|
return (0, import_ai2.tool)({
|
|
@@ -1761,18 +1777,25 @@ var Agent = class {
|
|
|
1761
1777
|
});
|
|
1762
1778
|
}
|
|
1763
1779
|
};
|
|
1764
|
-
var MANAGER_AGENT_PROMPT = `You are an AI agent who orchestrates other AI Agents.
|
|
1765
|
-
These other agents have tools available to them.
|
|
1766
|
-
Given a prompt, utilize these agents to address requests.
|
|
1767
|
-
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.
|
|
1768
|
-
`;
|
|
1769
1780
|
var ManagerAgent = class extends Agent {
|
|
1770
1781
|
agents;
|
|
1782
|
+
/**
|
|
1783
|
+
* A manager agent which coordinates agents available to it to achieve a
|
|
1784
|
+
* given task
|
|
1785
|
+
*
|
|
1786
|
+
* @param name Name of the agent
|
|
1787
|
+
* @param background Background of the agent. If not passed, default will be used.
|
|
1788
|
+
* @param model LLM model to use
|
|
1789
|
+
* @param agents: List of agents available to the agent
|
|
1790
|
+
* @param maxSteps number of times the manager agent can call the LLM at most.
|
|
1791
|
+
* If the agent abruptly stops execution after calling other agents, you may
|
|
1792
|
+
* need to increase maxSteps
|
|
1793
|
+
*/
|
|
1771
1794
|
constructor({
|
|
1772
|
-
maxSteps,
|
|
1773
|
-
background = MANAGER_AGENT_PROMPT,
|
|
1774
1795
|
agents,
|
|
1796
|
+
background = MANAGER_AGENT_PROMPT,
|
|
1775
1797
|
model,
|
|
1798
|
+
maxSteps,
|
|
1776
1799
|
name = "manager llm"
|
|
1777
1800
|
}) {
|
|
1778
1801
|
super({
|
|
@@ -1797,6 +1820,11 @@ var Task = class {
|
|
|
1797
1820
|
this.context = context;
|
|
1798
1821
|
this.taskParameters = taskParameters;
|
|
1799
1822
|
}
|
|
1823
|
+
/**
|
|
1824
|
+
* Run the agents to complete the task
|
|
1825
|
+
*
|
|
1826
|
+
* @returns Result of the task as { text: string }
|
|
1827
|
+
*/
|
|
1800
1828
|
async run() {
|
|
1801
1829
|
const { prompt, ...otherParams } = this.taskParameters;
|
|
1802
1830
|
const safePrompt = await this.context.run("Get Prompt", () => prompt);
|
|
@@ -1827,6 +1855,29 @@ var WorkflowAgents = class {
|
|
|
1827
1855
|
constructor({ context }) {
|
|
1828
1856
|
this.context = context;
|
|
1829
1857
|
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Defines an agent
|
|
1860
|
+
*
|
|
1861
|
+
* ```ts
|
|
1862
|
+
* const researcherAgent = context.agents.agent({
|
|
1863
|
+
* model,
|
|
1864
|
+
* name: 'academic',
|
|
1865
|
+
* maxSteps: 2,
|
|
1866
|
+
* tools: {
|
|
1867
|
+
* wikiTool: new WikipediaQueryRun({
|
|
1868
|
+
* topKResults: 1,
|
|
1869
|
+
* maxDocContentLength: 500,
|
|
1870
|
+
* })
|
|
1871
|
+
* },
|
|
1872
|
+
* background:
|
|
1873
|
+
* 'You are researcher agent with access to Wikipedia. ' +
|
|
1874
|
+
* 'Utilize Wikipedia as much as possible for correct information',
|
|
1875
|
+
* });
|
|
1876
|
+
* ```
|
|
1877
|
+
*
|
|
1878
|
+
* @param params agent parameters
|
|
1879
|
+
* @returns
|
|
1880
|
+
*/
|
|
1830
1881
|
agent(params) {
|
|
1831
1882
|
const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
|
|
1832
1883
|
return new Agent({
|
|
@@ -1837,6 +1888,9 @@ var WorkflowAgents = class {
|
|
|
1837
1888
|
task(taskParameters) {
|
|
1838
1889
|
return new Task({ context: this.context, taskParameters });
|
|
1839
1890
|
}
|
|
1891
|
+
/**
|
|
1892
|
+
* creates an openai model for agents
|
|
1893
|
+
*/
|
|
1840
1894
|
openai(...params) {
|
|
1841
1895
|
const openai2 = createWorkflowOpenAI(this.context);
|
|
1842
1896
|
return openai2(...params);
|
|
@@ -2437,7 +2491,6 @@ var checkIfLastOneIsDuplicate = async (steps, debug) => {
|
|
|
2437
2491
|
if (step.stepId === lastStepId && step.targetStep === lastTargetStepId) {
|
|
2438
2492
|
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.`;
|
|
2439
2493
|
await debug?.log("WARN", "RESPONSE_DEFAULT", message);
|
|
2440
|
-
console.log(steps);
|
|
2441
2494
|
console.warn(message);
|
|
2442
2495
|
return true;
|
|
2443
2496
|
}
|
package/nextjs.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/workflow","version":"v0.2.5-agents","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.2.5-agents-2","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.20","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
|
package/solidjs.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'ai';
|
|
5
5
|
import '@ai-sdk/openai';
|
|
6
|
-
import 'langchain/tools';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Serve method to serve a Upstash Workflow in a Nextjs project
|
package/solidjs.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'ai';
|
|
5
5
|
import '@ai-sdk/openai';
|
|
6
|
-
import 'langchain/tools';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Serve method to serve a Upstash Workflow in a Nextjs project
|