@loopstack/accessing-tool-results-example-workflow 0.21.0 → 0.21.2
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 +96 -67
- package/package.json +12 -7
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.
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
#### 2. Accessing Data Across Transitions
|
|
77
69
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
Instance properties persist across transitions. In a subsequent `@Final` method, the stored data is still available:
|
|
71
|
+
|
|
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';
|
|
111
105
|
|
|
112
|
-
|
|
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;
|
|
119
|
+
|
|
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
|
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"tool",
|
|
11
11
|
"workflow"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.21.
|
|
13
|
+
"version": "0.21.2",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Jakob Klippel",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"watch": "nest build --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loopstack/common": "^0.25.
|
|
35
|
-
"@loopstack/core": "^0.25.
|
|
36
|
-
"@loopstack/create-chat-message-tool": "^0.21.
|
|
37
|
-
"@loopstack/create-value-tool": "^0.21.
|
|
38
|
-
"@nestjs/common": "^11.1.
|
|
34
|
+
"@loopstack/common": "^0.25.1",
|
|
35
|
+
"@loopstack/core": "^0.25.1",
|
|
36
|
+
"@loopstack/create-chat-message-tool": "^0.21.2",
|
|
37
|
+
"@loopstack/create-value-tool": "^0.21.2",
|
|
38
|
+
"@nestjs/common": "^11.1.19",
|
|
39
39
|
"zod": "^4.3.6"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
@@ -51,7 +51,12 @@
|
|
|
51
51
|
"rootDir": "src",
|
|
52
52
|
"testRegex": ".*\\.spec\\.ts$",
|
|
53
53
|
"transform": {
|
|
54
|
-
"^.+\\.ts$":
|
|
54
|
+
"^.+\\.ts$": [
|
|
55
|
+
"ts-jest",
|
|
56
|
+
{
|
|
57
|
+
"tsconfig": "tsconfig.spec.json"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
55
60
|
},
|
|
56
61
|
"collectCoverageFrom": [
|
|
57
62
|
"**/*.(t|j)s"
|