@strands-agents/sdk 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/agent/agent.d.ts +22 -42
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +73 -426
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/context-manager/modes/agentic/agentic-context.d.ts +2 -2
- package/dist/src/errors.d.ts +15 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +18 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/events.d.ts +5 -4
- package/dist/src/hooks/events.d.ts.map +1 -1
- package/dist/src/hooks/events.js +3 -3
- package/dist/src/hooks/events.js.map +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.node.d.ts.map +1 -1
- package/dist/src/index.node.js +2 -6
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/middleware/interrupt.d.ts +18 -0
- package/dist/src/middleware/interrupt.d.ts.map +1 -0
- package/dist/src/middleware/interrupt.js +33 -0
- package/dist/src/middleware/interrupt.js.map +1 -0
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +23 -1
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/openai/errors.d.ts.map +1 -1
- package/dist/src/models/openai/errors.js +1 -0
- package/dist/src/models/openai/errors.js.map +1 -1
- package/dist/src/models/openai/mantle.d.ts +8 -3
- package/dist/src/models/openai/mantle.d.ts.map +1 -1
- package/dist/src/models/openai/mantle.js +41 -6
- package/dist/src/models/openai/mantle.js.map +1 -1
- package/dist/src/models/openai/model.d.ts.map +1 -1
- package/dist/src/models/openai/model.js +4 -3
- package/dist/src/models/openai/model.js.map +1 -1
- package/dist/src/models/openai/responses-adapter.d.ts.map +1 -1
- package/dist/src/models/openai/responses-adapter.js +41 -9
- package/dist/src/models/openai/responses-adapter.js.map +1 -1
- package/dist/src/models/vercel.d.ts.map +1 -1
- package/dist/src/models/vercel.js +28 -1
- package/dist/src/models/vercel.js.map +1 -1
- package/dist/src/multiagent/graph.d.ts.map +1 -1
- package/dist/src/multiagent/graph.js +1 -1
- package/dist/src/multiagent/graph.js.map +1 -1
- package/dist/src/{multiagent/queue.d.ts → queue.d.ts} +12 -27
- package/dist/src/queue.d.ts.map +1 -0
- package/dist/src/{multiagent/queue.js → queue.js} +4 -2
- package/dist/src/queue.js.map +1 -0
- package/dist/src/register-node-defaults.d.ts +3 -0
- package/dist/src/register-node-defaults.d.ts.map +1 -0
- package/dist/src/register-node-defaults.js +10 -0
- package/dist/src/register-node-defaults.js.map +1 -0
- package/dist/src/sandbox/register-node-defaults.d.ts +3 -0
- package/dist/src/sandbox/register-node-defaults.d.ts.map +1 -0
- package/dist/src/sandbox/register-node-defaults.js +8 -0
- package/dist/src/sandbox/register-node-defaults.js.map +1 -0
- package/dist/src/session/file-storage.d.ts +3 -0
- package/dist/src/session/file-storage.d.ts.map +1 -1
- package/dist/src/session/file-storage.js +3 -0
- package/dist/src/session/file-storage.js.map +1 -1
- package/dist/src/session/s3-storage.d.ts +3 -0
- package/dist/src/session/s3-storage.d.ts.map +1 -1
- package/dist/src/session/s3-storage.js +3 -0
- package/dist/src/session/s3-storage.js.map +1 -1
- package/dist/src/session/session-manager.d.ts +11 -2
- package/dist/src/session/session-manager.d.ts.map +1 -1
- package/dist/src/session/session-manager.js +19 -8
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/session/snapshot-storage-adapter.d.ts +93 -0
- package/dist/src/session/snapshot-storage-adapter.d.ts.map +1 -0
- package/dist/src/session/snapshot-storage-adapter.js +157 -0
- package/dist/src/session/snapshot-storage-adapter.js.map +1 -0
- package/dist/src/session/storage.d.ts +3 -6
- package/dist/src/session/storage.d.ts.map +1 -1
- package/dist/src/storage/in-memory-storage.d.ts +64 -0
- package/dist/src/storage/in-memory-storage.d.ts.map +1 -0
- package/dist/src/storage/in-memory-storage.js +85 -0
- package/dist/src/storage/in-memory-storage.js.map +1 -0
- package/dist/src/storage/index.d.ts +20 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +18 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/local-file-storage.d.ts +81 -0
- package/dist/src/storage/local-file-storage.d.ts.map +1 -0
- package/dist/src/storage/local-file-storage.js +244 -0
- package/dist/src/storage/local-file-storage.js.map +1 -0
- package/dist/src/storage/s3-storage.d.ts +73 -0
- package/dist/src/storage/s3-storage.d.ts.map +1 -0
- package/dist/src/storage/s3-storage.js +146 -0
- package/dist/src/storage/s3-storage.js.map +1 -0
- package/dist/src/storage/storage.d.ts +102 -0
- package/dist/src/storage/storage.d.ts.map +1 -0
- package/dist/src/storage/storage.js +68 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/telemetry/tracer.d.ts +18 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -1
- package/dist/src/telemetry/tracer.js +31 -11
- package/dist/src/telemetry/tracer.js.map +1 -1
- package/dist/src/tools/executors/concurrent.d.ts +32 -0
- package/dist/src/tools/executors/concurrent.d.ts.map +1 -0
- package/dist/src/tools/executors/concurrent.js +128 -0
- package/dist/src/tools/executors/concurrent.js.map +1 -0
- package/dist/src/tools/executors/executor.d.ts +61 -0
- package/dist/src/tools/executors/executor.d.ts.map +1 -0
- package/dist/src/tools/executors/executor.js +190 -0
- package/dist/src/tools/executors/executor.js.map +1 -0
- package/dist/src/tools/executors/sequential.d.ts +30 -0
- package/dist/src/tools/executors/sequential.d.ts.map +1 -0
- package/dist/src/tools/executors/sequential.js +67 -0
- package/dist/src/tools/executors/sequential.js.map +1 -0
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/agent.d.ts +5 -4
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/vended-memory-stores/test-memory-store/store.d.ts +32 -24
- package/dist/src/vended-memory-stores/test-memory-store/store.d.ts.map +1 -1
- package/dist/src/vended-memory-stores/test-memory-store/store.js +84 -91
- package/dist/src/vended-memory-stores/test-memory-store/store.js.map +1 -1
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts +37 -5
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/plugin.js +116 -17
- package/dist/src/vended-plugins/context-offloader/plugin.js.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.d.ts +23 -9
- package/dist/src/vended-plugins/context-offloader/storage.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.js +21 -6
- package/dist/src/vended-plugins/context-offloader/storage.js.map +1 -1
- package/dist/src/vended-tools/index.d.ts +3 -1
- package/dist/src/vended-tools/index.d.ts.map +1 -1
- package/dist/src/vended-tools/index.js +3 -1
- package/dist/src/vended-tools/index.js.map +1 -1
- package/dist/src/vended-tools/notebook/notebook.d.ts +1 -1
- package/dist/src/vended-tools/sleep/index.d.ts +9 -0
- package/dist/src/vended-tools/sleep/index.d.ts.map +1 -0
- package/dist/src/vended-tools/sleep/index.js +7 -0
- package/dist/src/vended-tools/sleep/index.js.map +1 -0
- package/dist/src/vended-tools/sleep/make-sleep.d.ts +48 -0
- package/dist/src/vended-tools/sleep/make-sleep.d.ts.map +1 -0
- package/dist/src/vended-tools/sleep/make-sleep.js +81 -0
- package/dist/src/vended-tools/sleep/make-sleep.js.map +1 -0
- package/dist/src/vended-tools/sleep/sleep.d.ts +19 -0
- package/dist/src/vended-tools/sleep/sleep.d.ts.map +1 -0
- package/dist/src/vended-tools/sleep/sleep.js +20 -0
- package/dist/src/vended-tools/sleep/sleep.js.map +1 -0
- package/dist/src/vended-tools/sleep/types.d.ts +31 -0
- package/dist/src/vended-tools/sleep/types.d.ts.map +1 -0
- package/dist/src/vended-tools/sleep/types.js +22 -0
- package/dist/src/vended-tools/sleep/types.js.map +1 -0
- package/dist/src/vended-tools/stop/index.d.ts +8 -0
- package/dist/src/vended-tools/stop/index.d.ts.map +1 -0
- package/dist/src/vended-tools/stop/index.js +6 -0
- package/dist/src/vended-tools/stop/index.js.map +1 -0
- package/dist/src/vended-tools/stop/stop.d.ts +47 -0
- package/dist/src/vended-tools/stop/stop.d.ts.map +1 -0
- package/dist/src/vended-tools/stop/stop.js +85 -0
- package/dist/src/vended-tools/stop/stop.js.map +1 -0
- package/dist/src/vended-tools/stop/types.d.ts +54 -0
- package/dist/src/vended-tools/stop/types.d.ts.map +1 -0
- package/dist/src/vended-tools/stop/types.js +58 -0
- package/dist/src/vended-tools/stop/types.js.map +1 -0
- package/package.json +13 -2
- package/dist/src/conversation-manager/index.d.ts +0 -10
- package/dist/src/conversation-manager/index.d.ts.map +0 -1
- package/dist/src/conversation-manager/index.js +0 -10
- package/dist/src/conversation-manager/index.js.map +0 -1
- package/dist/src/multiagent/queue.d.ts.map +0 -1
- package/dist/src/multiagent/queue.js.map +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep tool factory: pauses execution for a bounded, cooperative duration.
|
|
3
|
+
*
|
|
4
|
+
* The returned tool honors the invocation's `AbortSignal` (from
|
|
5
|
+
* `context.agent.cancelSignal`), so cancelling the agent aborts the sleep
|
|
6
|
+
* immediately rather than waiting for the full duration.
|
|
7
|
+
*/
|
|
8
|
+
import type { InvokableTool } from '../../tools/tool.js';
|
|
9
|
+
import type { JSONValue } from '../../types/json.js';
|
|
10
|
+
import type { SleepInput } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options for {@link makeSleep}.
|
|
13
|
+
*/
|
|
14
|
+
export interface MakeSleepOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Upper bound on the `duration` input, in seconds. Must be a finite, positive
|
|
17
|
+
* number. Defaults to {@link DEFAULT_MAX_DURATION} (60 s).
|
|
18
|
+
*/
|
|
19
|
+
maxDuration?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Tool name. Defaults to `"sleep"`.
|
|
22
|
+
*/
|
|
23
|
+
name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Tool description shown to the model.
|
|
26
|
+
*/
|
|
27
|
+
description?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a sleep tool with a configurable maximum duration.
|
|
31
|
+
*
|
|
32
|
+
* The returned tool pauses for the requested number of seconds. It attaches a
|
|
33
|
+
* one-shot listener to `context.agent.cancelSignal` so that cancellation of
|
|
34
|
+
* the enclosing agent invocation immediately aborts the sleep with an
|
|
35
|
+
* `AbortError`.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Configuration options.
|
|
38
|
+
* @returns A tool that pauses execution for the requested duration.
|
|
39
|
+
* @throws Error if `maxDuration` is not a finite, positive number.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const shortSleep = makeSleep({ maxDuration: 5 })
|
|
44
|
+
* const agent = new Agent({ tools: [shortSleep] })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function makeSleep(options?: MakeSleepOptions): InvokableTool<SleepInput, JSONValue>;
|
|
48
|
+
//# sourceMappingURL=make-sleep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-sleep.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/make-sleep.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CA0D9F"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep tool factory: pauses execution for a bounded, cooperative duration.
|
|
3
|
+
*
|
|
4
|
+
* The returned tool honors the invocation's `AbortSignal` (from
|
|
5
|
+
* `context.agent.cancelSignal`), so cancelling the agent aborts the sleep
|
|
6
|
+
* immediately rather than waiting for the full duration.
|
|
7
|
+
*/
|
|
8
|
+
import { tool } from '../../tools/tool-factory.js';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { DEFAULT_MAX_DURATION, sleepDescription } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a sleep tool with a configurable maximum duration.
|
|
13
|
+
*
|
|
14
|
+
* The returned tool pauses for the requested number of seconds. It attaches a
|
|
15
|
+
* one-shot listener to `context.agent.cancelSignal` so that cancellation of
|
|
16
|
+
* the enclosing agent invocation immediately aborts the sleep with an
|
|
17
|
+
* `AbortError`.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Configuration options.
|
|
20
|
+
* @returns A tool that pauses execution for the requested duration.
|
|
21
|
+
* @throws Error if `maxDuration` is not a finite, positive number.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const shortSleep = makeSleep({ maxDuration: 5 })
|
|
26
|
+
* const agent = new Agent({ tools: [shortSleep] })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function makeSleep(options = {}) {
|
|
30
|
+
const maxDuration = options.maxDuration ?? DEFAULT_MAX_DURATION;
|
|
31
|
+
if (typeof maxDuration !== 'number' || !Number.isFinite(maxDuration) || maxDuration <= 0) {
|
|
32
|
+
throw new Error(`maxDuration must be a positive, finite number, got ${String(maxDuration)}`);
|
|
33
|
+
}
|
|
34
|
+
const inputSchema = z.object({
|
|
35
|
+
duration: z
|
|
36
|
+
.number()
|
|
37
|
+
.finite('duration must be a finite number')
|
|
38
|
+
.nonnegative('duration must be non-negative')
|
|
39
|
+
.max(maxDuration, `duration exceeds maximum of ${maxDuration} seconds`)
|
|
40
|
+
.describe(`Seconds to pause. Must be finite, non-negative, and no larger than ${maxDuration}.`),
|
|
41
|
+
});
|
|
42
|
+
return tool({
|
|
43
|
+
name: options.name ?? 'sleep',
|
|
44
|
+
description: options.description ?? sleepDescription(maxDuration),
|
|
45
|
+
inputSchema,
|
|
46
|
+
callback: async (input, context) => {
|
|
47
|
+
const { duration } = input;
|
|
48
|
+
const cancelSignal = context?.agent.cancelSignal;
|
|
49
|
+
if (cancelSignal?.aborted) {
|
|
50
|
+
throw cancelSignal.reason ?? new DOMException('Sleep cancelled before it started', 'AbortError');
|
|
51
|
+
}
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
function cleanup() {
|
|
54
|
+
if (cancelSignal) {
|
|
55
|
+
cancelSignal.removeEventListener('abort', onAbort);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function onAbort() {
|
|
59
|
+
globalThis.clearTimeout(timer);
|
|
60
|
+
cleanup();
|
|
61
|
+
reject(cancelSignal?.reason ?? new DOMException('Sleep cancelled', 'AbortError'));
|
|
62
|
+
}
|
|
63
|
+
const timer = globalThis.setTimeout(() => {
|
|
64
|
+
cleanup();
|
|
65
|
+
resolve();
|
|
66
|
+
}, duration * 1000);
|
|
67
|
+
if (cancelSignal) {
|
|
68
|
+
cancelSignal.addEventListener('abort', onAbort, { once: true });
|
|
69
|
+
// Re-check after attaching: the signal may have aborted between the
|
|
70
|
+
// pre-flight check and here, and abort listeners do not fire for
|
|
71
|
+
// events dispatched before they were added.
|
|
72
|
+
if (cancelSignal.aborted) {
|
|
73
|
+
onAbort();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return `Slept for ${duration} seconds`;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=make-sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-sleep.js","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/make-sleep.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAqBnE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CAAC,UAA4B,EAAE;IACtD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,oBAAoB,CAAA;IAC/D,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,KAAK,CAAC,sDAAsD,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAC9F,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;QAC3B,QAAQ,EAAE,CAAC;aACR,MAAM,EAAE;aACR,MAAM,CAAC,kCAAkC,CAAC;aAC1C,WAAW,CAAC,+BAA+B,CAAC;aAC5C,GAAG,CAAC,WAAW,EAAE,+BAA+B,WAAW,UAAU,CAAC;aACtE,QAAQ,CAAC,sEAAsE,WAAW,GAAG,CAAC;KAClG,CAAC,CAAA;IAEF,OAAO,IAAI,CAAC;QACV,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO;QAC7B,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,gBAAgB,CAAC,WAAW,CAAC;QACjE,WAAW;QACX,Q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,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default sleep tool with the built-in maximum duration.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default sleep tool. Pauses execution for up to 60 seconds and aborts
|
|
6
|
+
* immediately when the agent invocation is cancelled.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // With an agent
|
|
11
|
+
* const agent = new Agent({ tools: [sleep] })
|
|
12
|
+
* await agent.invoke('Wait 2 seconds, then continue')
|
|
13
|
+
*
|
|
14
|
+
* // Direct usage
|
|
15
|
+
* await sleep.invoke({ duration: 0.5 })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const sleep: import("../../index.js").InvokableTool<import("./types.js").SleepInput, import("../../index.js").JSONValue>;
|
|
19
|
+
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/sleep.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,6GAAc,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default sleep tool with the built-in maximum duration.
|
|
3
|
+
*/
|
|
4
|
+
import { makeSleep } from './make-sleep.js';
|
|
5
|
+
/**
|
|
6
|
+
* Default sleep tool. Pauses execution for up to 60 seconds and aborts
|
|
7
|
+
* immediately when the agent invocation is cancelled.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // With an agent
|
|
12
|
+
* const agent = new Agent({ tools: [sleep] })
|
|
13
|
+
* await agent.invoke('Wait 2 seconds, then continue')
|
|
14
|
+
*
|
|
15
|
+
* // Direct usage
|
|
16
|
+
* await sleep.invoke({ duration: 0.5 })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const sleep = makeSleep();
|
|
20
|
+
//# sourceMappingURL=sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/sleep.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions and constants for the sleep tool.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default upper bound on `duration` (seconds) accepted by `makeSleep`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_MAX_DURATION = 60;
|
|
8
|
+
/**
|
|
9
|
+
* Build the model-facing description with the configured maximum interpolated
|
|
10
|
+
* so the model knows the exact ceiling.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sleepDescription(maxDuration: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Description for the default sleep tool (60-second cap).
|
|
15
|
+
*/
|
|
16
|
+
export declare const SLEEP_DESCRIPTION: string;
|
|
17
|
+
/**
|
|
18
|
+
* Input parameters accepted by the sleep tool.
|
|
19
|
+
*
|
|
20
|
+
* The Zod schema in `make-sleep.ts` is the single source of truth for the
|
|
21
|
+
* validated input shape (it also enforces the configured maximum); this type
|
|
22
|
+
* describes the pre-refinement shape callers can pass directly.
|
|
23
|
+
*/
|
|
24
|
+
export interface SleepInput {
|
|
25
|
+
/**
|
|
26
|
+
* Seconds to pause. Must be a finite, non-negative number and no larger than
|
|
27
|
+
* the tool's configured maximum.
|
|
28
|
+
*/
|
|
29
|
+
duration: number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAO5D;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAyC,CAAA;AAEvE;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions and constants for the sleep tool.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default upper bound on `duration` (seconds) accepted by `makeSleep`.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_MAX_DURATION = 60;
|
|
8
|
+
/**
|
|
9
|
+
* Build the model-facing description with the configured maximum interpolated
|
|
10
|
+
* so the model knows the exact ceiling.
|
|
11
|
+
*/
|
|
12
|
+
export function sleepDescription(maxDuration) {
|
|
13
|
+
return (`Pauses execution for a specified number of seconds (max ${maxDuration}). ` +
|
|
14
|
+
'Cooperative and cancellable: the sleep aborts immediately when the agent ' +
|
|
15
|
+
'invocation is cancelled. Rejects negative, NaN, infinite, or non-numeric ' +
|
|
16
|
+
`durations, and durations above ${maxDuration}.`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Description for the default sleep tool (60-second cap).
|
|
20
|
+
*/
|
|
21
|
+
export const SLEEP_DESCRIPTION = sleepDescription(DEFAULT_MAX_DURATION);
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/vended-tools/sleep/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAEtC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,OAAO,CACL,2DAA2D,WAAW,KAAK;QAC3E,2EAA2E;QAC3E,2EAA2E;QAC3E,kCAAkC,WAAW,GAAG,CACjD,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop tool for gracefully ending the agent loop.
|
|
3
|
+
*/
|
|
4
|
+
export { stop, makeStop } from './stop.js';
|
|
5
|
+
export type { MakeStopOptions } from './stop.js';
|
|
6
|
+
export { DEFAULT_MAX_STOP_MESSAGE_LENGTH, DEFAULT_STOP_DESCRIPTION, DEFAULT_STOP_MESSAGE } from './types.js';
|
|
7
|
+
export type { StopInput } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/stop/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAC5G,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/vended-tools/stop/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { tool } from '../../tools/tool-factory.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by {@link makeStop}.
|
|
4
|
+
*/
|
|
5
|
+
export interface MakeStopOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Tool name shown to the model. Defaults to `'stop'`.
|
|
8
|
+
*/
|
|
9
|
+
name?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Tool description shown to the model. Defaults to {@link DEFAULT_STOP_DESCRIPTION}.
|
|
12
|
+
*/
|
|
13
|
+
description?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum accepted length for the model-supplied `message` argument, in
|
|
16
|
+
* characters. Must be a positive integer. Defaults to
|
|
17
|
+
* {@link DEFAULT_MAX_STOP_MESSAGE_LENGTH} (4096).
|
|
18
|
+
*/
|
|
19
|
+
maxMessageLength?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a stop tool that gracefully ends the agent loop.
|
|
23
|
+
*
|
|
24
|
+
* Shims onto the SDK's existing `AfterToolsEvent.endTurn` primitive: the tool
|
|
25
|
+
* records the model's optional final message on `invocationState`, then a
|
|
26
|
+
* lazily-installed hook on the agent reads that marker on the terminating
|
|
27
|
+
* `AfterToolsEvent` and sets `endTurn` to the message, which the agent loop
|
|
28
|
+
* already treats as a cooperative stop signal.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Agent } from '@strands-agents/sdk'
|
|
33
|
+
* import { stop } from '@strands-agents/sdk/vended-tools/stop'
|
|
34
|
+
*
|
|
35
|
+
* const agent = new Agent({ model, tools: [stop] })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function makeStop(options?: MakeStopOptions): ReturnType<typeof tool>;
|
|
39
|
+
/**
|
|
40
|
+
* Default stop tool.
|
|
41
|
+
*
|
|
42
|
+
* Ends the agent loop cooperatively when called by the model. Any tools the
|
|
43
|
+
* model requested alongside `stop` in the same turn still run to completion —
|
|
44
|
+
* the loop halts after the batch, without calling the model again.
|
|
45
|
+
*/
|
|
46
|
+
export declare const stop: import("../../index.js").InvokableTool<unknown, import("../../index.js").JSONValue>;
|
|
47
|
+
//# sourceMappingURL=stop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/stop/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAmBlD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAqCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CA2B3E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,qFAAa,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { tool } from '../../tools/tool-factory.js';
|
|
2
|
+
import { AfterToolsEvent } from '../../hooks/events.js';
|
|
3
|
+
import { DEFAULT_MAX_STOP_MESSAGE_LENGTH, DEFAULT_STOP_DESCRIPTION, DEFAULT_STOP_MESSAGE, STOP_INVOCATION_STATE_KEY, buildStopInputSchema, } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Tracks agents on which the terminal `AfterToolsEvent` hook has been
|
|
6
|
+
* installed, so we install it at most once per agent instance regardless of
|
|
7
|
+
* how many times the model calls `stop`. Keyed weakly so garbage-collected
|
|
8
|
+
* agents drop out automatically.
|
|
9
|
+
*/
|
|
10
|
+
const installedAgents = new WeakSet();
|
|
11
|
+
/**
|
|
12
|
+
* Installs a one-time `AfterToolsEvent` hook that ends the agent loop when the
|
|
13
|
+
* stop tool has set its marker on `invocationState`. Reads the marker fresh
|
|
14
|
+
* on every event so subsequent invocations of the same agent can call `stop`
|
|
15
|
+
* again without leaking state across turns.
|
|
16
|
+
*/
|
|
17
|
+
function ensureHookInstalled(agent) {
|
|
18
|
+
if (installedAgents.has(agent))
|
|
19
|
+
return;
|
|
20
|
+
// Register the hook FIRST — if `addHook` throws, we haven't marked the agent
|
|
21
|
+
// as installed, so a later call still gets a chance to install one. Marking
|
|
22
|
+
// before registering would silently no-op every future stop() on this agent.
|
|
23
|
+
agent.addHook(AfterToolsEvent, (event) => {
|
|
24
|
+
const marker = event.invocationState[STOP_INVOCATION_STATE_KEY];
|
|
25
|
+
// JSON round-tripping `invocationState` can turn an absent field into
|
|
26
|
+
// `null`; treat both as "no stop requested".
|
|
27
|
+
if (marker == null)
|
|
28
|
+
return;
|
|
29
|
+
// Consume the marker to avoid re-firing if the caller reuses `invocationState` across invocations.
|
|
30
|
+
delete event.invocationState[STOP_INVOCATION_STATE_KEY];
|
|
31
|
+
event.endTurn = marker.message;
|
|
32
|
+
});
|
|
33
|
+
installedAgents.add(agent);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a stop tool that gracefully ends the agent loop.
|
|
37
|
+
*
|
|
38
|
+
* Shims onto the SDK's existing `AfterToolsEvent.endTurn` primitive: the tool
|
|
39
|
+
* records the model's optional final message on `invocationState`, then a
|
|
40
|
+
* lazily-installed hook on the agent reads that marker on the terminating
|
|
41
|
+
* `AfterToolsEvent` and sets `endTurn` to the message, which the agent loop
|
|
42
|
+
* already treats as a cooperative stop signal.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { Agent } from '@strands-agents/sdk'
|
|
47
|
+
* import { stop } from '@strands-agents/sdk/vended-tools/stop'
|
|
48
|
+
*
|
|
49
|
+
* const agent = new Agent({ model, tools: [stop] })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function makeStop(options) {
|
|
53
|
+
const maxMessageLength = options?.maxMessageLength ?? DEFAULT_MAX_STOP_MESSAGE_LENGTH;
|
|
54
|
+
if (!Number.isInteger(maxMessageLength) || maxMessageLength <= 0) {
|
|
55
|
+
throw new Error(`maxMessageLength must be a positive integer, got ${String(maxMessageLength)}`);
|
|
56
|
+
}
|
|
57
|
+
return tool({
|
|
58
|
+
name: options?.name ?? 'stop',
|
|
59
|
+
description: options?.description ?? DEFAULT_STOP_DESCRIPTION,
|
|
60
|
+
inputSchema: buildStopInputSchema(maxMessageLength),
|
|
61
|
+
callback: (input, context) => {
|
|
62
|
+
if (!context) {
|
|
63
|
+
throw new Error('Tool context is required for stop operations');
|
|
64
|
+
}
|
|
65
|
+
// Fall back to the default when message is absent (undefined or null,
|
|
66
|
+
// e.g. from providers that serialize omitted fields as null) OR empty.
|
|
67
|
+
// The agent loop treats `endTurn === ''` as falsy, so an empty string
|
|
68
|
+
// would fail to halt the loop even though the model called `stop`.
|
|
69
|
+
const message = input.message != null && input.message.length > 0 ? input.message : DEFAULT_STOP_MESSAGE;
|
|
70
|
+
ensureHookInstalled(context.agent);
|
|
71
|
+
const marker = { message };
|
|
72
|
+
context.invocationState[STOP_INVOCATION_STATE_KEY] = marker;
|
|
73
|
+
return message;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Default stop tool.
|
|
79
|
+
*
|
|
80
|
+
* Ends the agent loop cooperatively when called by the model. Any tools the
|
|
81
|
+
* model requested alongside `stop` in the same turn still run to completion —
|
|
82
|
+
* the loop halts after the batch, without calling the model again.
|
|
83
|
+
*/
|
|
84
|
+
export const stop = makeStop();
|
|
85
|
+
//# sourceMappingURL=stop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop.js","sourceRoot":"","sources":["../../../../src/vended-tools/stop/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AAM;QAC7B,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,wBAAwB;QAC7D,WAAW,EAAE,oBAAoB,CAAC,gBAAgB,CAAC;QACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC3B,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;YACjE,CAAC;YAED,sEAAsE;YACtE,uEAAuE;YACvE,sEAAsE;YACtE,mEAAmE;YACnE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAA;YAExG,mBAAmB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAClC,MAAM,MAAM,GAAe,EAAE,OAAO,EAAE,CAAA;YACtC,OAAO,CAAC,eAAe,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAA;YAE3D,OAAO,OAAO,CAAA;QAChB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the stop tool.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Default assistant-facing message appended when the loop ends and the model
|
|
7
|
+
* called `stop` without providing its own message.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_STOP_MESSAGE = "Agent loop stopped.";
|
|
10
|
+
/**
|
|
11
|
+
* Description shown to the model for the `stop` tool.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_STOP_DESCRIPTION: string;
|
|
14
|
+
/**
|
|
15
|
+
* Default cap on the optional `message` argument, in characters. The cap
|
|
16
|
+
* exists so a runaway model can't blow the conversation history in one shot;
|
|
17
|
+
* override it via `makeStop({ maxMessageLength: ... })` when a longer summary
|
|
18
|
+
* is legitimate.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_MAX_STOP_MESSAGE_LENGTH = 4096;
|
|
21
|
+
/**
|
|
22
|
+
* Key set on `invocationState` by the stop tool to signal the loop should end
|
|
23
|
+
* after the current tool batch completes. Consumers should not depend on the
|
|
24
|
+
* literal value; the hook installed by the tool treats a `null` or `undefined`
|
|
25
|
+
* marker as "no stop requested" and any other value as a request to halt.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare const STOP_INVOCATION_STATE_KEY = "__strandsStopRequested";
|
|
30
|
+
/**
|
|
31
|
+
* Build the Zod schema for the stop tool input at a configured message-length
|
|
32
|
+
* cap. Single source of truth for the input shape; {@link StopInput} is derived
|
|
33
|
+
* from the default-capped schema.
|
|
34
|
+
*
|
|
35
|
+
* `message` is optional and length-capped to keep a runaway model from
|
|
36
|
+
* flooding the conversation with an unbounded final string. It also accepts
|
|
37
|
+
* `null` for providers that serialize omitted fields as JSON null.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildStopInputSchema(maxMessageLength: number): z.ZodObject<{
|
|
40
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Default Zod schema for the stop tool input, capped at
|
|
44
|
+
* {@link DEFAULT_MAX_STOP_MESSAGE_LENGTH}.
|
|
45
|
+
*/
|
|
46
|
+
export declare const stopInputSchema: z.ZodObject<{
|
|
47
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/**
|
|
50
|
+
* Input parameters for the stop tool. Derived from {@link stopInputSchema}
|
|
51
|
+
* so the two cannot drift.
|
|
52
|
+
*/
|
|
53
|
+
export type StopInput = z.infer<typeof stopInputSchema>;
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/stop/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,wBAAwB,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAG4D,CAAA;AAEjG;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,OAAO,CAAA;AAEnD;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,2BAA2B,CAAA;AAEjE;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC1E,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;CACnD,CAAC,CAaD;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;aApBjB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;iBAoBgC,CAAA;AAEpF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the stop tool.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Default assistant-facing message appended when the loop ends and the model
|
|
7
|
+
* called `stop` without providing its own message.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_STOP_MESSAGE = 'Agent loop stopped.';
|
|
10
|
+
/**
|
|
11
|
+
* Description shown to the model for the `stop` tool.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_STOP_DESCRIPTION = 'Gracefully ends the agent loop when the task is complete. ' +
|
|
14
|
+
'Call this tool once with an optional final message when no further work is needed. ' +
|
|
15
|
+
'This is a cooperative stop, not an abort: any tools already requested in this turn still run.';
|
|
16
|
+
/**
|
|
17
|
+
* Default cap on the optional `message` argument, in characters. The cap
|
|
18
|
+
* exists so a runaway model can't blow the conversation history in one shot;
|
|
19
|
+
* override it via `makeStop({ maxMessageLength: ... })` when a longer summary
|
|
20
|
+
* is legitimate.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_MAX_STOP_MESSAGE_LENGTH = 4096;
|
|
23
|
+
/**
|
|
24
|
+
* Key set on `invocationState` by the stop tool to signal the loop should end
|
|
25
|
+
* after the current tool batch completes. Consumers should not depend on the
|
|
26
|
+
* literal value; the hook installed by the tool treats a `null` or `undefined`
|
|
27
|
+
* marker as "no stop requested" and any other value as a request to halt.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export const STOP_INVOCATION_STATE_KEY = '__strandsStopRequested';
|
|
32
|
+
/**
|
|
33
|
+
* Build the Zod schema for the stop tool input at a configured message-length
|
|
34
|
+
* cap. Single source of truth for the input shape; {@link StopInput} is derived
|
|
35
|
+
* from the default-capped schema.
|
|
36
|
+
*
|
|
37
|
+
* `message` is optional and length-capped to keep a runaway model from
|
|
38
|
+
* flooding the conversation with an unbounded final string. It also accepts
|
|
39
|
+
* `null` for providers that serialize omitted fields as JSON null.
|
|
40
|
+
*/
|
|
41
|
+
export function buildStopInputSchema(maxMessageLength) {
|
|
42
|
+
return z.object({
|
|
43
|
+
message: z
|
|
44
|
+
.string()
|
|
45
|
+
.max(maxMessageLength, {
|
|
46
|
+
message: `\`message\` length exceeds the maximum of ${maxMessageLength} characters`,
|
|
47
|
+
})
|
|
48
|
+
.nullable()
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Optional final message summarizing why the loop is ending. Appears as the loop's last assistant turn."),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Default Zod schema for the stop tool input, capped at
|
|
55
|
+
* {@link DEFAULT_MAX_STOP_MESSAGE_LENGTH}.
|
|
56
|
+
*/
|
|
57
|
+
export const stopInputSchema = buildStopInputSchema(DEFAULT_MAX_STOP_MESSAGE_LENGTH);
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/vended-tools/stop/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GACnC,4DAA4D;IAC5D,qFAAqF;IACrF,+FAA+F,CAAA;AAEjG;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,wBAAwB,CAAA;AAEjE;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,gBAAwB;IAG3D,OAAO,CAAC,CAAC,MAAM,CAAC;QACd,OAAO,EAAE,CAAC;aACP,MAAM,EAAE;aACR,GAAG,CAAC,gBAAgB,EAAE;YACrB,OAAO,EAAE,6CAA6C,gBAAgB,aAAa;SACpF,CAAC;aACD,QAAQ,EAAE;aACV,QAAQ,EAAE;aACV,QAAQ,CACP,uGAAuG,CACxG;KACJ,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC,+BAA+B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strands-agents/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "TypeScript SDK for Strands Agents framework",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"module": "dist/src/index.js",
|
|
@@ -68,6 +68,14 @@
|
|
|
68
68
|
"types": "./dist/src/vended-tools/bash/index.d.ts",
|
|
69
69
|
"default": "./dist/src/vended-tools/bash/index.js"
|
|
70
70
|
},
|
|
71
|
+
"./vended-tools/sleep": {
|
|
72
|
+
"types": "./dist/src/vended-tools/sleep/index.d.ts",
|
|
73
|
+
"default": "./dist/src/vended-tools/sleep/index.js"
|
|
74
|
+
},
|
|
75
|
+
"./vended-tools/stop": {
|
|
76
|
+
"types": "./dist/src/vended-tools/stop/index.d.ts",
|
|
77
|
+
"default": "./dist/src/vended-tools/stop/index.js"
|
|
78
|
+
},
|
|
71
79
|
"./a2a": {
|
|
72
80
|
"types": "./dist/src/a2a/index.d.ts",
|
|
73
81
|
"default": "./dist/src/a2a/index.js"
|
|
@@ -128,6 +136,10 @@
|
|
|
128
136
|
"types": "./dist/src/vended-plugins/index.d.ts",
|
|
129
137
|
"default": "./dist/src/vended-plugins/index.js"
|
|
130
138
|
},
|
|
139
|
+
"./storage": {
|
|
140
|
+
"types": "./dist/src/storage/index.d.ts",
|
|
141
|
+
"default": "./dist/src/storage/index.js"
|
|
142
|
+
},
|
|
131
143
|
"./sandbox": {
|
|
132
144
|
"types": "./dist/src/sandbox/index.d.ts",
|
|
133
145
|
"default": "./dist/src/sandbox/index.js"
|
|
@@ -205,7 +217,6 @@
|
|
|
205
217
|
"@smithy/types": "^4.15.1",
|
|
206
218
|
"@types/express": "^5.0.6",
|
|
207
219
|
"@types/node": "^25.9.4",
|
|
208
|
-
"@types/uuid": "^11.0.0",
|
|
209
220
|
"@typescript-eslint/eslint-plugin": "^8.62.1",
|
|
210
221
|
"@typescript-eslint/parser": "^8.0.0",
|
|
211
222
|
"@vitest/browser": "^4.1.10",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation Manager exports.
|
|
3
|
-
*
|
|
4
|
-
* This module exports conversation manager implementations.
|
|
5
|
-
*/
|
|
6
|
-
export { ConversationManager, type ProactiveCompressionConfig, type ConversationManagerReduceOptions as ReduceOptions, type ConversationManagerOptions, } from './conversation-manager.js';
|
|
7
|
-
export { NullConversationManager } from './null-conversation-manager.js';
|
|
8
|
-
export { SlidingWindowConversationManager, type SlidingWindowConversationManagerConfig, } from './sliding-window-conversation-manager.js';
|
|
9
|
-
export { SummarizingConversationManager, type SummarizingConversationManagerConfig, } from './summarizing-conversation-manager.js';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/conversation-manager/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,gCAAgC,IAAI,aAAa,EACtD,KAAK,0BAA0B,GAChC,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EACL,gCAAgC,EAChC,KAAK,sCAAsC,GAC5C,MAAM,0CAA0C,CAAA;AACjD,OAAO,EACL,8BAA8B,EAC9B,KAAK,oCAAoC,GAC1C,MAAM,uCAAuC,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation Manager exports.
|
|
3
|
-
*
|
|
4
|
-
* This module exports conversation manager implementations.
|
|
5
|
-
*/
|
|
6
|
-
export { ConversationManager, } from './conversation-manager.js';
|
|
7
|
-
export { NullConversationManager } from './null-conversation-manager.js';
|
|
8
|
-
export { SlidingWindowConversationManager, } from './sliding-window-conversation-manager.js';
|
|
9
|
-
export { SummarizingConversationManager, } from './summarizing-conversation-manager.js';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/conversation-manager/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,GAIpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EACL,gCAAgC,GAEjC,MAAM,0CAA0C,CAAA;AACjD,OAAO,EACL,8BAA8B,GAE/B,MAAM,uCAAuC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/multiagent/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAE/C;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAA;IACf,GAAG,EAAE,MAAM,IAAI,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,+DAA+D;IAC/D,OAAO,CAAC,OAAO,CAAC,CAA0B;IAC1C,OAAO,CAAC,SAAS,CAAQ;IAEzB;;OAEG;IACH,IAAI,CAAC,IAAI,EA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