@ai-sdk/workflow 2.0.70 → 2.0.72
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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +130 -79
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/do-generate-step.ts +14 -2
- package/src/do-stream-step.ts +3 -16
- package/src/language-model-prompt-to-model-messages.ts +28 -0
- package/src/model-call-iterator.ts +3 -0
- package/src/model-call.ts +6 -1
- package/src/test/concurrency-workflows.ts +66 -0
- package/src/workflow-agent.ts +170 -120
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 2.0.72
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9523eb0: feat(ai): add configurable tool call execution concurrency
|
|
8
|
+
- Updated dependencies [9523eb0]
|
|
9
|
+
- ai@7.0.140
|
|
10
|
+
|
|
11
|
+
## 2.0.71
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 6d6900f: fix(workflow): pass URL-backed inputs through workflow functions before model steps
|
|
16
|
+
|
|
17
|
+
URL-backed image and file inputs are no longer downloaded in the workflow context, where `fetch` is unavailable. Model steps now download unsupported URLs using the resolved model's `supportedUrls`, for both `stream()` and `generate()`.
|
|
18
|
+
|
|
19
|
+
A custom `experimental_download` function now runs inside the model step instead of the workflow context. Mark it with `'use step'` so it can be passed to the step (as with `repairToolCall`).
|
|
20
|
+
|
|
21
|
+
- ai@7.0.139
|
|
22
|
+
|
|
3
23
|
## 2.0.70
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -281,6 +281,7 @@ interface PrepareCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext e
|
|
|
281
281
|
tools: TTools;
|
|
282
282
|
instructions?: Instructions;
|
|
283
283
|
toolChoice?: ToolChoice<TTools>;
|
|
284
|
+
toolCallConcurrency?: number;
|
|
284
285
|
stopWhen?: StopCondition<NoInfer<TTools>, TRuntimeContext> | Array<StopCondition<NoInfer<TTools>, TRuntimeContext>>;
|
|
285
286
|
activeTools?: ActiveTools<NoInfer<TTools>>;
|
|
286
287
|
experimental_download?: DownloadFunction;
|
|
@@ -342,6 +343,12 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
|
|
|
342
343
|
* The tool choice strategy. Default: 'auto'.
|
|
343
344
|
*/
|
|
344
345
|
toolChoice?: ToolChoice<TTools>;
|
|
346
|
+
/**
|
|
347
|
+
* Maximum number of local tool calls that may execute concurrently within a step.
|
|
348
|
+
* Set to `1` to execute calls sequentially in model order, including approved
|
|
349
|
+
* calls. By default, all local tool calls execute concurrently.
|
|
350
|
+
*/
|
|
351
|
+
toolCallConcurrency?: number;
|
|
345
352
|
/**
|
|
346
353
|
* Optional telemetry configuration.
|
|
347
354
|
*/
|
|
@@ -397,6 +404,7 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
|
|
|
397
404
|
experimental_repairToolCall?: ToolCallRepairFunction$1<TTools>;
|
|
398
405
|
/**
|
|
399
406
|
* Default custom download function to use for URLs.
|
|
407
|
+
* Mark the function with `'use step'` when used in a workflow.
|
|
400
408
|
*
|
|
401
409
|
* Per-stream `experimental_download` values passed to `stream()` override this default.
|
|
402
410
|
*/
|
|
@@ -712,6 +720,12 @@ type WorkflowAgentCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext
|
|
|
712
720
|
* Overrides the toolChoice from the constructor if provided.
|
|
713
721
|
*/
|
|
714
722
|
toolChoice?: ToolChoice<TTools>;
|
|
723
|
+
/**
|
|
724
|
+
* Maximum number of local tool calls that may execute concurrently within a step.
|
|
725
|
+
* Set to `1` to execute calls sequentially in model order, including approved
|
|
726
|
+
* calls. By default, all local tool calls execute concurrently.
|
|
727
|
+
*/
|
|
728
|
+
toolCallConcurrency?: number;
|
|
715
729
|
/**
|
|
716
730
|
* Limits the tools that are available for the model to call without
|
|
717
731
|
* changing the tool call and result types in the result.
|
|
@@ -781,6 +795,7 @@ type WorkflowAgentCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext
|
|
|
781
795
|
/**
|
|
782
796
|
* Custom download function to use for URLs.
|
|
783
797
|
* By default, files are downloaded if the model does not support the URL for the given media type.
|
|
798
|
+
* Mark the function with `'use step'` when used in a workflow.
|
|
784
799
|
*/
|
|
785
800
|
experimental_download?: DownloadFunction;
|
|
786
801
|
/**
|
|
@@ -1073,6 +1088,7 @@ export declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntim
|
|
|
1073
1088
|
private instructions?;
|
|
1074
1089
|
private generationSettings;
|
|
1075
1090
|
private toolChoice?;
|
|
1091
|
+
private toolCallConcurrency?;
|
|
1076
1092
|
private telemetry?;
|
|
1077
1093
|
private runtimeContext?;
|
|
1078
1094
|
private toolsContext?;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["CoreTelemetryOptions","SandboxSession","ToolCallRepairFunction"],"sources":["../src/model-call.ts","../src/types.ts","../src/workflow-agent.ts","../src/to-ui-message-chunk.ts","../src/normalize-ui-message-stream.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["CoreTelemetryOptions","SandboxSession","ToolCallRepairFunction"],"sources":["../src/model-call.ts","../src/types.ts","../src/workflow-agent.ts","../src/to-ui-message-chunk.ts","../src/normalize-ui-message-stream.ts"],"mappings":";;;;;KAuBY,oBAAoB,eAAe,UAAU,WACrD,qCAAqC;EAEnC;EACA;EACA;EACA;;EAEA;;;;;;;;;KCrBM,0BAA0B;;;;;;;;KC4E1B,+BACV,eAAe,UAAU,SACzB,wBAAwB,UAAU,WAChC,8BAA8B,QAAQ;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,WAAW;;;;;;;;EASX,aAAa;;;;EAKb,cAAc;;;;;;;;EASd;;;;EAKA,YAAY;;;;;EAMZ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BG,cACX,mBAAmB,UAAU,SAC7B,wBAAwB,UAAU,SAClC,cACA;;;;WAKgB;UAER;;;;WAIQ,OAAO;UACf;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAGA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAIA;UAIA;UAIA;UAIA;UACA;UACA;EAGN,YAAA,SAAS,qBACP,YACA,iBACA,QACA;EAoDE,SACJ,eAAe,aAAa,YAC5B,UAAU,sBAAsB,SAChC,iBAAiB,2BAA2B,iBAE5C,SAAS,6BACP,QACA,iBACA,SACA,kBAED,QAAQ,4BAA4B,QAAQ,iBAAiB;EAuC1D,OACJ,eAAe,aAAa,YAC5B,UAAU,2BAA2B,SACrC,iBAAiB,2BAA2B,iBAE5C,SAAS,2BACP,QACA,iBACA,SACA,kBAED,QAAQ,0BAA0B,QAAQ;UAI/B;UAuMA;;;;;;;;wBCp3DA,iBACd,MAAM,oBAAoB,WACzB;;;;;;;;;;;wBAwNa,oCACd;;;;;EAMA;IACO,gBAAgB,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBC3HhC,8BACrB,QAAQ,cAAc,kBACrB,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as normalizeUIMessageStreamParts, t as WorkflowChatTransport } from "./workflow-chat-transport-Dj1poviu.js";
|
|
2
2
|
import { asArray, asSchema, convertUint8ArrayToBase64, createIdGenerator, generateId, getErrorMessage, isAbortError, jsonSchema, validateTypes, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { DefaultGeneratedFile, InvalidToolApprovalSignatureError, NoOutputGeneratedError, Output, ToolChoiceViolationError, dynamicTool, experimental_filterActiveTools, experimental_streamLanguageModelCall, gateway, isStepCount, tool, wrapLanguageModel } from "ai";
|
|
4
|
-
import { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertLanguageModelContent, convertToLanguageModelPrompt, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, isOutputChunk, mapToolResultOutput, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions, prepareRetries, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, validateApprovedToolApprovals, verifyToolApprovalSignature } from "ai/internal";
|
|
4
|
+
import { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertLanguageModelContent, convertToLanguageModelPrompt, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, isOutputChunk, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, validateApprovedToolApprovals, verifyToolApprovalSignature } from "ai/internal";
|
|
5
5
|
import { getWorkflowMetadata } from "workflow";
|
|
6
6
|
import Ajv from "ajv";
|
|
7
7
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
@@ -382,6 +382,26 @@ async function buildModelStepResult(raw, toolCalls, finish, providerExecutedTool
|
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
384
|
//#endregion
|
|
385
|
+
//#region src/language-model-prompt-to-model-messages.ts
|
|
386
|
+
/**
|
|
387
|
+
* Prepares a workflow-side `LanguageModelV4Prompt` for a second, model-aware
|
|
388
|
+
* `convertToLanguageModelPrompt` pass inside a model step.
|
|
389
|
+
*
|
|
390
|
+
* The workflow-side conversion preserves URLs (it cannot download them) and
|
|
391
|
+
* filters out approval responses for tools that are not provider-executed.
|
|
392
|
+
* The remaining approval responses are restored with the `providerExecuted`
|
|
393
|
+
* marker that the second conversion expects.
|
|
394
|
+
*/
|
|
395
|
+
function languageModelPromptToModelMessages(prompt) {
|
|
396
|
+
return prompt.map((message) => message.role !== "tool" ? message : {
|
|
397
|
+
...message,
|
|
398
|
+
content: message.content.map((part) => part.type === "tool-approval-response" ? {
|
|
399
|
+
...part,
|
|
400
|
+
providerExecuted: true
|
|
401
|
+
} : part)
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
385
405
|
//#region src/serializable-schema.ts
|
|
386
406
|
/**
|
|
387
407
|
* Converts a ToolSet (with Zod/standard schemas and execute functions) to a
|
|
@@ -652,6 +672,16 @@ async function generateModelCall(prompt, modelInit, serializedTools, options, la
|
|
|
652
672
|
if (remaining != null && remaining <= 0) throw new DOMException("The generation deadline expired.", "TimeoutError");
|
|
653
673
|
const abortSignal = remaining == null ? options.abortSignal : AbortSignal.any([...options.abortSignal == null ? [] : [options.abortSignal], AbortSignal.timeout(remaining)]);
|
|
654
674
|
const model = resolveLanguageModel(modelInit);
|
|
675
|
+
const modelPrompt = await convertToLanguageModelPrompt({
|
|
676
|
+
prompt: {
|
|
677
|
+
instructions: void 0,
|
|
678
|
+
messages: languageModelPromptToModelMessages(prompt)
|
|
679
|
+
},
|
|
680
|
+
supportedUrls: await model.supportedUrls,
|
|
681
|
+
download: options.download,
|
|
682
|
+
abortSignal,
|
|
683
|
+
provider: model.provider.split(".")[0]
|
|
684
|
+
});
|
|
655
685
|
const tools = resolveSerializableTools(serializedTools);
|
|
656
686
|
const toolChoice = prepareToolChoice({ toolChoice: options.toolChoice });
|
|
657
687
|
const modelTools = await prepareTools({ tools });
|
|
@@ -680,7 +710,7 @@ async function generateModelCall(prompt, modelInit, serializedTools, options, la
|
|
|
680
710
|
callId: callId ?? "",
|
|
681
711
|
execute: () => model.doGenerate({
|
|
682
712
|
...settings,
|
|
683
|
-
prompt:
|
|
713
|
+
prompt: modelPrompt,
|
|
684
714
|
tools: modelTools,
|
|
685
715
|
toolChoice,
|
|
686
716
|
responseFormat: options.responseFormat,
|
|
@@ -707,7 +737,7 @@ async function generateModelCall(prompt, modelInit, serializedTools, options, la
|
|
|
707
737
|
toolCall,
|
|
708
738
|
tools,
|
|
709
739
|
repairToolCall: options.repairToolCall,
|
|
710
|
-
instructions:
|
|
740
|
+
instructions: modelPrompt.filter((message) => message.role === "system").map((message) => message.content).join("\n") || void 0,
|
|
711
741
|
messages: prompt.filter((message) => message.role !== "system")
|
|
712
742
|
})));
|
|
713
743
|
if ((toolChoice.type === "required" || toolChoice.type === "tool") && !toolCalls.some((call) => toolChoice.type === "required" || call.toolName === toolChoice.toolName)) throw new ToolChoiceViolationError({
|
|
@@ -837,13 +867,7 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
837
867
|
try {
|
|
838
868
|
const { stream } = await retry(() => experimental_streamLanguageModelCall({
|
|
839
869
|
model: modelWithTransforms,
|
|
840
|
-
messages: conversationPrompt
|
|
841
|
-
...message,
|
|
842
|
-
content: message.content.map((part) => part.type === "tool-approval-response" ? {
|
|
843
|
-
...part,
|
|
844
|
-
providerExecuted: true
|
|
845
|
-
} : part)
|
|
846
|
-
}),
|
|
870
|
+
messages: languageModelPromptToModelMessages(conversationPrompt),
|
|
847
871
|
allowSystemInMessages: true,
|
|
848
872
|
tools,
|
|
849
873
|
toolChoice: options?.toolChoice,
|
|
@@ -862,6 +886,7 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
862
886
|
stopSequences: options?.stopSequences,
|
|
863
887
|
seed: options?.seed,
|
|
864
888
|
repairToolCall: options?.repairToolCall,
|
|
889
|
+
download: options?.download,
|
|
865
890
|
...languageModelCallTelemetry
|
|
866
891
|
}));
|
|
867
892
|
return stream;
|
|
@@ -1182,7 +1207,7 @@ function mergePrepareStepGenerationSettings(current, overrides) {
|
|
|
1182
1207
|
...definedOverrides
|
|
1183
1208
|
};
|
|
1184
1209
|
}
|
|
1185
|
-
async function* modelCallIterator({ prompt, mode = "stream", include, initialInstructions, initialMessages = prompt, tools = {}, writable, model, stopConditions, onStepEnd, onStepFinish, onStepStart, onError, prepareStep, generationSettings, toolChoice, runtimeContext, toolsContext, telemetry, includeRawChunks = false, timeoutAt, repairToolCall, responseFormat, experimental_transform, experimental_sandbox: sandbox }) {
|
|
1210
|
+
async function* modelCallIterator({ prompt, mode = "stream", include, initialInstructions, initialMessages = prompt, tools = {}, writable, model, stopConditions, onStepEnd, onStepFinish, onStepStart, onError, prepareStep, generationSettings, toolChoice, runtimeContext, toolsContext, telemetry, includeRawChunks = false, timeoutAt, repairToolCall, download, responseFormat, experimental_transform, experimental_sandbox: sandbox }) {
|
|
1186
1211
|
let conversationPrompt = [...prompt];
|
|
1187
1212
|
let currentModel = model;
|
|
1188
1213
|
let currentGenerationSettings = generationSettings ?? {};
|
|
@@ -1310,6 +1335,7 @@ async function* modelCallIterator({ prompt, mode = "stream", include, initialIns
|
|
|
1310
1335
|
includeRawChunks,
|
|
1311
1336
|
timeoutAt,
|
|
1312
1337
|
repairToolCall,
|
|
1338
|
+
download,
|
|
1313
1339
|
responseFormat,
|
|
1314
1340
|
include,
|
|
1315
1341
|
experimental_transform,
|
|
@@ -1660,6 +1686,7 @@ var WorkflowAgent = class {
|
|
|
1660
1686
|
this.tools = options.tools ?? {};
|
|
1661
1687
|
this.instructions = options.instructions ?? options.system;
|
|
1662
1688
|
this.toolChoice = options.toolChoice;
|
|
1689
|
+
this.toolCallConcurrency = options.toolCallConcurrency;
|
|
1663
1690
|
this.telemetry = options.telemetry;
|
|
1664
1691
|
this.runtimeContext = options.runtimeContext;
|
|
1665
1692
|
this.toolsContext = options.toolsContext;
|
|
@@ -1733,6 +1760,7 @@ var WorkflowAgent = class {
|
|
|
1733
1760
|
let effectiveRuntimeContext = options.runtimeContext ?? this.runtimeContext ?? {};
|
|
1734
1761
|
let effectiveToolsContext = options.toolsContext ?? this.toolsContext ?? {};
|
|
1735
1762
|
let effectiveToolChoiceFromPrepare = options.toolChoice ?? this.toolChoice;
|
|
1763
|
+
let effectiveToolCallConcurrency = options.toolCallConcurrency ?? this.toolCallConcurrency;
|
|
1736
1764
|
let effectiveStopWhenFromPrepare = options.stopWhen ?? this.stopWhen ?? (mode === "generate" ? isStepCount(20) : void 0);
|
|
1737
1765
|
let effectiveActiveToolsFromPrepare = options.activeTools ?? this.activeTools;
|
|
1738
1766
|
let effectiveDownloadFromPrepare = options.experimental_download ?? this.experimentalDownload;
|
|
@@ -1748,6 +1776,7 @@ var WorkflowAgent = class {
|
|
|
1748
1776
|
tools: this.tools,
|
|
1749
1777
|
instructions: effectiveInstructions,
|
|
1750
1778
|
toolChoice: effectiveToolChoiceFromPrepare,
|
|
1779
|
+
toolCallConcurrency: effectiveToolCallConcurrency,
|
|
1751
1780
|
stopWhen: effectiveStopWhenFromPrepare,
|
|
1752
1781
|
activeTools: effectiveActiveToolsFromPrepare,
|
|
1753
1782
|
experimental_download: effectiveDownloadFromPrepare,
|
|
@@ -1766,6 +1795,7 @@ var WorkflowAgent = class {
|
|
|
1766
1795
|
if (prepared.runtimeContext !== void 0) effectiveRuntimeContext = prepared.runtimeContext;
|
|
1767
1796
|
if (prepared.toolsContext !== void 0) effectiveToolsContext = prepared.toolsContext;
|
|
1768
1797
|
if (prepared.toolChoice !== void 0) effectiveToolChoiceFromPrepare = prepared.toolChoice;
|
|
1798
|
+
if (prepared.toolCallConcurrency !== void 0) effectiveToolCallConcurrency = prepared.toolCallConcurrency;
|
|
1769
1799
|
if (prepared.stopWhen !== void 0) effectiveStopWhenFromPrepare = prepared.stopWhen;
|
|
1770
1800
|
if (prepared.activeTools !== void 0) effectiveActiveToolsFromPrepare = prepared.activeTools;
|
|
1771
1801
|
if (prepared.experimental_download !== void 0) effectiveDownloadFromPrepare = prepared.experimental_download;
|
|
@@ -1784,6 +1814,7 @@ var WorkflowAgent = class {
|
|
|
1784
1814
|
if (prepared.reasoning !== void 0) effectiveGenerationSettings.reasoning = prepared.reasoning;
|
|
1785
1815
|
if (prepared.providerOptions !== void 0) effectiveGenerationSettings.providerOptions = prepared.providerOptions;
|
|
1786
1816
|
}
|
|
1817
|
+
const toolCallConcurrency = prepareToolCallConcurrency(options.toolCallConcurrency ?? effectiveToolCallConcurrency);
|
|
1787
1818
|
const effectiveTelemetry = effectiveTelemetryFromPrepare;
|
|
1788
1819
|
const telemetryDispatcher = createRestrictedTelemetryDispatcher({
|
|
1789
1820
|
telemetry: effectiveTelemetry,
|
|
@@ -1795,7 +1826,7 @@ var WorkflowAgent = class {
|
|
|
1795
1826
|
allowSystemInMessages: this.allowSystemInMessages,
|
|
1796
1827
|
...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
|
|
1797
1828
|
});
|
|
1798
|
-
const
|
|
1829
|
+
const workflowDownload = async (requests) => requests.map(() => null);
|
|
1799
1830
|
const sandbox = options.experimental_sandbox ?? this.experimentalSandbox;
|
|
1800
1831
|
const abortSignalTimeout = isInWorkflow() ? void 0 : options.timeout;
|
|
1801
1832
|
const effectiveAbortSignal = mergeAbortSignals(options.abortSignal ?? effectiveGenerationSettings.abortSignal, abortSignalTimeout);
|
|
@@ -1810,13 +1841,15 @@ var WorkflowAgent = class {
|
|
|
1810
1841
|
effectiveRuntimeContext,
|
|
1811
1842
|
effectiveToolsContext,
|
|
1812
1843
|
effectiveToolChoiceFromPrepare,
|
|
1844
|
+
toolCallConcurrency,
|
|
1813
1845
|
effectiveStopWhenFromPrepare,
|
|
1814
1846
|
effectiveActiveToolsFromPrepare,
|
|
1815
1847
|
effectiveToolApprovalSecret,
|
|
1816
1848
|
effectiveTelemetry,
|
|
1817
1849
|
telemetryDispatcher,
|
|
1818
1850
|
prompt,
|
|
1819
|
-
download,
|
|
1851
|
+
download: effectiveDownloadFromPrepare,
|
|
1852
|
+
workflowDownload,
|
|
1820
1853
|
sandbox,
|
|
1821
1854
|
effectiveAbortSignal,
|
|
1822
1855
|
timeoutAt,
|
|
@@ -1825,7 +1858,7 @@ var WorkflowAgent = class {
|
|
|
1825
1858
|
};
|
|
1826
1859
|
}
|
|
1827
1860
|
async execute(options, mode = "stream") {
|
|
1828
|
-
const { onEnd, effectiveModel, effectiveInstructions, effectiveGenerationSettings, effectiveRuntimeContext, effectiveToolsContext, effectiveToolChoiceFromPrepare, effectiveStopWhenFromPrepare, effectiveActiveToolsFromPrepare, effectiveToolApprovalSecret, effectiveTelemetry, telemetryDispatcher, prompt, download, sandbox, effectiveAbortSignal, timeoutAt, mergedOnToolExecutionStart, mergedOnToolExecutionEnd } = await this.prepareInvocation(options, mode);
|
|
1861
|
+
const { onEnd, effectiveModel, effectiveInstructions, effectiveGenerationSettings, effectiveRuntimeContext, effectiveToolsContext, effectiveToolChoiceFromPrepare, toolCallConcurrency, effectiveStopWhenFromPrepare, effectiveActiveToolsFromPrepare, effectiveToolApprovalSecret, effectiveTelemetry, telemetryDispatcher, prompt, download, workflowDownload, sandbox, effectiveAbortSignal, timeoutAt, mergedOnToolExecutionStart, mergedOnToolExecutionEnd } = await this.prepareInvocation(options, mode);
|
|
1829
1862
|
const initialResponseMessages = [];
|
|
1830
1863
|
const abortReason = () => effectiveAbortSignal?.reason === void 0 ? void 0 : { value: effectiveAbortSignal.reason };
|
|
1831
1864
|
const collectedApprovals = collectToolApprovals({ messages: prompt.messages });
|
|
@@ -1849,13 +1882,55 @@ var WorkflowAgent = class {
|
|
|
1849
1882
|
if (approvedToolApprovals.length > 0 || deniedToolApprovals.length > 0) {
|
|
1850
1883
|
const toolResultContent = [];
|
|
1851
1884
|
const approvedRawResults = [];
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1885
|
+
const approvedResults = await mapWithConcurrency({
|
|
1886
|
+
items: approvedToolApprovals.filter((approval) => !approval.providerExecuted),
|
|
1887
|
+
concurrency: toolCallConcurrency,
|
|
1888
|
+
abortSignal: effectiveAbortSignal,
|
|
1889
|
+
execute: async (approval) => {
|
|
1890
|
+
const tool = this.tools[approval.toolName];
|
|
1891
|
+
if (tool && typeof tool.execute === "function") {
|
|
1892
|
+
if (!tool.needsApproval) {
|
|
1893
|
+
const reason = `Tool "${approval.toolName}" does not require approval`;
|
|
1894
|
+
return { modelResult: {
|
|
1895
|
+
type: "tool-result",
|
|
1896
|
+
toolCallId: approval.toolCallId,
|
|
1897
|
+
toolName: approval.toolName,
|
|
1898
|
+
output: await createLanguageModelToolResultOutput({
|
|
1899
|
+
toolCallId: approval.toolCallId,
|
|
1900
|
+
toolName: approval.toolName,
|
|
1901
|
+
input: approval.input,
|
|
1902
|
+
output: reason,
|
|
1903
|
+
tool,
|
|
1904
|
+
errorMode: "text",
|
|
1905
|
+
supportedUrls: {},
|
|
1906
|
+
download: workflowDownload
|
|
1907
|
+
})
|
|
1908
|
+
} };
|
|
1909
|
+
}
|
|
1910
|
+
let revalidationReason;
|
|
1911
|
+
try {
|
|
1912
|
+
await validateWorkflowToolApprovalSignature({
|
|
1913
|
+
secret: effectiveToolApprovalSecret,
|
|
1914
|
+
approvalId: approval.collected.approvalRequest.approvalId,
|
|
1915
|
+
toolCallId: approval.toolCallId,
|
|
1916
|
+
toolName: approval.toolName,
|
|
1917
|
+
input: approval.input,
|
|
1918
|
+
signature: approval.collected.approvalRequest.signature
|
|
1919
|
+
});
|
|
1920
|
+
const { deniedToolApprovals: policyDenied, invalidToolApprovals } = await validateApprovedToolApprovals({
|
|
1921
|
+
approvedToolApprovals: [approval.collected],
|
|
1922
|
+
tools: this.tools,
|
|
1923
|
+
toolApproval: void 0,
|
|
1924
|
+
messages: prompt.messages,
|
|
1925
|
+
toolsContext: effectiveToolsContext,
|
|
1926
|
+
runtimeContext: effectiveRuntimeContext
|
|
1927
|
+
});
|
|
1928
|
+
if (invalidToolApprovals.length > 0) revalidationReason = getErrorMessage(invalidToolApprovals[0].error);
|
|
1929
|
+
else if (policyDenied.length > 0) revalidationReason = policyDenied[0].approvalResponse.reason ?? "Tool approval denied";
|
|
1930
|
+
} catch (error) {
|
|
1931
|
+
revalidationReason = getErrorMessage(error);
|
|
1932
|
+
}
|
|
1933
|
+
if (revalidationReason != null) return { modelResult: {
|
|
1859
1934
|
type: "tool-result",
|
|
1860
1935
|
toolCallId: approval.toolCallId,
|
|
1861
1936
|
toolName: approval.toolName,
|
|
@@ -1863,69 +1938,34 @@ var WorkflowAgent = class {
|
|
|
1863
1938
|
toolCallId: approval.toolCallId,
|
|
1864
1939
|
toolName: approval.toolName,
|
|
1865
1940
|
input: approval.input,
|
|
1866
|
-
output:
|
|
1941
|
+
output: revalidationReason,
|
|
1867
1942
|
tool,
|
|
1868
1943
|
errorMode: "text",
|
|
1869
1944
|
supportedUrls: {},
|
|
1870
|
-
download
|
|
1945
|
+
download: workflowDownload
|
|
1871
1946
|
})
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
}
|
|
1875
|
-
let revalidationReason;
|
|
1876
|
-
try {
|
|
1877
|
-
await validateWorkflowToolApprovalSignature({
|
|
1878
|
-
secret: effectiveToolApprovalSecret,
|
|
1879
|
-
approvalId: approval.collected.approvalRequest.approvalId,
|
|
1947
|
+
} };
|
|
1948
|
+
const result = await executeToolWithCallbacks({
|
|
1880
1949
|
toolCallId: approval.toolCallId,
|
|
1881
1950
|
toolName: approval.toolName,
|
|
1882
|
-
input: approval.input
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
tools: this.tools,
|
|
1888
|
-
toolApproval: void 0,
|
|
1889
|
-
messages: prompt.messages,
|
|
1890
|
-
toolsContext: effectiveToolsContext,
|
|
1891
|
-
runtimeContext: effectiveRuntimeContext
|
|
1892
|
-
});
|
|
1893
|
-
if (invalidToolApprovals.length > 0) revalidationReason = getErrorMessage(invalidToolApprovals[0].error);
|
|
1894
|
-
else if (policyDenied.length > 0) revalidationReason = policyDenied[0].approvalResponse.reason ?? "Tool approval denied";
|
|
1895
|
-
} catch (error) {
|
|
1896
|
-
revalidationReason = getErrorMessage(error);
|
|
1897
|
-
}
|
|
1898
|
-
if (revalidationReason != null) {
|
|
1899
|
-
toolResultContent.push({
|
|
1900
|
-
type: "tool-result",
|
|
1901
|
-
toolCallId: approval.toolCallId,
|
|
1902
|
-
toolName: approval.toolName,
|
|
1903
|
-
output: await createLanguageModelToolResultOutput({
|
|
1951
|
+
input: approval.input
|
|
1952
|
+
}, this.tools, prompt.messages, effectiveToolsContext, 0, sandbox);
|
|
1953
|
+
return {
|
|
1954
|
+
modelResult: result.modelResult,
|
|
1955
|
+
rawResult: {
|
|
1904
1956
|
toolCallId: approval.toolCallId,
|
|
1905
1957
|
toolName: approval.toolName,
|
|
1906
1958
|
input: approval.input,
|
|
1907
|
-
output:
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
supportedUrls: {},
|
|
1911
|
-
download
|
|
1912
|
-
})
|
|
1913
|
-
});
|
|
1914
|
-
continue;
|
|
1959
|
+
output: result.rawOutput
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1915
1962
|
}
|
|
1916
|
-
const result = await executeToolWithCallbacks({
|
|
1917
|
-
toolCallId: approval.toolCallId,
|
|
1918
|
-
toolName: approval.toolName,
|
|
1919
|
-
input: approval.input
|
|
1920
|
-
}, this.tools, prompt.messages, effectiveToolsContext, 0, sandbox);
|
|
1921
|
-
toolResultContent.push(result.modelResult);
|
|
1922
|
-
approvedRawResults.push({
|
|
1923
|
-
toolCallId: approval.toolCallId,
|
|
1924
|
-
toolName: approval.toolName,
|
|
1925
|
-
input: approval.input,
|
|
1926
|
-
output: result.rawOutput
|
|
1927
|
-
});
|
|
1928
1963
|
}
|
|
1964
|
+
});
|
|
1965
|
+
for (const result of approvedResults) {
|
|
1966
|
+
if (result == null) continue;
|
|
1967
|
+
toolResultContent.push(result.modelResult);
|
|
1968
|
+
if (result.rawResult != null) approvedRawResults.push(result.rawResult);
|
|
1929
1969
|
}
|
|
1930
1970
|
for (const denial of deniedToolApprovals) {
|
|
1931
1971
|
if (denial.providerExecuted || denial.existingToolResult !== void 0) continue;
|
|
@@ -1975,7 +2015,7 @@ var WorkflowAgent = class {
|
|
|
1975
2015
|
const modelPrompt = await convertToLanguageModelPrompt({
|
|
1976
2016
|
prompt,
|
|
1977
2017
|
supportedUrls: {},
|
|
1978
|
-
download
|
|
2018
|
+
download: workflowDownload
|
|
1979
2019
|
});
|
|
1980
2020
|
const mergedGenerationSettings = {
|
|
1981
2021
|
...effectiveGenerationSettings,
|
|
@@ -2072,7 +2112,7 @@ var WorkflowAgent = class {
|
|
|
2072
2112
|
const startTime = Date.now();
|
|
2073
2113
|
let result;
|
|
2074
2114
|
try {
|
|
2075
|
-
const execute = () => executeTool(toolCall, tools, messages, resolvedContext, effectiveAbortSignal,
|
|
2115
|
+
const execute = () => executeTool(toolCall, tools, messages, resolvedContext, effectiveAbortSignal, workflowDownload, stepSandbox);
|
|
2076
2116
|
result = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
|
|
2077
2117
|
callId: "workflow-agent",
|
|
2078
2118
|
toolCallId: toolCall.toolCallId,
|
|
@@ -2207,6 +2247,7 @@ var WorkflowAgent = class {
|
|
|
2207
2247
|
includeRawChunks: options.includeRawChunks ?? false,
|
|
2208
2248
|
timeoutAt,
|
|
2209
2249
|
repairToolCall: options.repairToolCall ?? options.experimental_repairToolCall ?? this.repairToolCall,
|
|
2250
|
+
download,
|
|
2210
2251
|
responseFormat: await (options.output ?? this.output)?.responseFormat,
|
|
2211
2252
|
experimental_transform: options.experimental_transform,
|
|
2212
2253
|
experimental_sandbox: sandbox
|
|
@@ -2281,10 +2322,15 @@ var WorkflowAgent = class {
|
|
|
2281
2322
|
});
|
|
2282
2323
|
const providerApprovalRequests = step?.content.filter((part) => part.type === "tool-approval-request").filter((part) => part.toolCall.providerExecuted) ?? [];
|
|
2283
2324
|
if (pausedToolCalls.length > 0 || providerApprovalRequests.length > 0) {
|
|
2284
|
-
const executableResults = await
|
|
2325
|
+
const executableResults = await mapWithConcurrency({
|
|
2326
|
+
items: executableToolCalls,
|
|
2327
|
+
concurrency: toolCallConcurrency,
|
|
2328
|
+
abortSignal: effectiveAbortSignal,
|
|
2329
|
+
execute: (toolCall) => executeToolWithCallbacks(toolCall, stepTools, iterMessages, toolsContext, currentStepNumber, toolExecutionSandbox)
|
|
2330
|
+
});
|
|
2285
2331
|
const providerResultEntries = await Promise.all(providerToolCallsForResults.filter((call) => !providerApprovalRequests.some((request) => request.toolCall.toolCallId === call.toolCallId)).map(async (toolCall) => ({
|
|
2286
2332
|
toolCall,
|
|
2287
|
-
result: await resolveProviderToolResult(toolCall, capturedProviderToolResults, stepTools,
|
|
2333
|
+
result: await resolveProviderToolResult(toolCall, capturedProviderToolResults, stepTools, workflowDownload)
|
|
2288
2334
|
})));
|
|
2289
2335
|
await Promise.all(providerResultEntries.flatMap(({ toolCall, result }) => result == null ? [] : [recordProviderExecutedToolTelemetry(toolCall, result, iterMessages, currentStepNumber)]));
|
|
2290
2336
|
const providerResults = providerResultEntries.flatMap(({ result }) => result == null ? [] : [result]);
|
|
@@ -2379,10 +2425,15 @@ var WorkflowAgent = class {
|
|
|
2379
2425
|
initialResponseMessages
|
|
2380
2426
|
};
|
|
2381
2427
|
}
|
|
2382
|
-
const clientToolResults = await
|
|
2428
|
+
const clientToolResults = await mapWithConcurrency({
|
|
2429
|
+
items: nonProviderToolCalls,
|
|
2430
|
+
concurrency: toolCallConcurrency,
|
|
2431
|
+
abortSignal: effectiveAbortSignal,
|
|
2432
|
+
execute: (toolCall) => executeToolWithCallbacks(toolCall, stepTools, iterMessages, toolsContext, currentStepNumber, toolExecutionSandbox)
|
|
2433
|
+
});
|
|
2383
2434
|
const providerToolResultEntries = await Promise.all(providerToolCallsForResults.map(async (toolCall) => ({
|
|
2384
2435
|
toolCall,
|
|
2385
|
-
result: await resolveProviderToolResult(toolCall, capturedProviderToolResults, stepTools,
|
|
2436
|
+
result: await resolveProviderToolResult(toolCall, capturedProviderToolResults, stepTools, workflowDownload)
|
|
2386
2437
|
})));
|
|
2387
2438
|
await Promise.all(providerToolResultEntries.flatMap(({ toolCall, result }) => result == null ? [] : [recordProviderExecutedToolTelemetry(toolCall, result, iterMessages, currentStepNumber)]));
|
|
2388
2439
|
const providerToolResults = providerToolResultEntries.flatMap(({ result }) => result == null ? [] : [result]);
|