@loopstack/accessing-tool-results-example-workflow 0.20.7 → 0.21.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/README.md +97 -68
- package/dist/workflow-tool-results.ui.yaml +1 -0
- package/dist/workflow-tool-results.workflow.d.ts +6 -11
- package/dist/workflow-tool-results.workflow.d.ts.map +1 -1
- package/dist/workflow-tool-results.workflow.js +34 -10
- package/dist/workflow-tool-results.workflow.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/workflow-tool-results.workflow.spec.ts +19 -37
- package/src/workflow-tool-results.ui.yaml +1 -0
- package/src/workflow-tool-results.workflow.ts +36 -17
- package/dist/workflow-tool-results.workflow.yaml +0 -40
- package/src/workflow-tool-results.workflow.yaml +0 -40
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@ The Tool Results Example Workflow shows how to retrieve and use data returned by
|
|
|
10
10
|
|
|
11
11
|
By using this workflow as a reference, you'll learn how to:
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- Create
|
|
13
|
+
- Call tools using `@InjectTool()` and access their return values directly
|
|
14
|
+
- Store tool results as workflow instance properties for use across transitions
|
|
15
|
+
- Access stored data in later transitions via instance properties
|
|
16
|
+
- Create private helper methods to encapsulate data access logic
|
|
17
17
|
|
|
18
18
|
This example is useful for developers learning to build data-driven workflows that need to pass information between steps.
|
|
19
19
|
|
|
@@ -25,104 +25,133 @@ See [SETUP.md](./SETUP.md) for installation and setup instructions.
|
|
|
25
25
|
|
|
26
26
|
### Workflow Class
|
|
27
27
|
|
|
28
|
-
The workflow declares tools
|
|
28
|
+
The workflow extends `BaseWorkflow` and declares tools via `@InjectTool()`. Tool results are stored as instance properties and accessed across transitions:
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
31
|
@Workflow({
|
|
32
|
-
|
|
32
|
+
uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
|
|
33
33
|
})
|
|
34
|
-
export class WorkflowToolResultsWorkflow {
|
|
34
|
+
export class WorkflowToolResultsWorkflow extends BaseWorkflow {
|
|
35
35
|
@InjectTool() private createValue: CreateValue;
|
|
36
36
|
@InjectTool() private createChatMessage: CreateChatMessage;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
runtime: {
|
|
40
|
-
tools: {
|
|
41
|
-
create_some_data: {
|
|
42
|
-
say_hello: {
|
|
43
|
-
data: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
@DefineHelper()
|
|
50
|
-
theMessage(): string {
|
|
51
|
-
return this.runtime.tools.create_some_data.say_hello.data;
|
|
52
|
-
}
|
|
38
|
+
storedMessage?: string;
|
|
53
39
|
}
|
|
54
40
|
```
|
|
55
41
|
|
|
56
|
-
###
|
|
57
|
-
|
|
58
|
-
#### 1. Using Call IDs
|
|
42
|
+
### Key Concepts
|
|
59
43
|
|
|
60
|
-
|
|
44
|
+
#### 1. Calling Tools and Storing Results
|
|
61
45
|
|
|
62
|
-
|
|
63
|
-
- id: say_hello
|
|
64
|
-
tool: createValue
|
|
65
|
-
args:
|
|
66
|
-
input: 'Hello World.'
|
|
46
|
+
In a transition method, call a tool with `this.tool.call(args)` and store the result as an instance property:
|
|
67
47
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
```typescript
|
|
49
|
+
@Initial({ to: 'data_created' })
|
|
50
|
+
async createSomeData() {
|
|
51
|
+
const result = await this.createValue.call({ input: 'Hello World.' });
|
|
52
|
+
this.storedMessage = result.data as string;
|
|
53
|
+
|
|
54
|
+
await this.createChatMessage.call({
|
|
55
|
+
role: 'assistant',
|
|
56
|
+
content: `Data from specific call id: ${this.storedMessage}`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await this.createChatMessage.call({
|
|
60
|
+
role: 'assistant',
|
|
61
|
+
content: `Data from first tool call: ${this.storedMessage}`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
72
64
|
```
|
|
73
65
|
|
|
74
|
-
|
|
66
|
+
The `createValue` tool returns a `ToolResult` object with a `data` property containing the output. This value is stored in `this.storedMessage` for later use.
|
|
67
|
+
|
|
68
|
+
#### 2. Accessing Data Across Transitions
|
|
75
69
|
|
|
76
|
-
|
|
70
|
+
Instance properties persist across transitions. In a subsequent `@Final` method, the stored data is still available:
|
|
77
71
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
```typescript
|
|
73
|
+
@Final({ from: 'data_created' })
|
|
74
|
+
async accessData() {
|
|
75
|
+
await this.createChatMessage.call({
|
|
76
|
+
role: 'assistant',
|
|
77
|
+
content: `Data from previous transition: ${this.storedMessage}`,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await this.createChatMessage.call({
|
|
81
|
+
role: 'assistant',
|
|
82
|
+
content: `Data access using custom helper: ${this.theMessage()}`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
83
85
|
```
|
|
84
86
|
|
|
85
|
-
#### 3.
|
|
87
|
+
#### 3. Private Helper Methods
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
Define private methods on the workflow class to encapsulate data access logic:
|
|
88
90
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
to: end
|
|
94
|
-
call:
|
|
95
|
-
- tool: createChatMessage
|
|
96
|
-
args:
|
|
97
|
-
role: 'assistant'
|
|
98
|
-
content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
91
|
+
```typescript
|
|
92
|
+
private theMessage(): string {
|
|
93
|
+
return this.storedMessage!;
|
|
94
|
+
}
|
|
99
95
|
```
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
These are standard TypeScript methods -- no decorator needed. Call them from any transition method using `this.theMessage()`.
|
|
102
98
|
|
|
103
|
-
|
|
99
|
+
### Complete Workflow
|
|
104
100
|
|
|
105
101
|
```typescript
|
|
106
|
-
@
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
import { BaseWorkflow, Final, Initial, InjectTool, Workflow } from '@loopstack/common';
|
|
103
|
+
import { CreateChatMessage } from '@loopstack/create-chat-message-tool';
|
|
104
|
+
import { CreateValue } from '@loopstack/create-value-tool';
|
|
105
|
+
|
|
106
|
+
@Workflow({
|
|
107
|
+
uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
|
|
108
|
+
})
|
|
109
|
+
export class WorkflowToolResultsWorkflow extends BaseWorkflow {
|
|
110
|
+
@InjectTool() private createValue: CreateValue;
|
|
111
|
+
@InjectTool() private createChatMessage: CreateChatMessage;
|
|
112
|
+
|
|
113
|
+
storedMessage?: string;
|
|
114
|
+
|
|
115
|
+
@Initial({ to: 'data_created' })
|
|
116
|
+
async createSomeData() {
|
|
117
|
+
const result = await this.createValue.call({ input: 'Hello World.' });
|
|
118
|
+
this.storedMessage = result.data as string;
|
|
111
119
|
|
|
112
|
-
|
|
120
|
+
await this.createChatMessage.call({
|
|
121
|
+
role: 'assistant',
|
|
122
|
+
content: `Data from specific call id: ${this.storedMessage}`,
|
|
123
|
+
});
|
|
113
124
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
await this.createChatMessage.call({
|
|
126
|
+
role: 'assistant',
|
|
127
|
+
content: `Data from first tool call: ${this.storedMessage}`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Final({ from: 'data_created' })
|
|
132
|
+
async accessData() {
|
|
133
|
+
await this.createChatMessage.call({
|
|
134
|
+
role: 'assistant',
|
|
135
|
+
content: `Data from previous transition: ${this.storedMessage}`,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await this.createChatMessage.call({
|
|
139
|
+
role: 'assistant',
|
|
140
|
+
content: `Data access using custom helper: ${this.theMessage()}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private theMessage(): string {
|
|
145
|
+
return this.storedMessage!;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
119
148
|
```
|
|
120
149
|
|
|
121
150
|
## Dependencies
|
|
122
151
|
|
|
123
152
|
This workflow uses the following Loopstack modules:
|
|
124
153
|
|
|
125
|
-
- `@loopstack/
|
|
154
|
+
- `@loopstack/common` - Base classes, decorators, and tool injection
|
|
126
155
|
- `@loopstack/create-chat-message-tool` - Provides `CreateChatMessage` tool
|
|
127
156
|
- `@loopstack/create-value-tool` - Provides `CreateValue` tool
|
|
128
157
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
title: 'Workflow Tool Result'
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { BaseWorkflow } from '@loopstack/common';
|
|
2
|
+
export declare class WorkflowToolResultsWorkflow extends BaseWorkflow {
|
|
2
3
|
private createValue;
|
|
3
4
|
private createChatMessage;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
data: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
theMessage(): string;
|
|
5
|
+
storedMessage?: string;
|
|
6
|
+
createSomeData(): Promise<void>;
|
|
7
|
+
accessData(): Promise<void>;
|
|
8
|
+
private theMessage;
|
|
14
9
|
}
|
|
15
10
|
//# 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":"AAAA,OAAO,EAAE,YAAY,EAAwC,MAAM,mBAAmB,CAAC;AAIvF,qBAGa,2BAA4B,SAAQ,YAAY;IAC7C,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,iBAAiB,CAAoB;IAE3D,aAAa,CAAC,EAAE,MAAM,CAAC;IAGjB,cAAc;IAgBd,UAAU;IAYhB,OAAO,CAAC,UAAU;CAGnB"}
|
|
@@ -13,12 +13,34 @@ exports.WorkflowToolResultsWorkflow = void 0;
|
|
|
13
13
|
const common_1 = require("@loopstack/common");
|
|
14
14
|
const create_chat_message_tool_1 = require("@loopstack/create-chat-message-tool");
|
|
15
15
|
const create_value_tool_1 = require("@loopstack/create-value-tool");
|
|
16
|
-
let WorkflowToolResultsWorkflow = class WorkflowToolResultsWorkflow {
|
|
16
|
+
let WorkflowToolResultsWorkflow = class WorkflowToolResultsWorkflow extends common_1.BaseWorkflow {
|
|
17
17
|
createValue;
|
|
18
18
|
createChatMessage;
|
|
19
|
-
|
|
19
|
+
storedMessage;
|
|
20
|
+
async createSomeData() {
|
|
21
|
+
const result = await this.createValue.call({ input: 'Hello World.' });
|
|
22
|
+
this.storedMessage = result.data;
|
|
23
|
+
await this.createChatMessage.call({
|
|
24
|
+
role: 'assistant',
|
|
25
|
+
content: `Data from specific call id: ${this.storedMessage}`,
|
|
26
|
+
});
|
|
27
|
+
await this.createChatMessage.call({
|
|
28
|
+
role: 'assistant',
|
|
29
|
+
content: `Data from first tool call: ${this.storedMessage}`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async accessData() {
|
|
33
|
+
await this.createChatMessage.call({
|
|
34
|
+
role: 'assistant',
|
|
35
|
+
content: `Data from previous transition: ${this.storedMessage}`,
|
|
36
|
+
});
|
|
37
|
+
await this.createChatMessage.call({
|
|
38
|
+
role: 'assistant',
|
|
39
|
+
content: `Data access using custom helper: ${this.theMessage()}`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
20
42
|
theMessage() {
|
|
21
|
-
return this.
|
|
43
|
+
return this.storedMessage;
|
|
22
44
|
}
|
|
23
45
|
};
|
|
24
46
|
exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow;
|
|
@@ -31,18 +53,20 @@ __decorate([
|
|
|
31
53
|
__metadata("design:type", create_chat_message_tool_1.CreateChatMessage)
|
|
32
54
|
], WorkflowToolResultsWorkflow.prototype, "createChatMessage", void 0);
|
|
33
55
|
__decorate([
|
|
34
|
-
(0, common_1.
|
|
35
|
-
__metadata("design:type",
|
|
36
|
-
|
|
56
|
+
(0, common_1.Initial)({ to: 'data_created' }),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", []),
|
|
59
|
+
__metadata("design:returntype", Promise)
|
|
60
|
+
], WorkflowToolResultsWorkflow.prototype, "createSomeData", null);
|
|
37
61
|
__decorate([
|
|
38
|
-
(0, common_1.
|
|
62
|
+
(0, common_1.Final)({ from: 'data_created' }),
|
|
39
63
|
__metadata("design:type", Function),
|
|
40
64
|
__metadata("design:paramtypes", []),
|
|
41
|
-
__metadata("design:returntype",
|
|
42
|
-
], WorkflowToolResultsWorkflow.prototype, "
|
|
65
|
+
__metadata("design:returntype", Promise)
|
|
66
|
+
], WorkflowToolResultsWorkflow.prototype, "accessData", null);
|
|
43
67
|
exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow = __decorate([
|
|
44
68
|
(0, common_1.Workflow)({
|
|
45
|
-
|
|
69
|
+
uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
|
|
46
70
|
})
|
|
47
71
|
], WorkflowToolResultsWorkflow);
|
|
48
72
|
//# sourceMappingURL=workflow-tool-results.workflow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-tool-results.workflow.js","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"workflow-tool-results.workflow.js","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuF;AACvF,kFAAwE;AACxE,oEAA2D;AAKpD,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,qBAAY;IACrC,WAAW,CAAc;IACzB,iBAAiB,CAAoB;IAE3D,aAAa,CAAU;IAGjB,AAAN,KAAK,CAAC,cAAc;QAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,IAAc,CAAC;QAE3C,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,+BAA+B,IAAI,CAAC,aAAa,EAAE;SAC7D,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,8BAA8B,IAAI,CAAC,aAAa,EAAE;SAC5D,CAAC,CAAC;IACL,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,kCAAkC,IAAI,CAAC,aAAa,EAAE;SAChE,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,oCAAoC,IAAI,CAAC,UAAU,EAAE,EAAE;SACjE,CAAC,CAAC;IACL,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,aAAc,CAAC;IAC7B,CAAC;CACF,CAAA;AAtCY,kEAA2B;AAChB;IAArB,IAAA,mBAAU,GAAE;8BAAsB,+BAAW;gEAAC;AACzB;IAArB,IAAA,mBAAU,GAAE;8BAA4B,4CAAiB;sEAAC;AAKrD;IADL,IAAA,gBAAO,EAAC,EAAE,EAAE,EAAE,cAAc,EAAE,CAAC;;;;iEAc/B;AAGK;IADL,IAAA,cAAK,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;;;;6DAW/B;sCAjCU,2BAA2B;IAHvC,IAAA,iBAAQ,EAAC;QACR,QAAQ,EAAE,SAAS,GAAG,gCAAgC;KACvD,CAAC;GACW,2BAA2B,CAsCvC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"tool",
|
|
11
11
|
"workflow"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.21.1",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Jakob Klippel",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"watch": "nest build --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loopstack/common": "^0.
|
|
35
|
-
"@loopstack/core": "^0.
|
|
36
|
-
"@loopstack/create-chat-message-tool": "^0.
|
|
37
|
-
"@loopstack/create-value-tool": "^0.
|
|
34
|
+
"@loopstack/common": "^0.25.0",
|
|
35
|
+
"@loopstack/core": "^0.25.0",
|
|
36
|
+
"@loopstack/create-chat-message-tool": "^0.21.1",
|
|
37
|
+
"@loopstack/create-value-tool": "^0.21.1",
|
|
38
38
|
"@nestjs/common": "^11.1.14",
|
|
39
39
|
"zod": "^4.3.6"
|
|
40
40
|
},
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TestingModule } from '@nestjs/testing';
|
|
2
|
-
import { RunContext, getBlockHelpers } from '@loopstack/common';
|
|
3
2
|
import { LoopCoreModule, WorkflowProcessorService } from '@loopstack/core';
|
|
4
3
|
import { CreateChatMessage, CreateChatMessageToolModule } from '@loopstack/create-chat-message-tool';
|
|
5
4
|
import { CreateValue, CreateValueToolModule } from '@loopstack/create-value-tool';
|
|
6
|
-
import { ToolMock, createWorkflowTest } from '@loopstack/testing';
|
|
5
|
+
import { ToolMock, createStatelessContext, createWorkflowTest } from '@loopstack/testing';
|
|
7
6
|
import { WorkflowToolResultsWorkflow } from '../workflow-tool-results.workflow';
|
|
8
7
|
|
|
9
8
|
describe('WorkflowToolResultsWorkflow', () => {
|
|
@@ -37,81 +36,64 @@ describe('WorkflowToolResultsWorkflow', () => {
|
|
|
37
36
|
expect(workflow).toBeDefined();
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
it('should have extractMessage helper', () => {
|
|
41
|
-
expect(getBlockHelpers(workflow)).toContain('theMessage');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
39
|
describe('tool result access', () => {
|
|
45
40
|
it('should access tool results by call id and index in same transition', async () => {
|
|
46
|
-
const context =
|
|
47
|
-
mockCreateValue.
|
|
48
|
-
mockCreateChatMessage.
|
|
41
|
+
const context = createStatelessContext();
|
|
42
|
+
mockCreateValue.call.mockResolvedValue({ data: 'Hello World.' });
|
|
43
|
+
mockCreateChatMessage.call.mockResolvedValue({ data: undefined });
|
|
49
44
|
|
|
50
45
|
await processor.process(workflow, {}, context);
|
|
51
46
|
|
|
52
47
|
// Verify CreateValue was called
|
|
53
|
-
expect(mockCreateValue.
|
|
54
|
-
{ input: 'Hello World.' },
|
|
55
|
-
expect.anything(),
|
|
56
|
-
expect.anything(),
|
|
57
|
-
expect.anything(),
|
|
58
|
-
);
|
|
48
|
+
expect(mockCreateValue.call).toHaveBeenCalledWith({ input: 'Hello World.' }, undefined);
|
|
59
49
|
|
|
60
50
|
// Verify CreateChatMessage received resolved template values
|
|
61
|
-
expect(mockCreateChatMessage.
|
|
51
|
+
expect(mockCreateChatMessage.call).toHaveBeenCalledWith(
|
|
62
52
|
{
|
|
63
53
|
role: 'assistant',
|
|
64
54
|
content: 'Data from specific call id: Hello World.',
|
|
65
55
|
},
|
|
66
|
-
|
|
67
|
-
expect.anything(),
|
|
68
|
-
expect.anything(),
|
|
56
|
+
undefined,
|
|
69
57
|
);
|
|
70
58
|
|
|
71
|
-
expect(mockCreateChatMessage.
|
|
59
|
+
expect(mockCreateChatMessage.call).toHaveBeenCalledWith(
|
|
72
60
|
{
|
|
73
61
|
role: 'assistant',
|
|
74
62
|
content: 'Data from first tool call: Hello World.',
|
|
75
63
|
},
|
|
76
|
-
|
|
77
|
-
expect.anything(),
|
|
78
|
-
expect.anything(),
|
|
64
|
+
undefined,
|
|
79
65
|
);
|
|
80
66
|
});
|
|
81
67
|
|
|
82
68
|
it('should access tool results from previous transition', async () => {
|
|
83
|
-
const context =
|
|
84
|
-
mockCreateValue.
|
|
85
|
-
mockCreateChatMessage.
|
|
69
|
+
const context = createStatelessContext();
|
|
70
|
+
mockCreateValue.call.mockResolvedValue({ data: 'Hello World.' });
|
|
71
|
+
mockCreateChatMessage.call.mockResolvedValue({ data: undefined });
|
|
86
72
|
|
|
87
73
|
await processor.process(workflow, {}, context);
|
|
88
74
|
|
|
89
|
-
expect(mockCreateChatMessage.
|
|
75
|
+
expect(mockCreateChatMessage.call).toHaveBeenCalledWith(
|
|
90
76
|
{
|
|
91
77
|
role: 'assistant',
|
|
92
78
|
content: 'Data from previous transition: Hello World.',
|
|
93
79
|
},
|
|
94
|
-
|
|
95
|
-
expect.anything(),
|
|
96
|
-
expect.anything(),
|
|
80
|
+
undefined,
|
|
97
81
|
);
|
|
98
82
|
});
|
|
99
83
|
|
|
100
84
|
it('should access tool results using custom helper', async () => {
|
|
101
|
-
const context =
|
|
102
|
-
mockCreateValue.
|
|
103
|
-
mockCreateChatMessage.
|
|
85
|
+
const context = createStatelessContext();
|
|
86
|
+
mockCreateValue.call.mockResolvedValue({ data: 'Hello World.' });
|
|
87
|
+
mockCreateChatMessage.call.mockResolvedValue({ data: undefined });
|
|
104
88
|
|
|
105
89
|
await processor.process(workflow, {}, context);
|
|
106
90
|
|
|
107
|
-
expect(mockCreateChatMessage.
|
|
91
|
+
expect(mockCreateChatMessage.call).toHaveBeenCalledWith(
|
|
108
92
|
{
|
|
109
93
|
role: 'assistant',
|
|
110
94
|
content: 'Data access using custom helper: Hello World.',
|
|
111
95
|
},
|
|
112
|
-
|
|
113
|
-
expect.anything(),
|
|
114
|
-
expect.anything(),
|
|
96
|
+
undefined,
|
|
115
97
|
);
|
|
116
98
|
});
|
|
117
99
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
title: 'Workflow Tool Result'
|
|
@@ -1,27 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseWorkflow, Final, Initial, InjectTool, Workflow } from '@loopstack/common';
|
|
2
2
|
import { CreateChatMessage } from '@loopstack/create-chat-message-tool';
|
|
3
3
|
import { CreateValue } from '@loopstack/create-value-tool';
|
|
4
4
|
|
|
5
5
|
@Workflow({
|
|
6
|
-
|
|
6
|
+
uiConfig: __dirname + '/workflow-tool-results.ui.yaml',
|
|
7
7
|
})
|
|
8
|
-
export class WorkflowToolResultsWorkflow {
|
|
8
|
+
export class WorkflowToolResultsWorkflow extends BaseWorkflow {
|
|
9
9
|
@InjectTool() private createValue: CreateValue;
|
|
10
10
|
@InjectTool() private createChatMessage: CreateChatMessage;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
storedMessage?: string;
|
|
13
|
+
|
|
14
|
+
@Initial({ to: 'data_created' })
|
|
15
|
+
async createSomeData() {
|
|
16
|
+
const result = await this.createValue.call({ input: 'Hello World.' });
|
|
17
|
+
this.storedMessage = result.data as string;
|
|
18
|
+
|
|
19
|
+
await this.createChatMessage.call({
|
|
20
|
+
role: 'assistant',
|
|
21
|
+
content: `Data from specific call id: ${this.storedMessage}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await this.createChatMessage.call({
|
|
25
|
+
role: 'assistant',
|
|
26
|
+
content: `Data from first tool call: ${this.storedMessage}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Final({ from: 'data_created' })
|
|
31
|
+
async accessData() {
|
|
32
|
+
await this.createChatMessage.call({
|
|
33
|
+
role: 'assistant',
|
|
34
|
+
content: `Data from previous transition: ${this.storedMessage}`,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await this.createChatMessage.call({
|
|
38
|
+
role: 'assistant',
|
|
39
|
+
content: `Data access using custom helper: ${this.theMessage()}`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private theMessage(): string {
|
|
44
|
+
return this.storedMessage!;
|
|
26
45
|
}
|
|
27
46
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
title: 'Workflow Tool Result'
|
|
2
|
-
|
|
3
|
-
transitions:
|
|
4
|
-
- id: create_some_data
|
|
5
|
-
from: start
|
|
6
|
-
to: data_created
|
|
7
|
-
call:
|
|
8
|
-
# Create test data and return it in the tool result
|
|
9
|
-
- id: say_hello
|
|
10
|
-
tool: createValue
|
|
11
|
-
args:
|
|
12
|
-
input: 'Hello World.'
|
|
13
|
-
|
|
14
|
-
# Access the data using the call id as identifier
|
|
15
|
-
- tool: createChatMessage
|
|
16
|
-
args:
|
|
17
|
-
role: 'assistant'
|
|
18
|
-
content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
19
|
-
|
|
20
|
-
# Access the data using the call index
|
|
21
|
-
- tool: createChatMessage
|
|
22
|
-
args:
|
|
23
|
-
role: 'assistant'
|
|
24
|
-
content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
|
|
25
|
-
|
|
26
|
-
- id: access_data
|
|
27
|
-
from: data_created
|
|
28
|
-
to: end
|
|
29
|
-
call:
|
|
30
|
-
# Access the data from a previous transition using transition and call id
|
|
31
|
-
- tool: createChatMessage
|
|
32
|
-
args:
|
|
33
|
-
role: 'assistant'
|
|
34
|
-
content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
35
|
-
|
|
36
|
-
# Access the data using a custom helper function of the workflow
|
|
37
|
-
- tool: createChatMessage
|
|
38
|
-
args:
|
|
39
|
-
role: 'assistant'
|
|
40
|
-
content: 'Data access using custom helper: {{ theMessage }}'
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
title: 'Workflow Tool Result'
|
|
2
|
-
|
|
3
|
-
transitions:
|
|
4
|
-
- id: create_some_data
|
|
5
|
-
from: start
|
|
6
|
-
to: data_created
|
|
7
|
-
call:
|
|
8
|
-
# Create test data and return it in the tool result
|
|
9
|
-
- id: say_hello
|
|
10
|
-
tool: createValue
|
|
11
|
-
args:
|
|
12
|
-
input: 'Hello World.'
|
|
13
|
-
|
|
14
|
-
# Access the data using the call id as identifier
|
|
15
|
-
- tool: createChatMessage
|
|
16
|
-
args:
|
|
17
|
-
role: 'assistant'
|
|
18
|
-
content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
19
|
-
|
|
20
|
-
# Access the data using the call index
|
|
21
|
-
- tool: createChatMessage
|
|
22
|
-
args:
|
|
23
|
-
role: 'assistant'
|
|
24
|
-
content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
|
|
25
|
-
|
|
26
|
-
- id: access_data
|
|
27
|
-
from: data_created
|
|
28
|
-
to: end
|
|
29
|
-
call:
|
|
30
|
-
# Access the data from a previous transition using transition and call id
|
|
31
|
-
- tool: createChatMessage
|
|
32
|
-
args:
|
|
33
|
-
role: 'assistant'
|
|
34
|
-
content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
|
|
35
|
-
|
|
36
|
-
# Access the data using a custom helper function of the workflow
|
|
37
|
-
- tool: createChatMessage
|
|
38
|
-
args:
|
|
39
|
-
role: 'assistant'
|
|
40
|
-
content: 'Data access using custom helper: {{ theMessage }}'
|