@loopstack/accessing-tool-results-example-workflow 0.20.0 → 0.20.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 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
13
+ - Access tool results using call IDs via `runtime.tools`
14
14
  - Access tool results using call indices
15
15
  - Retrieve data from previous transitions
16
- - Create custom helper functions for data extraction
16
+ - Create custom helper functions that access `runtime` for data extraction
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
 
@@ -48,18 +48,48 @@ Use npm install if you want to use and maintain the module as node dependency.
48
48
 
49
49
  > This step is automatically done for you when using the `loopstack add` command.
50
50
 
51
- - Add `AccessingToolResultsExampleModule` to the imports of `default.module.ts` or any other custom module.
51
+ - Add `ToolResultsExampleModule` to the imports of `default.module.ts` or any other custom module.
52
52
  - Inject the `WorkflowToolResultsWorkflow` workflow to your workspace class using the `@InjectWorkflow()` decorator.
53
53
 
54
54
  See here for more information about working with [Modules](https://loopstack.ai/docs/building-with-loopstack/creating-a-module) and [Workspaces](https://loopstack.ai/docs/building-with-loopstack/creating-workspaces)
55
55
 
56
56
  ## How It Works
57
57
 
58
+ ### Workflow Class
59
+
60
+ The workflow declares tools, typed runtime, and a helper function:
61
+
62
+ ```typescript
63
+ @Workflow({
64
+ configFile: __dirname + '/workflow-tool-results.workflow.yaml',
65
+ })
66
+ export class WorkflowToolResultsWorkflow {
67
+ @InjectTool() private createValue: CreateValue;
68
+ @InjectTool() private createChatMessage: CreateChatMessage;
69
+
70
+ @Runtime()
71
+ runtime: {
72
+ tools: {
73
+ create_some_data: {
74
+ say_hello: {
75
+ data: string;
76
+ };
77
+ };
78
+ };
79
+ };
80
+
81
+ @DefineHelper()
82
+ theMessage(): string {
83
+ return this.runtime.tools.create_some_data.say_hello.data;
84
+ }
85
+ }
86
+ ```
87
+
58
88
  ### Accessing Tool Results
59
89
 
60
90
  #### 1. Using Call IDs
61
91
 
62
- Assign a unique `id` to a tool call, then reference it via `metadata.tools.<transition_id>.<call_id>.data`:
92
+ Assign a unique `id` to a tool call, then reference it via `runtime.tools.<transition_id>.<call_id>.data`:
63
93
 
64
94
  ```yaml
65
95
  - id: say_hello
@@ -69,7 +99,8 @@ Assign a unique `id` to a tool call, then reference it via `metadata.tools.<tran
69
99
 
70
100
  - tool: createChatMessage
71
101
  args:
72
- content: '{{ metadata.tools.create_some_data.say_hello.data }}'
102
+ role: 'assistant'
103
+ content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
73
104
  ```
74
105
 
75
106
  #### 2. Using Call Indices
@@ -79,37 +110,44 @@ Access tool results by their position (zero-indexed) within the transition:
79
110
  ```yaml
80
111
  - tool: createChatMessage
81
112
  args:
82
- content: '{{ metadata.tools.create_some_data.0.data }}'
113
+ role: 'assistant'
114
+ content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
83
115
  ```
84
116
 
85
117
  #### 3. Across Transitions
86
118
 
87
- Tool results persist and can be accessed from subsequent transitions using the same patterns:
119
+ Tool results persist and can be accessed from subsequent transitions using the same `runtime.tools` patterns:
88
120
 
89
121
  ```yaml
90
122
  # In a later transition
91
- - tool: createChatMessage
92
- args:
93
- content: '{{ metadata.tools.create_some_data.say_hello.data }}'
123
+ - id: access_data
124
+ from: data_created
125
+ to: end
126
+ call:
127
+ - tool: createChatMessage
128
+ args:
129
+ role: 'assistant'
130
+ content: 'Data from previous transition: {{ runtime.tools.create_some_data.say_hello.data }}'
94
131
  ```
95
132
 
96
133
  #### 4. Using Helper Functions
97
134
 
98
- Define custom helper functions in your workflow class for complex data extraction:
135
+ Define custom helper functions in your workflow class that access `this.runtime` directly:
99
136
 
100
137
  ```typescript
101
138
  @DefineHelper()
102
- extractMessage(metadata: WorkflowMetadataInterface): string {
103
- return metadata.tools.create_some_data.say_hello.data;
139
+ theMessage(): string {
140
+ return this.runtime.tools.create_some_data.say_hello.data;
104
141
  }
105
142
  ```
106
143
 
107
- Then use them in your YAML configuration:
144
+ Then use them in your YAML configuration (no arguments needed):
108
145
 
109
146
  ```yaml
110
147
  - tool: createChatMessage
111
148
  args:
112
- content: '{{ extractMessage metadata }}'
149
+ role: 'assistant'
150
+ content: 'Data access using custom helper: {{ theMessage }}'
113
151
  ```
114
152
 
115
153
  ## Dependencies
@@ -117,7 +155,7 @@ Then use them in your YAML configuration:
117
155
  This workflow uses the following Loopstack modules:
118
156
 
119
157
  - `@loopstack/core` - Core framework functionality
120
- - `@loopstack/core-ui-module` - Provides `CreateChatMessage` tool
158
+ - `@loopstack/create-chat-message-tool` - Provides `CreateChatMessage` tool
121
159
  - `@loopstack/create-value-tool` - Provides `CreateValue` tool
122
160
 
123
161
  ## About
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"workflow-tool-results.workflow.d.ts","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":"AAIA,qBAGa,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"}
@@ -10,8 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.WorkflowToolResultsWorkflow = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const common_2 = require("@loopstack/common");
13
+ const common_1 = require("@loopstack/common");
15
14
  const create_chat_message_tool_1 = require("@loopstack/create-chat-message-tool");
16
15
  const create_value_tool_1 = require("@loopstack/create-value-tool");
17
16
  let WorkflowToolResultsWorkflow = class WorkflowToolResultsWorkflow {
@@ -24,26 +23,25 @@ let WorkflowToolResultsWorkflow = class WorkflowToolResultsWorkflow {
24
23
  };
25
24
  exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow;
26
25
  __decorate([
27
- (0, common_2.InjectTool)(),
26
+ (0, common_1.InjectTool)(),
28
27
  __metadata("design:type", create_value_tool_1.CreateValue)
29
28
  ], WorkflowToolResultsWorkflow.prototype, "createValue", void 0);
30
29
  __decorate([
31
- (0, common_2.InjectTool)(),
30
+ (0, common_1.InjectTool)(),
32
31
  __metadata("design:type", create_chat_message_tool_1.CreateChatMessage)
33
32
  ], WorkflowToolResultsWorkflow.prototype, "createChatMessage", void 0);
34
33
  __decorate([
35
- (0, common_2.Runtime)(),
34
+ (0, common_1.Runtime)(),
36
35
  __metadata("design:type", Object)
37
36
  ], WorkflowToolResultsWorkflow.prototype, "runtime", void 0);
38
37
  __decorate([
39
- (0, common_2.DefineHelper)(),
38
+ (0, common_1.DefineHelper)(),
40
39
  __metadata("design:type", Function),
41
40
  __metadata("design:paramtypes", []),
42
41
  __metadata("design:returntype", String)
43
42
  ], WorkflowToolResultsWorkflow.prototype, "theMessage", null);
44
43
  exports.WorkflowToolResultsWorkflow = WorkflowToolResultsWorkflow = __decorate([
45
- (0, common_1.Injectable)(),
46
- (0, common_2.Workflow)({
44
+ (0, common_1.Workflow)({
47
45
  configFile: __dirname + '/workflow-tool-results.workflow.yaml',
48
46
  })
49
47
  ], WorkflowToolResultsWorkflow);
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"workflow-tool-results.workflow.js","sourceRoot":"","sources":["../src/workflow-tool-results.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAgF;AAChF,kFAAwE;AACxE,oEAA2D;AAKpD,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;IAHvC,IAAA,iBAAQ,EAAC;QACR,UAAU,EAAE,SAAS,GAAG,sCAAsC;KAC/D,CAAC;GACW,2BAA2B,CAmBvC"}
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "tool",
11
11
  "workflow"
12
12
  ],
13
- "version": "0.20.0",
13
+ "version": "0.20.1",
14
14
  "license": "Apache-2.0",
15
15
  "author": {
16
16
  "name": "Jakob Klippel",
@@ -32,9 +32,9 @@
32
32
  },
33
33
  "dependencies": {
34
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",
35
+ "@loopstack/core-ui-module": "^0.20.1",
36
+ "@loopstack/create-chat-message-tool": "^0.20.1",
37
+ "@loopstack/create-value-tool": "^0.20.1",
38
38
  "@nestjs/common": "^11.1.12",
39
39
  "zod": "^4.3.5"
40
40
  },
@@ -1,9 +1,7 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { DefineHelper, InjectTool, Runtime, Workflow } from '@loopstack/common';
3
2
  import { CreateChatMessage } from '@loopstack/create-chat-message-tool';
4
3
  import { CreateValue } from '@loopstack/create-value-tool';
5
4
 
6
- @Injectable()
7
5
  @Workflow({
8
6
  configFile: __dirname + '/workflow-tool-results.workflow.yaml',
9
7
  })