@temporalio/strands-agents 1.24.0 → 2.0.0-rc.1
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/LICENSE +6 -6
- package/README.md +112 -15
- package/lib/empty-module.d.ts +1 -1
- package/lib/empty-module.js +6 -1
- package/lib/empty-module.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +21 -11
- package/lib/index.js.map +1 -1
- package/lib/load-polyfills.js +15 -0
- package/lib/load-polyfills.js.map +1 -1
- package/lib/model-activity.d.ts +57 -2
- package/lib/model-activity.js +100 -6
- package/lib/model-activity.js.map +1 -1
- package/lib/plugin.d.ts +33 -12
- package/lib/plugin.js +127 -26
- package/lib/plugin.js.map +1 -1
- package/lib/strands-errors.d.ts +39 -0
- package/lib/strands-errors.js +130 -0
- package/lib/strands-errors.js.map +1 -0
- package/lib/temporal-activity-tool.d.ts +18 -10
- package/lib/temporal-activity-tool.js +50 -29
- package/lib/temporal-activity-tool.js.map +1 -1
- package/lib/temporal-agent.d.ts +38 -4
- package/lib/temporal-agent.js +68 -16
- package/lib/temporal-agent.js.map +1 -1
- package/lib/temporal-mcp-client.d.ts +113 -17
- package/lib/temporal-mcp-client.js +376 -102
- package/lib/temporal-mcp-client.js.map +1 -1
- package/lib/temporal-mcp-tool.d.ts +3 -1
- package/lib/temporal-mcp-tool.js +26 -16
- package/lib/temporal-mcp-tool.js.map +1 -1
- package/lib/temporal-model.d.ts +32 -0
- package/lib/temporal-model.js +108 -24
- package/lib/temporal-model.js.map +1 -1
- package/lib/workflow.js +17 -7
- package/lib/workflow.js.map +1 -1
- package/package.json +46 -22
- package/src/empty-module.ts +5 -0
- package/src/index.ts +3 -1
- package/src/load-polyfills.ts +20 -1
- package/src/model-activity.ts +153 -8
- package/src/plugin.ts +159 -31
- package/src/strands-errors.ts +147 -0
- package/src/temporal-activity-tool.ts +43 -32
- package/src/temporal-agent.ts +77 -19
- package/src/temporal-mcp-client.ts +407 -91
- package/src/temporal-mcp-tool.ts +9 -9
- package/src/temporal-model.ts +111 -18
- package/lib/failure-converter.d.ts +0 -14
- package/lib/failure-converter.js +0 -61
- package/lib/failure-converter.js.map +0 -1
- package/src/failure-converter.ts +0 -77
package/lib/model-activity.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModelActivity = void 0;
|
|
4
4
|
const sdk_1 = require("@strands-agents/sdk");
|
|
5
|
+
const activity_1 = require("@temporalio/activity");
|
|
6
|
+
const common_1 = require("@temporalio/common");
|
|
5
7
|
const client_1 = require("@temporalio/workflow-streams/client");
|
|
6
8
|
const heartbeat_1 = require("./heartbeat");
|
|
7
9
|
/**
|
|
@@ -27,6 +29,29 @@ function rebuildMessages(messages) {
|
|
|
27
29
|
}
|
|
28
30
|
return messages.map((m) => m instanceof sdk_1.Message ? m : sdk_1.Message.fromMessageData(m));
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Run `model.stream` with the activity's own cancellation signal as `cancelSignal`. Strands passes
|
|
34
|
+
* the agent's `cancelSignal`, an `AbortSignal`, which reaches the activity as a plain object.
|
|
35
|
+
*
|
|
36
|
+
* Once the activity's cancellation reaches the worker, the signal is aborted. That stops the model
|
|
37
|
+
* call only if the model passes `cancelSignal` to its client (Strands 1.19.0's `AnthropicModel`
|
|
38
|
+
* does not); otherwise the call runs on and the activity can complete with its result. A remote
|
|
39
|
+
* activity learns of cancellation only through heartbeats, so this needs a `heartbeatTimeout`,
|
|
40
|
+
* which `TemporalModel` sets to 10 seconds unless the activity options set their own. Model
|
|
41
|
+
* clients abort with their own errors (OpenAI's is named `Error`), which Temporal would record as a
|
|
42
|
+
* failure, so after cancellation the activity throws the signal's `CancelledFailure` instead.
|
|
43
|
+
*/
|
|
44
|
+
async function* streamWithActivityCancellation(model, messages, options) {
|
|
45
|
+
const signal = activity_1.Context.current().cancellationSignal;
|
|
46
|
+
try {
|
|
47
|
+
yield* model.stream(messages, { ...options, cancelSignal: signal });
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
if (signal.aborted)
|
|
51
|
+
throw signal.reason;
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
30
55
|
/**
|
|
31
56
|
* Holds the model factory map and exposes the model activities.
|
|
32
57
|
*
|
|
@@ -35,7 +60,7 @@ function rebuildMessages(messages) {
|
|
|
35
60
|
* default-Bedrock fallback; user-supplied factories force `model: 'name'`
|
|
36
61
|
* on every {@link TemporalAgent}.
|
|
37
62
|
*
|
|
38
|
-
*
|
|
63
|
+
* The model activities heartbeat at half the configured `heartbeatTimeout` via
|
|
39
64
|
* {@link autoHeartbeat} so long model calls don't stall the worker's view
|
|
40
65
|
* of activity liveness.
|
|
41
66
|
*/
|
|
@@ -48,6 +73,8 @@ class ModelActivity {
|
|
|
48
73
|
this.defaultName = defaultName;
|
|
49
74
|
this.invokeModel = (0, heartbeat_1.autoHeartbeat)(this.invokeModel.bind(this));
|
|
50
75
|
this.invokeModelStreaming = (0, heartbeat_1.autoHeartbeat)(this.invokeModelStreaming.bind(this));
|
|
76
|
+
this.invokeStatefulModel = (0, heartbeat_1.autoHeartbeat)(this.invokeStatefulModel.bind(this));
|
|
77
|
+
this.invokeStatefulModelStreaming = (0, heartbeat_1.autoHeartbeat)(this.invokeStatefulModelStreaming.bind(this));
|
|
51
78
|
}
|
|
52
79
|
getModel(name) {
|
|
53
80
|
const resolved = name ?? this.defaultName;
|
|
@@ -67,17 +94,66 @@ class ModelActivity {
|
|
|
67
94
|
}
|
|
68
95
|
return model;
|
|
69
96
|
}
|
|
70
|
-
async
|
|
97
|
+
async getModelConfig(input) {
|
|
71
98
|
const model = this.getModel(input.modelName);
|
|
99
|
+
const { modelId, contextWindowLimit } = model.getConfig();
|
|
100
|
+
return { modelId, contextWindowLimit, stateful: model.stateful };
|
|
101
|
+
}
|
|
102
|
+
async invokeModel(input) {
|
|
103
|
+
return this.runModel(this.getStatelessModel(input.modelName), input);
|
|
104
|
+
}
|
|
105
|
+
async invokeModelStreaming(input) {
|
|
106
|
+
return this.runModelStreaming(this.getStatelessModel(input.modelName), input);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The model for a stateless call. A stateful model cannot run here without the agent's model
|
|
110
|
+
* state, and retrying does not bring it: the workflow chose this activity because its config
|
|
111
|
+
* read had no stateful flag, from a worker without stateful support or from a model that became
|
|
112
|
+
* stateful later, or because `TemporalModel` runs without `TemporalAgent` and never read the
|
|
113
|
+
* config.
|
|
114
|
+
*/
|
|
115
|
+
getStatelessModel(name) {
|
|
116
|
+
const model = this.getModel(name);
|
|
117
|
+
if (model.stateful) {
|
|
118
|
+
throw common_1.ApplicationFailure.create({
|
|
119
|
+
type: 'StatefulModelOnStatelessPath',
|
|
120
|
+
nonRetryable: true,
|
|
121
|
+
message: `The worker model ${JSON.stringify(name ?? this.defaultName)} is stateful, but the workflow ` +
|
|
122
|
+
`called it without its model state. Its config was read from a worker without stateful ` +
|
|
123
|
+
`support, the worker model became stateful after the run read its config, or ` +
|
|
124
|
+
`TemporalModel runs without TemporalAgent and did not read it. Reset or terminate the run.`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return model;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The model for a stateful call. A model that is no longer stateful ignores the model state, and
|
|
131
|
+
* the agent, which read a stateful config, clears its messages after each turn, so the model
|
|
132
|
+
* would see only each turn's new message: the worker model became stateless after the run read
|
|
133
|
+
* its config.
|
|
134
|
+
*/
|
|
135
|
+
getStatefulModel(name) {
|
|
136
|
+
const model = this.getModel(name);
|
|
137
|
+
if (!model.stateful) {
|
|
138
|
+
throw common_1.ApplicationFailure.create({
|
|
139
|
+
type: 'StatelessModelOnStatefulPath',
|
|
140
|
+
nonRetryable: true,
|
|
141
|
+
message: `The worker model ${JSON.stringify(name ?? this.defaultName)} is not stateful, but the run ` +
|
|
142
|
+
`read a stateful config, so its agent does not keep the messages this model needs. The ` +
|
|
143
|
+
`worker model became stateless after the run read its config. Reset or terminate the run.`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return model;
|
|
147
|
+
}
|
|
148
|
+
async runModel(model, input) {
|
|
72
149
|
const messages = rebuildMessages(input.messages);
|
|
73
150
|
const events = [];
|
|
74
|
-
for await (const event of model
|
|
151
|
+
for await (const event of streamWithActivityCancellation(model, messages, input.options)) {
|
|
75
152
|
events.push(event);
|
|
76
153
|
}
|
|
77
154
|
return events;
|
|
78
155
|
}
|
|
79
|
-
async
|
|
80
|
-
const model = this.getModel(input.modelName);
|
|
156
|
+
async runModelStreaming(model, input) {
|
|
81
157
|
const messages = rebuildMessages(input.messages);
|
|
82
158
|
const stream = client_1.WorkflowStreamClient.fromWithinActivity({
|
|
83
159
|
batchInterval: input.streamingBatchInterval,
|
|
@@ -85,7 +161,7 @@ class ModelActivity {
|
|
|
85
161
|
const topic = stream.topic(input.streamingTopic);
|
|
86
162
|
const events = [];
|
|
87
163
|
try {
|
|
88
|
-
for await (const event of model
|
|
164
|
+
for await (const event of streamWithActivityCancellation(model, messages, input.options)) {
|
|
89
165
|
events.push(event);
|
|
90
166
|
topic.publish(event);
|
|
91
167
|
}
|
|
@@ -95,6 +171,24 @@ class ModelActivity {
|
|
|
95
171
|
}
|
|
96
172
|
return events;
|
|
97
173
|
}
|
|
174
|
+
// Stateful calls use their own activity types. A worker without stateful support does not
|
|
175
|
+
// register them, so it cannot take such a call, drop the model state and return no updated state
|
|
176
|
+
// while the agent clears its messages: the call fails there and is retried until a worker with
|
|
177
|
+
// stateful support takes it.
|
|
178
|
+
/** Run a stateful model with the agent's model state; return its events and the updated state. */
|
|
179
|
+
async invokeStatefulModel(input) {
|
|
180
|
+
const modelState = new sdk_1.StateStore(input.modelState);
|
|
181
|
+
const model = this.getStatefulModel(input.modelName);
|
|
182
|
+
const events = await this.runModel(model, { ...input, options: { ...input.options, modelState } });
|
|
183
|
+
return { events, modelState: modelState.getAll() };
|
|
184
|
+
}
|
|
185
|
+
/** As {@link invokeStatefulModel}, publishing each event as {@link invokeModelStreaming} does. */
|
|
186
|
+
async invokeStatefulModelStreaming(input) {
|
|
187
|
+
const modelState = new sdk_1.StateStore(input.modelState);
|
|
188
|
+
const model = this.getStatefulModel(input.modelName);
|
|
189
|
+
const events = await this.runModelStreaming(model, { ...input, options: { ...input.options, modelState } });
|
|
190
|
+
return { events, modelState: modelState.getAll() };
|
|
191
|
+
}
|
|
98
192
|
}
|
|
99
193
|
exports.ModelActivity = ModelActivity;
|
|
100
194
|
//# sourceMappingURL=model-activity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-activity.js","sourceRoot":"","sources":["../src/model-activity.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"model-activity.js","sourceRoot":"","sources":["../src/model-activity.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE1D,mDAA+C;AAC/C,+CAAwD;AACxD,gEAA2E;AAE3E,2CAA4C;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,eAAe,CAAC,QAAiB;IACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACxB,CAAC,YAAY,aAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAO,CAAC,eAAe,CAAC,CAAkD,CAAC,CACvG,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,SAAS,CAAC,CAAC,8BAA8B,CAC5C,KAAY,EACZ,QAAmB,EACnB,OAAuB;IAEvB,MAAM,MAAM,GAAG,kBAAO,CAAC,OAAO,EAAE,CAAC,kBAAkB,CAAC;IACpD,IAAI,CAAC;QACH,KAAK,CAAC,CAAC,KAAK,CA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,CAAC;IAED,kGAAkG;IAClG,KAAK,CAAC,4BAA4B,CAAC,KAAwC;QACzE,MAAM,UAAU,GAAG,IAAI,gBAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QAC5G,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;IACrD,CAAC;CACF;AA3ID,sCA2IC"}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { McpClient } from '@strands-agents/sdk';
|
|
2
2
|
import { type Model } from '@strands-agents/sdk';
|
|
3
3
|
import type { Duration } from '@temporalio/common';
|
|
4
|
-
import type { BundleOptions } from '@temporalio/worker';
|
|
4
|
+
import type { BundleOptions, Worker, WorkerOptions } from '@temporalio/worker';
|
|
5
5
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
6
6
|
/**
|
|
7
7
|
* Options for {@link StrandsPlugin}.
|
|
@@ -15,13 +15,14 @@ import { SimplePlugin } from '@temporalio/plugin';
|
|
|
15
15
|
* - `mcpClients` — name → MCP client factory map. Workflow-side
|
|
16
16
|
* `TemporalMCPClient({ server: 'name' })` selects a factory by name; the
|
|
17
17
|
* per-server `{name}-listTools` and `{name}-callTool` activities reuse one
|
|
18
|
-
* lazily-opened
|
|
18
|
+
* lazily-opened connection, which belongs to this plugin instance and closes
|
|
19
|
+
* when the last worker using the plugin stops. Tools are enumerated live on each
|
|
19
20
|
* `listTools`. By default (`TemporalMCPClient`'s `cacheTools: false`) the
|
|
20
21
|
* agent re-lists on each turn, so it picks up MCP-server changes (including
|
|
21
22
|
* redeploys) mid-workflow without restarting the worker; set `cacheTools:
|
|
22
23
|
* true` to list once at the start of the workflow instead.
|
|
23
24
|
*
|
|
24
|
-
* - `mcpConnectionIdleTimeout` — how long
|
|
25
|
+
* - `mcpConnectionIdleTimeout` — how long an idle MCP connection is
|
|
25
26
|
* kept open between `callTool` activities before it's disconnected. The window
|
|
26
27
|
* only starts once no activity is using the connection, so it never cuts off
|
|
27
28
|
* an in-flight call, however long it runs. Accepts a millisecond number or a
|
|
@@ -39,17 +40,32 @@ export interface StrandsPluginOptions {
|
|
|
39
40
|
* are routed through Temporal Activities for durable execution, retries, and
|
|
40
41
|
* timeouts.
|
|
41
42
|
*
|
|
42
|
-
* Register on the worker
|
|
43
|
-
* interrupts, so the client-side data converter picks up the failure
|
|
44
|
-
* converter):
|
|
43
|
+
* Register on the worker:
|
|
45
44
|
*
|
|
46
45
|
* ```ts
|
|
47
|
-
* const client = await Client.connect({ plugins: [new StrandsPlugin({...})] });
|
|
48
46
|
* const worker = new Worker({ ..., plugins: [new StrandsPlugin({...})] });
|
|
49
47
|
* ```
|
|
50
48
|
*/
|
|
51
49
|
export declare class StrandsPlugin extends SimplePlugin {
|
|
50
|
+
/** The package version, reported in worker heartbeats. */
|
|
51
|
+
readonly version: string;
|
|
52
52
|
constructor(options?: StrandsPluginOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Adds the model and MCP Activities to the Worker.
|
|
55
|
+
*
|
|
56
|
+
* @throws TypeError if the Worker already has a different Activity with one of these names: a
|
|
57
|
+
* caller Activity, another integration's Activity, or one from a `StrandsPlugin` that doesn't share
|
|
58
|
+
* this one's `models` object, MCP client factories and idle timeout.
|
|
59
|
+
*/
|
|
60
|
+
configureWorker(options: WorkerOptions): WorkerOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Runs the Worker.
|
|
63
|
+
*
|
|
64
|
+
* @throws TypeError, before the Worker polls, if a plugin applied after this one replaced one of
|
|
65
|
+
* its Activities with a different one. `Worker.create` applies the Worker's plugins in order, then
|
|
66
|
+
* the `NativeConnection`'s.
|
|
67
|
+
*/
|
|
68
|
+
runWorker(worker: Worker, next: (worker: Worker) => Promise<void>): Promise<void>;
|
|
53
69
|
/**
|
|
54
70
|
* Extend the bundler config so workflow code can bundle `@strands-agents/sdk`:
|
|
55
71
|
*
|
|
@@ -62,18 +78,23 @@ export declare class StrandsPlugin extends SimplePlugin {
|
|
|
62
78
|
* `@google/genai`, `ai`). The workers constructs models worker-side;
|
|
63
79
|
* workflow code only goes through {@link TemporalModel}.
|
|
64
80
|
* - `@aws-sdk/client-s3`, dynamically imported by the SDK's S3-backed
|
|
65
|
-
* `context-offloader` vended plugin
|
|
66
|
-
*
|
|
81
|
+
* `context-offloader` vended plugin. The offloader can run in workflows
|
|
82
|
+
* with in-memory storage; S3 I/O must run in Activities.
|
|
83
|
+
* - `@aws-sdk/client-s3vectors`, dynamically imported by the SDK's
|
|
84
|
+
* `S3VectorSearchStrategy`, which `S3Storage` imports.
|
|
67
85
|
* - `@temporalio/activity` and `@temporalio/client`, which the
|
|
68
86
|
* worker-only halves of {@link TemporalMCPClient}, {@link autoHeartbeat},
|
|
69
87
|
* and `@temporalio/workflow-streams/client` import.
|
|
70
88
|
* - `path` / `crypto`, pulled in transitively by the same worker-only code.
|
|
89
|
+
* - `node:crypto`, dynamically imported by `LocalFileStorage` through the
|
|
90
|
+
* unified storage entrypoint. In-memory storage does not use it.
|
|
71
91
|
*
|
|
72
92
|
* - Replace the dynamic-imported MCP transport helpers
|
|
73
93
|
* (`@modelcontextprotocol/sdk/client/{stdio,sse,streamableHttp}.js` and
|
|
74
|
-
* their `node:*` dependencies, plus `eventsource
|
|
75
|
-
* `
|
|
76
|
-
*
|
|
94
|
+
* their `node:*` dependencies, plus `eventsource` and
|
|
95
|
+
* `eventsource-parser/stream`) with a stub module. MCP v2 bundles its
|
|
96
|
+
* transports into the client entrypoint, so their static EventSource
|
|
97
|
+
* imports must also be stubbed. Transport I/O only runs worker-side.
|
|
77
98
|
*
|
|
78
99
|
* - Inline async chunks so the bundle stays a single file — webpack's
|
|
79
100
|
* default JSONP chunk loader references `self`/`document`, neither of
|
package/lib/plugin.js
CHANGED
|
@@ -4,24 +4,66 @@ exports.StrandsPlugin = void 0;
|
|
|
4
4
|
const sdk_1 = require("@strands-agents/sdk");
|
|
5
5
|
const time_1 = require("@temporalio/common/lib/time");
|
|
6
6
|
const plugin_1 = require("@temporalio/plugin");
|
|
7
|
+
const strands_errors_1 = require("./strands-errors");
|
|
7
8
|
const model_activity_1 = require("./model-activity");
|
|
9
|
+
const temporal_model_1 = require("./temporal-model");
|
|
8
10
|
const temporal_mcp_client_1 = require("./temporal-mcp-client");
|
|
11
|
+
// What each Activity a StrandsPlugin builds was built from: its name, then what it depends on.
|
|
12
|
+
// configureWorker lets one of these replace another with the same entries: that is the same
|
|
13
|
+
// instance, or one built from the same options, registered twice (e.g. on the NativeConnection
|
|
14
|
+
// and the Worker).
|
|
15
|
+
const activitySources = new WeakMap();
|
|
16
|
+
function sameSources(a, b) {
|
|
17
|
+
const x = activitySources.get(a);
|
|
18
|
+
const y = activitySources.get(b);
|
|
19
|
+
return x !== undefined && y !== undefined && x.length === y.length && x.every((v, i) => v === y[i]);
|
|
20
|
+
}
|
|
21
|
+
const REMEDY = 'Rename or remove the other Activity, run the other integration on its own Worker and task queue, ' +
|
|
22
|
+
'or use one StrandsPlugin instance on this Worker.';
|
|
23
|
+
/** The plugin's model activities, whose context overflows the agent recovers from. */
|
|
24
|
+
const MODEL_ACTIVITIES = new Set(['invokeModel', 'invokeModelStreaming']);
|
|
25
|
+
/**
|
|
26
|
+
* Rethrows Strands' interrupt and terminal errors from activities as typed, non-retryable
|
|
27
|
+
* failures. The worker turns any other error an activity throws into a retryable
|
|
28
|
+
* `ApplicationFailure` before a failure converter sees it, so this cannot be left to one.
|
|
29
|
+
*/
|
|
30
|
+
function strandsActivityInbound(ctx) {
|
|
31
|
+
return {
|
|
32
|
+
async execute(input, next) {
|
|
33
|
+
try {
|
|
34
|
+
return await next(input);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw (0, strands_errors_1.rewriteError)(err, { benignOverflow: MODEL_ACTIVITIES.has(ctx.info.activityType) });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Reads this package's version, which worker heartbeats report. Empty if it can't be read. */
|
|
43
|
+
function packageVersion() {
|
|
44
|
+
try {
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
46
|
+
return require('../package.json').version ?? '';
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
9
52
|
/**
|
|
10
53
|
* Temporal plugin that runs Strands Agents inside Temporal workflows. Model,
|
|
11
54
|
* MCP tool, and (via {@link workflow.activityAsTool}) custom-tool invocations
|
|
12
55
|
* are routed through Temporal Activities for durable execution, retries, and
|
|
13
56
|
* timeouts.
|
|
14
57
|
*
|
|
15
|
-
* Register on the worker
|
|
16
|
-
* interrupts, so the client-side data converter picks up the failure
|
|
17
|
-
* converter):
|
|
58
|
+
* Register on the worker:
|
|
18
59
|
*
|
|
19
60
|
* ```ts
|
|
20
|
-
* const client = await Client.connect({ plugins: [new StrandsPlugin({...})] });
|
|
21
61
|
* const worker = new Worker({ ..., plugins: [new StrandsPlugin({...})] });
|
|
22
62
|
* ```
|
|
23
63
|
*/
|
|
24
64
|
class StrandsPlugin extends plugin_1.SimplePlugin {
|
|
65
|
+
/** The package version, reported in worker heartbeats. */
|
|
66
|
+
version = packageVersion();
|
|
25
67
|
constructor(options = {}) {
|
|
26
68
|
let modelFactories = options.models;
|
|
27
69
|
let defaultName;
|
|
@@ -39,34 +81,87 @@ class StrandsPlugin extends plugin_1.SimplePlugin {
|
|
|
39
81
|
const activities = {
|
|
40
82
|
invokeModel: (input) => modelActivity.invokeModel(input),
|
|
41
83
|
invokeModelStreaming: (input) => modelActivity.invokeModelStreaming(input),
|
|
84
|
+
[temporal_model_1.INVOKE_STATEFUL_MODEL_ACTIVITY]: (input) => modelActivity.invokeStatefulModel(input),
|
|
85
|
+
[temporal_model_1.INVOKE_STATEFUL_MODEL_STREAMING_ACTIVITY]: (input) => modelActivity.invokeStatefulModelStreaming(input),
|
|
86
|
+
[temporal_model_1.GET_MODEL_CONFIG_ACTIVITY]: (input) => modelActivity.getModelConfig(input),
|
|
42
87
|
};
|
|
88
|
+
// Without `models`, every plugin builds the same default.
|
|
89
|
+
const modelSources = options.models === undefined ? [] : [options.models, defaultName];
|
|
90
|
+
for (const [name, fn] of Object.entries(activities)) {
|
|
91
|
+
activitySources.set(fn, [name, ...modelSources]);
|
|
92
|
+
}
|
|
43
93
|
const mcpClients = options.mcpClients ?? {};
|
|
44
94
|
const idleMs = (0, time_1.msOptionalToNumber)(options.mcpConnectionIdleTimeout);
|
|
95
|
+
// This plugin's own MCP connections: the Workers that share this instance share
|
|
96
|
+
// them, and another StrandsPlugin opens its own, even for the same server name.
|
|
97
|
+
const connections = new temporal_mcp_client_1.McpConnections(idleMs);
|
|
45
98
|
for (const [server, factory] of Object.entries(mcpClients)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const runContext = async (next) => {
|
|
50
|
-
try {
|
|
51
|
-
await next();
|
|
99
|
+
// Fail when the Worker is built, not in every MCP Activity.
|
|
100
|
+
if (typeof factory !== 'function') {
|
|
101
|
+
throw new TypeError(`MCP client factory '${server}' is ${(0, temporal_mcp_client_1.describeValue)(factory)}, not a function.`);
|
|
52
102
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
103
|
+
const serverActivities = {
|
|
104
|
+
[(0, temporal_mcp_client_1.listToolsActivityName)(server)]: (0, temporal_mcp_client_1.buildListToolsActivity)(server, factory, connections),
|
|
105
|
+
[(0, temporal_mcp_client_1.callToolActivityName)(server)]: (0, temporal_mcp_client_1.buildCallToolActivity)(server, factory, connections),
|
|
106
|
+
};
|
|
107
|
+
for (const [name, fn] of Object.entries(serverActivities)) {
|
|
108
|
+
activities[name] = fn;
|
|
109
|
+
activitySources.set(fn, [name, factory, idleMs ?? temporal_mcp_client_1.MCP_CONNECTION_IDLE_MS]);
|
|
59
110
|
}
|
|
60
|
-
}
|
|
111
|
+
}
|
|
112
|
+
// Closes the MCP connections once the last Worker using this plugin stops.
|
|
113
|
+
const runContext = (next) => connections.use(next);
|
|
61
114
|
super({
|
|
62
115
|
name: 'StrandsPlugin',
|
|
63
116
|
activities,
|
|
64
117
|
runContext,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
118
|
+
// A function, because the object form rebuilds the worker's interceptors without the
|
|
119
|
+
// deprecated `activityInbound` key.
|
|
120
|
+
workerInterceptors: (existing) => ({
|
|
121
|
+
...existing,
|
|
122
|
+
activity: [...(existing?.activity ?? []), (ctx) => ({ inbound: strandsActivityInbound(ctx) })],
|
|
123
|
+
}),
|
|
68
124
|
});
|
|
69
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Adds the model and MCP Activities to the Worker.
|
|
128
|
+
*
|
|
129
|
+
* @throws TypeError if the Worker already has a different Activity with one of these names: a
|
|
130
|
+
* caller Activity, another integration's Activity, or one from a `StrandsPlugin` that doesn't share
|
|
131
|
+
* this one's `models` object, MCP client factories and idle timeout.
|
|
132
|
+
*/
|
|
133
|
+
configureWorker(options) {
|
|
134
|
+
const existing = options.activities;
|
|
135
|
+
for (const [name, fn] of Object.entries(this.options.activities)) {
|
|
136
|
+
const other = existing && Object.prototype.propertyIsEnumerable.call(existing, name) ? existing[name] : undefined;
|
|
137
|
+
if (typeof other === 'function' && other !== fn && !sameSources(other, fn)) {
|
|
138
|
+
throw new TypeError(`Duplicate registration of Activity '${name}': StrandsPlugin would replace a different Activity ` +
|
|
139
|
+
`with this name. ${REMEDY}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return super.configureWorker(options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Runs the Worker.
|
|
146
|
+
*
|
|
147
|
+
* @throws TypeError, before the Worker polls, if a plugin applied after this one replaced one of
|
|
148
|
+
* its Activities with a different one. `Worker.create` applies the Worker's plugins in order, then
|
|
149
|
+
* the `NativeConnection`'s.
|
|
150
|
+
*/
|
|
151
|
+
async runWorker(worker, next) {
|
|
152
|
+
for (const [name, fn] of Object.entries(this.options.activities)) {
|
|
153
|
+
const kept = worker.options.activities.get(name);
|
|
154
|
+
if (kept === undefined || kept === fn || sameSources(kept, fn))
|
|
155
|
+
continue;
|
|
156
|
+
// There is no public way to stop a Worker that has not run yet. Stopping it first means it
|
|
157
|
+
// never polls; `next` then releases it as `run()` does, so `connection.close()` still works.
|
|
158
|
+
worker.nativeWorker.initiateShutdown();
|
|
159
|
+
await next(worker).catch(() => undefined);
|
|
160
|
+
throw new TypeError(`Duplicate registration of Activity '${name}': a plugin applied after StrandsPlugin replaced its ` +
|
|
161
|
+
`Activity with this name. ${REMEDY}`);
|
|
162
|
+
}
|
|
163
|
+
return super.runWorker(worker, next);
|
|
164
|
+
}
|
|
70
165
|
/**
|
|
71
166
|
* Extend the bundler config so workflow code can bundle `@strands-agents/sdk`:
|
|
72
167
|
*
|
|
@@ -79,18 +174,23 @@ class StrandsPlugin extends plugin_1.SimplePlugin {
|
|
|
79
174
|
* `@google/genai`, `ai`). The workers constructs models worker-side;
|
|
80
175
|
* workflow code only goes through {@link TemporalModel}.
|
|
81
176
|
* - `@aws-sdk/client-s3`, dynamically imported by the SDK's S3-backed
|
|
82
|
-
* `context-offloader` vended plugin
|
|
83
|
-
*
|
|
177
|
+
* `context-offloader` vended plugin. The offloader can run in workflows
|
|
178
|
+
* with in-memory storage; S3 I/O must run in Activities.
|
|
179
|
+
* - `@aws-sdk/client-s3vectors`, dynamically imported by the SDK's
|
|
180
|
+
* `S3VectorSearchStrategy`, which `S3Storage` imports.
|
|
84
181
|
* - `@temporalio/activity` and `@temporalio/client`, which the
|
|
85
182
|
* worker-only halves of {@link TemporalMCPClient}, {@link autoHeartbeat},
|
|
86
183
|
* and `@temporalio/workflow-streams/client` import.
|
|
87
184
|
* - `path` / `crypto`, pulled in transitively by the same worker-only code.
|
|
185
|
+
* - `node:crypto`, dynamically imported by `LocalFileStorage` through the
|
|
186
|
+
* unified storage entrypoint. In-memory storage does not use it.
|
|
88
187
|
*
|
|
89
188
|
* - Replace the dynamic-imported MCP transport helpers
|
|
90
189
|
* (`@modelcontextprotocol/sdk/client/{stdio,sse,streamableHttp}.js` and
|
|
91
|
-
* their `node:*` dependencies, plus `eventsource
|
|
92
|
-
* `
|
|
93
|
-
*
|
|
190
|
+
* their `node:*` dependencies, plus `eventsource` and
|
|
191
|
+
* `eventsource-parser/stream`) with a stub module. MCP v2 bundles its
|
|
192
|
+
* transports into the client entrypoint, so their static EventSource
|
|
193
|
+
* imports must also be stubbed. Transport I/O only runs worker-side.
|
|
94
194
|
*
|
|
95
195
|
* - Inline async chunks so the bundle stays a single file — webpack's
|
|
96
196
|
* default JSONP chunk loader references `self`/`document`, neither of
|
|
@@ -108,6 +208,7 @@ class StrandsPlugin extends plugin_1.SimplePlugin {
|
|
|
108
208
|
'@temporalio/client',
|
|
109
209
|
'@aws-sdk/client-bedrock-runtime',
|
|
110
210
|
'@aws-sdk/client-s3',
|
|
211
|
+
'@aws-sdk/client-s3vectors',
|
|
111
212
|
'@aws-sdk/middleware-websocket',
|
|
112
213
|
'@anthropic-ai/sdk',
|
|
113
214
|
'openai',
|
|
@@ -143,7 +244,7 @@ exports.StrandsPlugin = StrandsPlugin;
|
|
|
143
244
|
*/
|
|
144
245
|
function emptyModuleRewritesPlugin() {
|
|
145
246
|
const empty = require.resolve('./empty-module');
|
|
146
|
-
const ignorePattern = /^(?:node:(?:fs\/promises|os|path|process|stream)|@modelcontextprotocol\/sdk\/client\/(?:stdio|sse|streamableHttp)\.js|eventsource-parser\/stream)$/;
|
|
247
|
+
const ignorePattern = /^(?:node:(?:crypto|fs\/promises|os|path|process|stream)|@modelcontextprotocol\/sdk\/client\/(?:stdio|sse|streamableHttp)\.js|eventsource|eventsource-parser\/stream)$/;
|
|
147
248
|
return {
|
|
148
249
|
apply(compiler) {
|
|
149
250
|
const { NormalModuleReplacementPlugin } = compiler.webpack;
|
package/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AACA,6CAA+D;AAE/D,sDAAiE;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AACA,6CAA+D;AAE/D,sDAAiE;AAGjE,+CAAkD;AAClD,qDAAgD;AAChD,qDAAiD;AAQjD,qDAI0B;AAC1B,+DAQ+B;AAE/B,+FAA+F;AAC/F,4FAA4F;AAC5F,+FAA+F;AAC/F,mBAAmB;AACnB,MAAM,eAAe,GAAG,IAAI,OAAO,EAA8B,CAAC;AAElE,SAAS,WAAW,CAAC,CAAS,EAAE,CAAS;IACvC,MAAM,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC;AAED,MAAM,MAAM,GACV,mGAAmG;IACnG,mDAAmD,CAAC;AAkCtD,sFAAsF;AACtF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAE1E;;;;GAIG;AAC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,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC9C,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AApLD,sCAoLC;AAsBD;;;;;;;;;;;GAWG;AACH,SAAS,yBAAyB;IAChC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAChD,MAAM,aAAa,GACjB,uKAAuK,CAAC;IAC1K,OAAO;QACL,KAAK,CAAC,QAAQ;YACZ,MAAM,EAAE,6BAA6B,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;YAC3D,IAAI,6BAA6B,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,EAAE;gBAC5D,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const STRANDS_INTERRUPT_TYPE = "StrandsInterrupt";
|
|
2
|
+
/** The failure type of an interrupt an activity threw that the plugin cannot read. */
|
|
3
|
+
export declare const STRANDS_MALFORMED_INTERRUPT_TYPE = "StrandsMalformedInterrupt";
|
|
4
|
+
/** The failure type of a Strands context overflow, from the model activity to `TemporalModel`. */
|
|
5
|
+
export declare const CONTEXT_WINDOW_OVERFLOW_TYPE = "ContextWindowOverflowError";
|
|
6
|
+
/** What each entry in a `StrandsInterrupt` failure's details holds. */
|
|
7
|
+
export interface InterruptDetails {
|
|
8
|
+
id?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
reason?: unknown;
|
|
11
|
+
response?: unknown;
|
|
12
|
+
source?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Rewrite an error an activity threw. A Strands interrupt becomes a typed,
|
|
16
|
+
* non-retryable failure that the worker treats as benign, and a malformed one a
|
|
17
|
+
* non-retryable failure of type {@link STRANDS_MALFORMED_INTERRUPT_TYPE}. A
|
|
18
|
+
* Strands terminal model error becomes a typed, non-retryable failure, benign
|
|
19
|
+
* for a context overflow when `benignOverflow` is set. Each keeps the error's
|
|
20
|
+
* stack and cause. Any other value is returned as it is.
|
|
21
|
+
*/
|
|
22
|
+
export declare function rewriteError(err: unknown, options?: {
|
|
23
|
+
benignOverflow?: boolean;
|
|
24
|
+
}): unknown;
|
|
25
|
+
/**
|
|
26
|
+
* The error a `TemporalAgent` turn ends with in workflow code, in place of one
|
|
27
|
+
* that would only fail the workflow task on every attempt. A Strands terminal
|
|
28
|
+
* model error becomes a typed, non-retryable failure with the original error as
|
|
29
|
+
* its cause. A Strands `ModelError` that wraps a Temporal failure, such as a
|
|
30
|
+
* model activity that failed or was cancelled, becomes that failure, so the run
|
|
31
|
+
* fails or is cancelled. Any other value is returned as it is.
|
|
32
|
+
*/
|
|
33
|
+
export declare function workflowErrorFor(err: unknown): unknown;
|
|
34
|
+
/**
|
|
35
|
+
* The application failure type of a decoded failure. It also reads the type from
|
|
36
|
+
* the failure's proto when the failure converter returned another kind of
|
|
37
|
+
* `TemporalFailure`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function applicationFailureType(failure: unknown): string | undefined;
|