@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.
Files changed (2) hide show
  1. package/README.md +96 -67
  2. 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
- - Access tool results using call IDs via `runtime.tools`
14
- - Access tool results using call indices
15
- - Retrieve data from previous transitions
16
- - Create custom helper functions that access `runtime` for data extraction
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, typed runtime, and a helper function:
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
- @Runtime()
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
- ### Accessing Tool Results
57
-
58
- #### 1. Using Call IDs
42
+ ### Key Concepts
59
43
 
60
- Assign a unique `id` to a tool call, then reference it via `runtime.tools.<transition_id>.<call_id>.data`:
44
+ #### 1. Calling Tools and Storing Results
61
45
 
62
- ```yaml
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
- - tool: createChatMessage
69
- args:
70
- role: 'assistant'
71
- content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
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
- #### 2. Using Call Indices
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
- Access tool results by their position (zero-indexed) within the transition:
68
+ #### 2. Accessing Data Across Transitions
77
69
 
78
- ```yaml
79
- - tool: createChatMessage
80
- args:
81
- role: 'assistant'
82
- content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
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. Across Transitions
87
+ #### 3. Private Helper Methods
86
88
 
87
- Tool results persist and can be accessed from subsequent transitions using the same `runtime.tools` patterns:
89
+ Define private methods on the workflow class to encapsulate data access logic:
88
90
 
89
- ```yaml
90
- # In a later transition
91
- - id: access_data
92
- from: data_created
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
- #### 4. Using Helper Functions
97
+ These are standard TypeScript methods -- no decorator needed. Call them from any transition method using `this.theMessage()`.
102
98
 
103
- Define custom helper functions in your workflow class that access `this.runtime` directly:
99
+ ### Complete Workflow
104
100
 
105
101
  ```typescript
106
- @DefineHelper()
107
- theMessage(): string {
108
- return this.runtime.tools.create_some_data.say_hello.data;
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
- Then use them in your YAML configuration (no arguments needed):
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
- ```yaml
115
- - tool: createChatMessage
116
- args:
117
- role: 'assistant'
118
- content: 'Data access using custom helper: {{ theMessage }}'
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/core` - Core framework functionality
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.0",
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.0",
35
- "@loopstack/core": "^0.25.0",
36
- "@loopstack/create-chat-message-tool": "^0.21.0",
37
- "@loopstack/create-value-tool": "^0.21.0",
38
- "@nestjs/common": "^11.1.14",
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$": "ts-jest"
54
+ "^.+\\.ts$": [
55
+ "ts-jest",
56
+ {
57
+ "tsconfig": "tsconfig.spec.json"
58
+ }
59
+ ]
55
60
  },
56
61
  "collectCoverageFrom": [
57
62
  "**/*.(t|j)s"