@loopstack/accessing-tool-results-example-workflow 0.20.0 → 0.20.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 CHANGED
@@ -10,56 +10,54 @@ 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
 
20
20
  ## Installation
21
21
 
22
- You can add this module using the `loopstack` cli or via `npm`.
22
+ See [SETUP.md](./SETUP.md) for installation and setup instructions.
23
23
 
24
- ### a) Add Sources via `loopstack add` (recommended)
25
-
26
- ```bash
27
- loopstack add @loopstack/accessing-tool-results-example-workflow
28
- ```
29
-
30
- This command copies the source files into your `src` directory.
24
+ ## How It Works
31
25
 
32
- - It is a great way to explore the code to learn new concepts or add own customizations
33
- - It will set up the module for you, so you do not need to manually update your application
26
+ ### Workflow Class
34
27
 
35
- ### b) Install via `npm install`
28
+ The workflow declares tools, typed runtime, and a helper function:
36
29
 
37
- ```bash
38
- npm install --save @loopstack/accessing-tool-results-example-workflow
30
+ ```typescript
31
+ @Workflow({
32
+ configFile: __dirname + '/workflow-tool-results.workflow.yaml',
33
+ })
34
+ export class WorkflowToolResultsWorkflow {
35
+ @InjectTool() private createValue: CreateValue;
36
+ @InjectTool() private createChatMessage: CreateChatMessage;
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
+ }
53
+ }
39
54
  ```
40
55
 
41
- Use npm install if you want to use and maintain the module as node dependency.
42
-
43
- - Use this, if you do not need to make changes to the code or want to review the source code.
44
-
45
- ## Setup
46
-
47
- ### 1. Manual setup (optional)
48
-
49
- > This step is automatically done for you when using the `loopstack add` command.
50
-
51
- - Add `AccessingToolResultsExampleModule` to the imports of `default.module.ts` or any other custom module.
52
- - Inject the `WorkflowToolResultsWorkflow` workflow to your workspace class using the `@InjectWorkflow()` decorator.
53
-
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
-
56
- ## How It Works
57
-
58
56
  ### Accessing Tool Results
59
57
 
60
58
  #### 1. Using Call IDs
61
59
 
62
- Assign a unique `id` to a tool call, then reference it via `metadata.tools.<transition_id>.<call_id>.data`:
60
+ Assign a unique `id` to a tool call, then reference it via `runtime.tools.<transition_id>.<call_id>.data`:
63
61
 
64
62
  ```yaml
65
63
  - id: say_hello
@@ -69,7 +67,8 @@ Assign a unique `id` to a tool call, then reference it via `metadata.tools.<tran
69
67
 
70
68
  - tool: createChatMessage
71
69
  args:
72
- content: '{{ metadata.tools.create_some_data.say_hello.data }}'
70
+ role: 'assistant'
71
+ content: 'Data from specific call id: {{ runtime.tools.create_some_data.say_hello.data }}'
73
72
  ```
74
73
 
75
74
  #### 2. Using Call Indices
@@ -79,37 +78,44 @@ Access tool results by their position (zero-indexed) within the transition:
79
78
  ```yaml
80
79
  - tool: createChatMessage
81
80
  args:
82
- content: '{{ metadata.tools.create_some_data.0.data }}'
81
+ role: 'assistant'
82
+ content: 'Data from first tool call: {{ runtime.tools.create_some_data.0.data }}'
83
83
  ```
84
84
 
85
85
  #### 3. Across Transitions
86
86
 
87
- Tool results persist and can be accessed from subsequent transitions using the same patterns:
87
+ Tool results persist and can be accessed from subsequent transitions using the same `runtime.tools` patterns:
88
88
 
89
89
  ```yaml
90
90
  # In a later transition
91
- - tool: createChatMessage
92
- args:
93
- content: '{{ metadata.tools.create_some_data.say_hello.data }}'
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 }}'
94
99
  ```
95
100
 
96
101
  #### 4. Using Helper Functions
97
102
 
98
- Define custom helper functions in your workflow class for complex data extraction:
103
+ Define custom helper functions in your workflow class that access `this.runtime` directly:
99
104
 
100
105
  ```typescript
101
106
  @DefineHelper()
102
- extractMessage(metadata: WorkflowMetadataInterface): string {
103
- return metadata.tools.create_some_data.say_hello.data;
107
+ theMessage(): string {
108
+ return this.runtime.tools.create_some_data.say_hello.data;
104
109
  }
105
110
  ```
106
111
 
107
- Then use them in your YAML configuration:
112
+ Then use them in your YAML configuration (no arguments needed):
108
113
 
109
114
  ```yaml
110
115
  - tool: createChatMessage
111
116
  args:
112
- content: '{{ extractMessage metadata }}'
117
+ role: 'assistant'
118
+ content: 'Data access using custom helper: {{ theMessage }}'
113
119
  ```
114
120
 
115
121
  ## Dependencies
@@ -117,7 +123,7 @@ Then use them in your YAML configuration:
117
123
  This workflow uses the following Loopstack modules:
118
124
 
119
125
  - `@loopstack/core` - Core framework functionality
120
- - `@loopstack/core-ui-module` - Provides `CreateChatMessage` tool
126
+ - `@loopstack/create-chat-message-tool` - Provides `CreateChatMessage` tool
121
127
  - `@loopstack/create-value-tool` - Provides `CreateValue` tool
122
128
 
123
129
  ## 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.2",
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.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",
34
+ "@loopstack/common": "^0.20.3",
35
+ "@loopstack/core-ui-module": "^0.20.2",
36
+ "@loopstack/create-chat-message-tool": "^0.20.2",
37
+ "@loopstack/create-value-tool": "^0.20.2",
38
38
  "@nestjs/common": "^11.1.12",
39
39
  "zod": "^4.3.5"
40
40
  },
@@ -66,6 +66,10 @@
66
66
  "module": "src/tool-results-example.module.ts",
67
67
  "workflows": [
68
68
  "src/workflow-tool-results.workflow.ts"
69
+ ],
70
+ "installModes": [
71
+ "add",
72
+ "install"
69
73
  ]
70
74
  }
71
75
  }
@@ -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
  })