@loopstack/accessing-tool-results-example-workflow 0.19.0-rc.1 → 0.20.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/dist/workflow-tool-results.workflow.d.ts +10 -2
- package/dist/workflow-tool-results.workflow.d.ts.map +1 -1
- package/dist/workflow-tool-results.workflow.js +9 -5
- package/dist/workflow-tool-results.workflow.js.map +1 -1
- package/dist/workflow-tool-results.workflow.yaml +4 -4
- package/package.json +19 -19
- package/src/__tests__/workflow-tool-results.workflow.spec.ts +11 -11
- package/src/workflow-tool-results.workflow.ts +14 -12
- package/src/workflow-tool-results.workflow.yaml +4 -4
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { WorkflowMetadataInterface } from '@loopstack/common';
|
|
2
1
|
export declare class WorkflowToolResultsWorkflow {
|
|
3
2
|
private createValue;
|
|
4
3
|
private createChatMessage;
|
|
5
|
-
|
|
4
|
+
runtime: {
|
|
5
|
+
tools: {
|
|
6
|
+
create_some_data: {
|
|
7
|
+
say_hello: {
|
|
8
|
+
data: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
theMessage(): string;
|
|
6
14
|
}
|
|
7
15
|
//# sourceMappingURL=workflow-tool-results.workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-tool-results.workflow.d.ts","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-tool-results.workflow.d.ts","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":"AAKA,qBAIa,2BAA2B;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,iBAAiB,CAAoB;IAG3D,OAAO,EAAE;QACP,KAAK,EAAE;YACL,gBAAgB,EAAE;gBAChB,SAAS,EAAE;oBACT,IAAI,EAAE,MAAM,CAAC;iBACd,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;IAGF,UAAU,IAAI,MAAM;CAGrB"}
|
|
@@ -17,9 +17,9 @@ const create_value_tool_1 = require("@loopstack/create-value-tool");
|
|
|
17
17
|
let WorkflowToolResultsWorkflow = class WorkflowToolResultsWorkflow {
|
|
18
18
|
createValue;
|
|
19
19
|
createChatMessage;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return tools.create_some_data.say_hello.data;
|
|
20
|
+
runtime;
|
|
21
|
+
theMessage() {
|
|
22
|
+
return this.runtime.tools.create_some_data.say_hello.data;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow;
|
|
@@ -31,12 +31,16 @@ __decorate([
|
|
|
31
31
|
(0, common_2.InjectTool)(),
|
|
32
32
|
__metadata("design:type", create_chat_message_tool_1.CreateChatMessage)
|
|
33
33
|
], WorkflowToolResultsWorkflow.prototype, "createChatMessage", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, common_2.Runtime)(),
|
|
36
|
+
__metadata("design:type", Object)
|
|
37
|
+
], WorkflowToolResultsWorkflow.prototype, "runtime", void 0);
|
|
34
38
|
__decorate([
|
|
35
39
|
(0, common_2.DefineHelper)(),
|
|
36
40
|
__metadata("design:type", Function),
|
|
37
|
-
__metadata("design:paramtypes", [
|
|
41
|
+
__metadata("design:paramtypes", []),
|
|
38
42
|
__metadata("design:returntype", String)
|
|
39
|
-
], WorkflowToolResultsWorkflow.prototype, "
|
|
43
|
+
], WorkflowToolResultsWorkflow.prototype, "theMessage", null);
|
|
40
44
|
exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow = __decorate([
|
|
41
45
|
(0, common_1.Injectable)(),
|
|
42
46
|
(0, common_2.Workflow)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-tool-results.workflow.js","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"workflow-tool-results.workflow.js","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,8CAAgF;AAChF,kFAAwE;AACxE,oEAA2D;AAMpD,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAChB,WAAW,CAAc;IACzB,iBAAiB,CAAoB;IAG3D,OAAO,CAQL;IAGF,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC;IAC5D,CAAC;CACF,CAAA;AAnBY,kEAA2B;AAChB;IAArB,IAAA,mBAAU,GAAE;8BAAsB,+BAAW;gEAAC;AACzB;IAArB,IAAA,mBAAU,GAAE;8BAA4B,4CAAiB;sEAAC;AAG3D;IADC,IAAA,gBAAO,GAAE;;4DASR;AAGF;IADC,IAAA,qBAAY,GAAE;;;;6DAGd;sCAlBU,2BAA2B;IAJvC,IAAA,mBAAU,GAAE;IACZ,IAAA,iBAAQ,EAAC;QACR,UAAU,EAAE,SAAS,GAAG,sCAAsC;KAC/D,CAAC;GACW,2BAA2B,CAmBvC"}
|
|
@@ -15,13 +15,13 @@ transitions:
|
|
|
15
15
|
- tool: createChatMessage
|
|
16
16
|
args:
|
|
17
17
|
role: 'assistant'
|
|
18
|
-
content: 'Data from specific call id: {{
|
|
18
|
+
content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
19
19
|
|
|
20
20
|
# Access the data using the call index
|
|
21
21
|
- tool: createChatMessage
|
|
22
22
|
args:
|
|
23
23
|
role: 'assistant'
|
|
24
|
-
content: 'Data from first tool call: {{
|
|
24
|
+
content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
|
|
25
25
|
|
|
26
26
|
- id: access_data
|
|
27
27
|
from: data_created
|
|
@@ -31,10 +31,10 @@ transitions:
|
|
|
31
31
|
- tool: createChatMessage
|
|
32
32
|
args:
|
|
33
33
|
role: 'assistant'
|
|
34
|
-
content: 'Data from previous transition: {{
|
|
34
|
+
content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
35
35
|
|
|
36
36
|
# Access the data using a custom helper function of the workflow
|
|
37
37
|
- tool: createChatMessage
|
|
38
38
|
args:
|
|
39
39
|
role: 'assistant'
|
|
40
|
-
content: 'Data access using custom helper: {{
|
|
40
|
+
content: 'Data access using custom helper: {{ theMessage }}'
|
package/package.json
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
"name": "@loopstack/accessing-tool-results-example-workflow",
|
|
3
3
|
"displayName": "Loopstack Tool Results Example",
|
|
4
4
|
"description": "A simple workflow showing different methods of how to access tool results in a subsequent workflow step.",
|
|
5
|
-
"version": "0.19.0-rc.1",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "Jakob Klippel",
|
|
8
|
-
"url": "https://www.linkedin.com/in/jakob-klippel/"
|
|
9
|
-
},
|
|
10
5
|
"keywords": [
|
|
6
|
+
"assign",
|
|
11
7
|
"example",
|
|
12
|
-
"tool",
|
|
13
|
-
"results",
|
|
14
|
-
"workflow",
|
|
15
8
|
"helper",
|
|
16
|
-
"
|
|
9
|
+
"results",
|
|
10
|
+
"tool",
|
|
11
|
+
"workflow"
|
|
17
12
|
],
|
|
13
|
+
"version": "0.20.0",
|
|
18
14
|
"license": "Apache-2.0",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Jakob Klippel",
|
|
17
|
+
"url": "https://www.linkedin.com/in/jakob-klippel/"
|
|
18
|
+
},
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"exports": {
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"watch": "nest build --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loopstack/common": "^0.
|
|
35
|
-
"@loopstack/core-ui-module": "^0.
|
|
36
|
-
"@loopstack/create-chat-message-tool": "^0.
|
|
37
|
-
"@loopstack/create-value-tool": "^0.
|
|
34
|
+
"@loopstack/common": "^0.20.0",
|
|
35
|
+
"@loopstack/core-ui-module": "^0.20.0",
|
|
36
|
+
"@loopstack/create-chat-message-tool": "^0.20.0",
|
|
37
|
+
"@loopstack/create-value-tool": "^0.20.0",
|
|
38
38
|
"@nestjs/common": "^11.1.12",
|
|
39
39
|
"zod": "^4.3.5"
|
|
40
40
|
},
|
|
@@ -42,12 +42,6 @@
|
|
|
42
42
|
"dist",
|
|
43
43
|
"src"
|
|
44
44
|
],
|
|
45
|
-
"loopstack": {
|
|
46
|
-
"module": "src/tool-results-example.module.ts",
|
|
47
|
-
"workflows": [
|
|
48
|
-
"src/workflow-tool-results.workflow.ts"
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
45
|
"jest": {
|
|
52
46
|
"moduleFileExtensions": [
|
|
53
47
|
"js",
|
|
@@ -67,5 +61,11 @@
|
|
|
67
61
|
"maxWorkers": 1,
|
|
68
62
|
"testTimeout": 10000,
|
|
69
63
|
"forceExit": true
|
|
64
|
+
},
|
|
65
|
+
"loopstack": {
|
|
66
|
+
"module": "src/tool-results-example.module.ts",
|
|
67
|
+
"workflows": [
|
|
68
|
+
"src/workflow-tool-results.workflow.ts"
|
|
69
|
+
]
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestingModule } from '@nestjs/testing';
|
|
2
|
-
import {
|
|
2
|
+
import { RunContext, getBlockHelpers } from '@loopstack/common';
|
|
3
3
|
import { WorkflowProcessorService } from '@loopstack/core';
|
|
4
4
|
import { CoreUiModule } from '@loopstack/core-ui-module';
|
|
5
5
|
import { CreateChatMessage, CreateChatMessageToolModule } from '@loopstack/create-chat-message-tool';
|
|
@@ -39,12 +39,12 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it('should have extractMessage helper', () => {
|
|
42
|
-
expect(getBlockHelpers(workflow)).toContain('
|
|
42
|
+
expect(getBlockHelpers(workflow)).toContain('theMessage');
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
describe('tool result access', () => {
|
|
46
46
|
it('should access tool results by call id and index in same transition', async () => {
|
|
47
|
-
const context =
|
|
47
|
+
const context = {} as RunContext;
|
|
48
48
|
mockCreateValue.execute.mockResolvedValue({ data: 'Hello World.' });
|
|
49
49
|
mockCreateChatMessage.execute.mockResolvedValue({ data: undefined });
|
|
50
50
|
|
|
@@ -55,6 +55,7 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
55
55
|
{ input: 'Hello World.' },
|
|
56
56
|
expect.anything(),
|
|
57
57
|
expect.anything(),
|
|
58
|
+
expect.anything(),
|
|
58
59
|
);
|
|
59
60
|
|
|
60
61
|
// Verify CreateChatMessage received resolved template values
|
|
@@ -65,6 +66,7 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
65
66
|
},
|
|
66
67
|
expect.anything(),
|
|
67
68
|
expect.anything(),
|
|
69
|
+
expect.anything(),
|
|
68
70
|
);
|
|
69
71
|
|
|
70
72
|
expect(mockCreateChatMessage.execute).toHaveBeenCalledWith(
|
|
@@ -74,20 +76,16 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
74
76
|
},
|
|
75
77
|
expect.anything(),
|
|
76
78
|
expect.anything(),
|
|
79
|
+
expect.anything(),
|
|
77
80
|
);
|
|
78
81
|
});
|
|
79
82
|
|
|
80
83
|
it('should access tool results from previous transition', async () => {
|
|
81
|
-
const context =
|
|
84
|
+
const context = {} as RunContext;
|
|
82
85
|
mockCreateValue.execute.mockResolvedValue({ data: 'Hello World.' });
|
|
83
86
|
mockCreateChatMessage.execute.mockResolvedValue({ data: undefined });
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// Should complete both transitions
|
|
88
|
-
const history = result.state.getHistory();
|
|
89
|
-
expect(history.some((h) => h.metadata.transition?.transition === 'create_some_data')).toBe(true);
|
|
90
|
-
expect(history.some((h) => h.metadata.transition?.transition === 'access_data')).toBe(true);
|
|
88
|
+
await processor.process(workflow, {}, context);
|
|
91
89
|
|
|
92
90
|
expect(mockCreateChatMessage.execute).toHaveBeenCalledWith(
|
|
93
91
|
{
|
|
@@ -96,11 +94,12 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
96
94
|
},
|
|
97
95
|
expect.anything(),
|
|
98
96
|
expect.anything(),
|
|
97
|
+
expect.anything(),
|
|
99
98
|
);
|
|
100
99
|
});
|
|
101
100
|
|
|
102
101
|
it('should access tool results using custom helper', async () => {
|
|
103
|
-
const context =
|
|
102
|
+
const context = {} as RunContext;
|
|
104
103
|
mockCreateValue.execute.mockResolvedValue({ data: 'Hello World.' });
|
|
105
104
|
mockCreateChatMessage.execute.mockResolvedValue({ data: undefined });
|
|
106
105
|
|
|
@@ -113,6 +112,7 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
113
112
|
},
|
|
114
113
|
expect.anything(),
|
|
115
114
|
expect.anything(),
|
|
115
|
+
expect.anything(),
|
|
116
116
|
);
|
|
117
117
|
});
|
|
118
118
|
});
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { DefineHelper, InjectTool,
|
|
2
|
+
import { DefineHelper, InjectTool, Runtime, Workflow } from '@loopstack/common';
|
|
3
3
|
import { CreateChatMessage } from '@loopstack/create-chat-message-tool';
|
|
4
4
|
import { CreateValue } from '@loopstack/create-value-tool';
|
|
5
5
|
|
|
6
|
-
interface WorkflowToolsMetadata {
|
|
7
|
-
create_some_data: {
|
|
8
|
-
say_hello: {
|
|
9
|
-
data: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
6
|
@Injectable()
|
|
15
7
|
@Workflow({
|
|
16
8
|
configFile: __dirname + '/workflow-tool-results.workflow.yaml',
|
|
@@ -19,9 +11,19 @@ export class WorkflowToolResultsWorkflow {
|
|
|
19
11
|
@InjectTool() private createValue: CreateValue;
|
|
20
12
|
@InjectTool() private createChatMessage: CreateChatMessage;
|
|
21
13
|
|
|
14
|
+
@Runtime()
|
|
15
|
+
runtime: {
|
|
16
|
+
tools: {
|
|
17
|
+
create_some_data: {
|
|
18
|
+
say_hello: {
|
|
19
|
+
data: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
22
25
|
@DefineHelper()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return tools.create_some_data.say_hello.data;
|
|
26
|
+
theMessage(): string {
|
|
27
|
+
return this.runtime.tools.create_some_data.say_hello.data;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -15,13 +15,13 @@ transitions:
|
|
|
15
15
|
- tool: createChatMessage
|
|
16
16
|
args:
|
|
17
17
|
role: 'assistant'
|
|
18
|
-
content: 'Data from specific call id: {{
|
|
18
|
+
content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
19
19
|
|
|
20
20
|
# Access the data using the call index
|
|
21
21
|
- tool: createChatMessage
|
|
22
22
|
args:
|
|
23
23
|
role: 'assistant'
|
|
24
|
-
content: 'Data from first tool call: {{
|
|
24
|
+
content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
|
|
25
25
|
|
|
26
26
|
- id: access_data
|
|
27
27
|
from: data_created
|
|
@@ -31,10 +31,10 @@ transitions:
|
|
|
31
31
|
- tool: createChatMessage
|
|
32
32
|
args:
|
|
33
33
|
role: 'assistant'
|
|
34
|
-
content: 'Data from previous transition: {{
|
|
34
|
+
content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
35
35
|
|
|
36
36
|
# Access the data using a custom helper function of the workflow
|
|
37
37
|
- tool: createChatMessage
|
|
38
38
|
args:
|
|
39
39
|
role: 'assistant'
|
|
40
|
-
content: 'Data access using custom helper: {{
|
|
40
|
+
content: 'Data access using custom helper: {{ theMessage }}'
|