@hexabot-ai/agentic 3.0.1-alpha.0
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/LICENSE.md +120 -0
- package/README.md +231 -0
- package/dist/cjs/action/abstract-action.js +141 -0
- package/dist/cjs/action/action.js +47 -0
- package/dist/cjs/action/action.types.js +7 -0
- package/dist/cjs/bindings/base-binding.js +278 -0
- package/dist/cjs/context.js +79 -0
- package/dist/cjs/dsl.types.js +318 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/runner-runtime-control.js +343 -0
- package/dist/cjs/step-executors/conditional-executor.js +63 -0
- package/dist/cjs/step-executors/loop-executor.js +187 -0
- package/dist/cjs/step-executors/parallel-executor.js +51 -0
- package/dist/cjs/step-executors/skip-helpers.js +29 -0
- package/dist/cjs/step-executors/task-executor.js +155 -0
- package/dist/cjs/step-executors/types.js +7 -0
- package/dist/cjs/suspension-rebuilder.js +301 -0
- package/dist/cjs/utils/deferred.js +17 -0
- package/dist/cjs/utils/naming.js +48 -0
- package/dist/cjs/utils/timeout.js +42 -0
- package/dist/cjs/utils/workflow-definition.js +102 -0
- package/dist/cjs/workflow-compiler.js +212 -0
- package/dist/cjs/workflow-event-emitter.js +40 -0
- package/dist/cjs/workflow-runner.js +448 -0
- package/dist/cjs/workflow-types.js +7 -0
- package/dist/cjs/workflow-values.js +99 -0
- package/dist/cjs/workflow.js +243 -0
- package/dist/esm/action/abstract-action.js +137 -0
- package/dist/esm/action/action.js +44 -0
- package/dist/esm/action/action.types.js +6 -0
- package/dist/esm/bindings/base-binding.js +273 -0
- package/dist/esm/context.js +75 -0
- package/dist/esm/dsl.types.js +309 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/runner-runtime-control.js +338 -0
- package/dist/esm/step-executors/conditional-executor.js +60 -0
- package/dist/esm/step-executors/loop-executor.js +182 -0
- package/dist/esm/step-executors/parallel-executor.js +48 -0
- package/dist/esm/step-executors/skip-helpers.js +25 -0
- package/dist/esm/step-executors/task-executor.js +152 -0
- package/dist/esm/step-executors/types.js +6 -0
- package/dist/esm/suspension-rebuilder.js +296 -0
- package/dist/esm/utils/deferred.js +14 -0
- package/dist/esm/utils/naming.js +42 -0
- package/dist/esm/utils/timeout.js +37 -0
- package/dist/esm/utils/workflow-definition.js +98 -0
- package/dist/esm/workflow-compiler.js +208 -0
- package/dist/esm/workflow-event-emitter.js +36 -0
- package/dist/esm/workflow-runner.js +444 -0
- package/dist/esm/workflow-types.js +6 -0
- package/dist/esm/workflow-values.js +89 -0
- package/dist/esm/workflow.js +236 -0
- package/dist/types/action/abstract-action.d.ts +54 -0
- package/dist/types/action/abstract-action.d.ts.map +1 -0
- package/dist/types/action/action.d.ts +23 -0
- package/dist/types/action/action.d.ts.map +1 -0
- package/dist/types/action/action.types.d.ts +55 -0
- package/dist/types/action/action.types.d.ts.map +1 -0
- package/dist/types/bindings/base-binding.d.ts +52 -0
- package/dist/types/bindings/base-binding.d.ts.map +1 -0
- package/dist/types/context.d.ts +105 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/dsl.types.d.ts +220 -0
- package/dist/types/dsl.types.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/runner-runtime-control.d.ts +64 -0
- package/dist/types/runner-runtime-control.d.ts.map +1 -0
- package/dist/types/step-executors/conditional-executor.d.ts +13 -0
- package/dist/types/step-executors/conditional-executor.d.ts.map +1 -0
- package/dist/types/step-executors/loop-executor.d.ts +33 -0
- package/dist/types/step-executors/loop-executor.d.ts.map +1 -0
- package/dist/types/step-executors/parallel-executor.d.ts +14 -0
- package/dist/types/step-executors/parallel-executor.d.ts.map +1 -0
- package/dist/types/step-executors/skip-helpers.d.ts +12 -0
- package/dist/types/step-executors/skip-helpers.d.ts.map +1 -0
- package/dist/types/step-executors/task-executor.d.ts +13 -0
- package/dist/types/step-executors/task-executor.d.ts.map +1 -0
- package/dist/types/step-executors/types.d.ts +24 -0
- package/dist/types/step-executors/types.d.ts.map +1 -0
- package/dist/types/suspension-rebuilder.d.ts +67 -0
- package/dist/types/suspension-rebuilder.d.ts.map +1 -0
- package/dist/types/utils/deferred.d.ts +7 -0
- package/dist/types/utils/deferred.d.ts.map +1 -0
- package/dist/types/utils/naming.d.ts +24 -0
- package/dist/types/utils/naming.d.ts.map +1 -0
- package/dist/types/utils/timeout.d.ts +17 -0
- package/dist/types/utils/timeout.d.ts.map +1 -0
- package/dist/types/utils/workflow-definition.d.ts +3 -0
- package/dist/types/utils/workflow-definition.d.ts.map +1 -0
- package/dist/types/workflow-compiler.d.ts +12 -0
- package/dist/types/workflow-compiler.d.ts.map +1 -0
- package/dist/types/workflow-event-emitter.d.ts +70 -0
- package/dist/types/workflow-event-emitter.d.ts.map +1 -0
- package/dist/types/workflow-runner.d.ts +179 -0
- package/dist/types/workflow-runner.d.ts.map +1 -0
- package/dist/types/workflow-types.d.ts +195 -0
- package/dist/types/workflow-types.d.ts.map +1 -0
- package/dist/types/workflow-values.d.ts +34 -0
- package/dist/types/workflow-values.d.ts.map +1 -0
- package/dist/types/workflow.d.ts +75 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/examples/defs-bindings-agent/actions/ai-agent.ts +110 -0
- package/examples/defs-bindings-agent/actions/caculate-score.ts +49 -0
- package/examples/defs-bindings-agent/actions/index.ts +15 -0
- package/examples/defs-bindings-agent/bindings.ts +20 -0
- package/examples/defs-bindings-agent/context.ts +32 -0
- package/examples/defs-bindings-agent/workflow.ts +67 -0
- package/examples/defs-bindings-agent/workflow.yml +28 -0
- package/examples/full/actions/await-user-input.ts +46 -0
- package/examples/full/actions/call-llm.ts +133 -0
- package/examples/full/actions/create-ticket.ts +46 -0
- package/examples/full/actions/decision-router.ts +83 -0
- package/examples/full/actions/get-calendar-events.ts +55 -0
- package/examples/full/actions/get-user-profile.ts +72 -0
- package/examples/full/actions/index.ts +33 -0
- package/examples/full/actions/query-memory.ts +45 -0
- package/examples/full/actions/search-web.ts +53 -0
- package/examples/full/actions/send-email.ts +50 -0
- package/examples/full/context.ts +41 -0
- package/examples/full/workflow.ts +75 -0
- package/examples/full/workflow.yml +359 -0
- package/examples/loop/actions/await-reply.ts +47 -0
- package/examples/loop/actions/index.ts +19 -0
- package/examples/loop/actions/send-text-message.ts +40 -0
- package/examples/loop/context.ts +32 -0
- package/examples/loop/workflow.ts +66 -0
- package/examples/loop/workflow.yml +66 -0
- package/examples/suspend-resume/actions/format-reply.ts +43 -0
- package/examples/suspend-resume/actions/index.ts +13 -0
- package/examples/suspend-resume/actions/wait-for-user.ts +51 -0
- package/examples/suspend-resume/context.ts +32 -0
- package/examples/suspend-resume/workflow.ts +79 -0
- package/examples/suspend-resume/workflow.yml +29 -0
- package/package.json +60 -0
- package/src/__tests__/parser.test.ts +95 -0
- package/src/__tests__/suspension-rebuilder.test.ts +361 -0
- package/src/__tests__/test-helpers.ts +36 -0
- package/src/__tests__/validation.test.ts +526 -0
- package/src/__tests__/workflow-compiler.test.ts +715 -0
- package/src/__tests__/workflow-definition-path.test.ts +381 -0
- package/src/__tests__/workflow-event-emitter.test.ts +50 -0
- package/src/__tests__/workflow-runner.test.ts +1397 -0
- package/src/__tests__/workflow-values.test.ts +132 -0
- package/src/__tests__/workflow.test.ts +320 -0
- package/src/action/__tests__/abstract-action-timing.test.ts +183 -0
- package/src/action/__tests__/action.test.ts +473 -0
- package/src/action/abstract-action.ts +215 -0
- package/src/action/action.ts +83 -0
- package/src/action/action.types.ts +93 -0
- package/src/bindings/base-binding.ts +508 -0
- package/src/context.ts +179 -0
- package/src/dsl.types.ts +473 -0
- package/src/index.ts +114 -0
- package/src/runner-runtime-control.ts +544 -0
- package/src/step-executors/conditional-executor.test.ts +192 -0
- package/src/step-executors/conditional-executor.ts +83 -0
- package/src/step-executors/loop-executor.test.ts +303 -0
- package/src/step-executors/loop-executor.ts +299 -0
- package/src/step-executors/parallel-executor.test.ts +182 -0
- package/src/step-executors/parallel-executor.ts +77 -0
- package/src/step-executors/skip-helpers.ts +68 -0
- package/src/step-executors/task-executor.test.ts +257 -0
- package/src/step-executors/task-executor.ts +248 -0
- package/src/step-executors/types.ts +70 -0
- package/src/suspension-rebuilder.ts +504 -0
- package/src/utils/deferred.ts +23 -0
- package/src/utils/naming.ts +55 -0
- package/src/utils/timeout.ts +48 -0
- package/src/utils/workflow-definition.ts +173 -0
- package/src/workflow-compiler.ts +317 -0
- package/src/workflow-event-emitter.ts +86 -0
- package/src/workflow-runner.ts +603 -0
- package/src/workflow-types.ts +207 -0
- package/src/workflow-values.ts +159 -0
- package/src/workflow.ts +387 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Fair Core License, Version 1.0, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FCL-1.0-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2025 Hexastack
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Limitations,
|
|
26
|
+
Patents, Redistribution and Trademark clauses below, we hereby grant you the
|
|
27
|
+
right to use, copy, modify, create derivative works, publicly perform, publicly
|
|
28
|
+
display and redistribute the Software for any Permitted Purpose identified
|
|
29
|
+
below.
|
|
30
|
+
|
|
31
|
+
### Permitted Purpose
|
|
32
|
+
|
|
33
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
34
|
+
means making the Software available to others in a commercial product or
|
|
35
|
+
service that:
|
|
36
|
+
|
|
37
|
+
1. substitutes for the Software;
|
|
38
|
+
|
|
39
|
+
2. substitutes for any other product or service we offer using the Software
|
|
40
|
+
that exists as of the date we make the Software available; or
|
|
41
|
+
|
|
42
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
43
|
+
|
|
44
|
+
Permitted Purposes specifically include using the Software:
|
|
45
|
+
|
|
46
|
+
1. for your internal use and access;
|
|
47
|
+
|
|
48
|
+
2. for non-commercial education;
|
|
49
|
+
|
|
50
|
+
3. for non-commercial research; and
|
|
51
|
+
|
|
52
|
+
4. in connection with professional services that you provide to a licensee
|
|
53
|
+
using the Software in accordance with these Terms and Conditions.
|
|
54
|
+
|
|
55
|
+
### Limitations
|
|
56
|
+
|
|
57
|
+
You must not move, change, disable, or circumvent the license key functionality
|
|
58
|
+
in the Software; or modify any portion of the Software protected by the license
|
|
59
|
+
key to:
|
|
60
|
+
|
|
61
|
+
1. enable access to the protected functionality without a valid license key; or
|
|
62
|
+
|
|
63
|
+
2. remove the protected functionality.
|
|
64
|
+
|
|
65
|
+
### Patents
|
|
66
|
+
|
|
67
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
68
|
+
patents, the license grant above includes a license under our patents. If you
|
|
69
|
+
make a claim against any party that the Software infringes or contributes to
|
|
70
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
71
|
+
immediately.
|
|
72
|
+
|
|
73
|
+
### Redistribution
|
|
74
|
+
|
|
75
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
76
|
+
the Software.
|
|
77
|
+
|
|
78
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
79
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
80
|
+
remove any copyright or other proprietary notices provided in or with the
|
|
81
|
+
Software.
|
|
82
|
+
|
|
83
|
+
### Disclaimer
|
|
84
|
+
|
|
85
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
86
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
87
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
88
|
+
|
|
89
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
90
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
91
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
92
|
+
|
|
93
|
+
In the event the provision of this Disclaimer section is unenforceable under
|
|
94
|
+
applicable law, the licenses granted herein are void.
|
|
95
|
+
|
|
96
|
+
### Trademarks
|
|
97
|
+
|
|
98
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
99
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
100
|
+
trademarks, trade names, service marks or product names.
|
|
101
|
+
|
|
102
|
+
## Grant of Future License
|
|
103
|
+
|
|
104
|
+
We hereby irrevocably grant you an additional license to use the Software,
|
|
105
|
+
under the Apache License, Version 2.0, that is effective on the second
|
|
106
|
+
anniversary of the date we make the Software available. On or after that date,
|
|
107
|
+
you may use the Software under the Apache License, Version 2.0, in which case
|
|
108
|
+
the following will apply:
|
|
109
|
+
|
|
110
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
111
|
+
this file except in compliance with the License.
|
|
112
|
+
|
|
113
|
+
You may obtain a copy of the License at
|
|
114
|
+
|
|
115
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
116
|
+
|
|
117
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
118
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
119
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
120
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# @hexabot-ai/agentic
|
|
2
|
+
|
|
3
|
+
Typed runtime and YAML DSL for orchestrating multi-step AI/automation workflows. The package combines JSONata-powered expressions, schema validation, and a resumable runner so you can wire LLMs, tools, and human-in-the-loop pauses with reliable execution controls.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
- Declarative workflow DSL in YAML or JS objects with JSONata expressions (prefixed by `=`) and clear scopes (`$input`, `$context`, `$output`, `$iteration`, `$accumulator`).
|
|
7
|
+
- Type-safe actions built with `defineAction`, Zod-validated IO, and merged settings (timeouts, retries, plus action-specific options) inherited from workflow defaults.
|
|
8
|
+
- Resumable execution via `WorkflowRunner` and `context.workflow.suspend`, plus snapshots for persistence and replay.
|
|
9
|
+
- Flow primitives: sequential `do`, `parallel` blocks (`wait_all`/`wait_any`), `conditional` branches, and two loop variants: `loop.type: for_each` (iterables) and `loop.type: while` (pre-check condition).
|
|
10
|
+
- Event emitter hooks for observability (`hook:workflow:start|finish|failure|suspended`, `hook:step:start|success|error|suspended|skipped`).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @hexabot-ai/agentic
|
|
16
|
+
# or
|
|
17
|
+
npm install @hexabot-ai/agentic
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Node.js >= 20.18.1.
|
|
21
|
+
|
|
22
|
+
The package ships both ESM (`import`) and CommonJS (`require`) entrypoints plus browser-safe internals, so you can run workflows in Node.js or bundle them for the client.
|
|
23
|
+
|
|
24
|
+
## DSL essentials
|
|
25
|
+
|
|
26
|
+
A workflow is a single YAML (or object) that declares inputs, context, defaults, definitions, control-flow, and outputs. The full annotated reference lives in `./DSL.md` and `examples/full/workflow.yml`. The important pieces:
|
|
27
|
+
|
|
28
|
+
- `inputs.schema`: JSON-schema-like fields validated at runtime.
|
|
29
|
+
- `context`: read-only values injected by the host (including any long-term state) and exposed to expressions.
|
|
30
|
+
- `defaults.settings`: inherited by every task (timeouts, retries, and action-specific settings).
|
|
31
|
+
- `defs`: required root registry for all definitions.
|
|
32
|
+
- `defs.<name>` with `kind: task`: executable task defs with `action` and optional `inputs`, `settings`, `bindings`, `description`.
|
|
33
|
+
- `defs.<name>` with `kind != task`: binding defs; `settings` is required (use `{}` when empty), with optional `action`, `bindings`, `description`.
|
|
34
|
+
- `flow[].do`: must reference a `defs.<name>` entry where `kind: task`.
|
|
35
|
+
- `defs.<name>.bindings`: optional kind-based refs on any def (`<kind>: [<defName>...]` for `multiple: true`, `<kind>: <defName>` for `multiple: false`).
|
|
36
|
+
- `flow`: ordered list of steps combining `do`, `parallel`, `conditional`, `loop`.
|
|
37
|
+
- `outputs`: expressions evaluated after the flow finishes.
|
|
38
|
+
- `loop`: must declare `type` (`for_each` or `while`). Legacy loops without `type` are invalid.
|
|
39
|
+
|
|
40
|
+
Task results are stored automatically under `$output.<task>` for downstream expressions.
|
|
41
|
+
|
|
42
|
+
When workflows use defs with bindings, pass `bindingKinds` to `Workflow.fromYaml` / `Workflow.fromDefinition`. Each kind descriptor supports `{ schema, multiple, supportedBindings?, actionPolicy? }`.
|
|
43
|
+
|
|
44
|
+
Binding validation is recursive and enforces cardinality, reference existence, kind matching, duplicate references, cycle detection, and allowlists:
|
|
45
|
+
- if a def has `action`, allowlist comes from `actions[action].supportedBindings`.
|
|
46
|
+
- otherwise allowlist comes from `bindingKinds[def.kind].supportedBindings`.
|
|
47
|
+
- when `actions` are provided at compile time, defs declaring `action` must resolve.
|
|
48
|
+
|
|
49
|
+
At runtime, mounted bindings follow kind cardinality:
|
|
50
|
+
- `multiple: true` kinds mount as `{ [defName]: { settings, action?, bindings? } }`.
|
|
51
|
+
- `multiple: false` kinds mount as `{ settings, action?, bindings? }`.
|
|
52
|
+
|
|
53
|
+
Any string starting with `=` is parsed as JSONata; everything else is literal. Expressions receive `{ input, context, output, iteration, accumulator }` as scope; `$context` resolves to your workflow context state.
|
|
54
|
+
|
|
55
|
+
## Defining actions
|
|
56
|
+
|
|
57
|
+
Actions wrap your IO or model calls. `defineAction` enforces schemas and merges settings.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { defineAction, Settings, BaseWorkflowContext } from '@hexabot-ai/agentic';
|
|
61
|
+
import type { InferWorkflowBindings } from '@hexabot-ai/agentic';
|
|
62
|
+
import { z } from 'zod';
|
|
63
|
+
|
|
64
|
+
class AppContext extends BaseWorkflowContext<{ user_id: string }> {
|
|
65
|
+
log(message: string, payload?: unknown) {
|
|
66
|
+
console.log(message, payload);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const bindingKinds = {
|
|
71
|
+
tools: {
|
|
72
|
+
// For non-task kinds, schema validates the "settings" payload.
|
|
73
|
+
schema: z.record(z.string(), z.unknown()),
|
|
74
|
+
multiple: true,
|
|
75
|
+
actionPolicy: 'required' as const,
|
|
76
|
+
supportedBindings: ['tools'] as const,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
type AppBindings = InferWorkflowBindings<typeof bindingKinds>;
|
|
80
|
+
|
|
81
|
+
export const call_api = defineAction<
|
|
82
|
+
{ id: string },
|
|
83
|
+
{ body: string },
|
|
84
|
+
AppContext,
|
|
85
|
+
Settings,
|
|
86
|
+
AppBindings
|
|
87
|
+
>({
|
|
88
|
+
name: 'call_api', // must match defs.<task>.action
|
|
89
|
+
description: 'Fetches data from an API',
|
|
90
|
+
inputSchema: z.object({ id: z.string() }),
|
|
91
|
+
outputSchema: z.object({ body: z.string() }),
|
|
92
|
+
execute: async ({ input, context, settings, bindings }) => {
|
|
93
|
+
context.log('calling api', {
|
|
94
|
+
id: input.id,
|
|
95
|
+
timeout: settings.timeout_ms,
|
|
96
|
+
tools: bindings.tools ? Object.keys(bindings.tools) : [],
|
|
97
|
+
});
|
|
98
|
+
return { body: `result for ${input.id}` };
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Settings are parsed and merged with workflow defaults before `execute` runs; retries and timeout wrappers are applied automatically. Awaiting `context.workflow.suspend(...)` pauses the workflow until `resume` is called.
|
|
104
|
+
|
|
105
|
+
## Running a workflow from YAML
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { Workflow, WorkflowEventEmitter, BaseWorkflowContext } from '@hexabot-ai/agentic';
|
|
109
|
+
import fs from 'node:fs';
|
|
110
|
+
|
|
111
|
+
const yamlSource = fs.readFileSync('workflow.yml', 'utf8');
|
|
112
|
+
const actions = { call_api }; // keys are action names referenced by defs.*.action
|
|
113
|
+
|
|
114
|
+
class AppContext extends BaseWorkflowContext<{ user_id: string; thread_id: string }> {}
|
|
115
|
+
|
|
116
|
+
const workflow = Workflow.fromYaml(yamlSource, { actions });
|
|
117
|
+
|
|
118
|
+
const emitter = new WorkflowEventEmitter();
|
|
119
|
+
emitter.on('hook:step:start', ({ step }) => console.log('start', step.id));
|
|
120
|
+
|
|
121
|
+
const runner = await workflow.buildAsyncRunner();
|
|
122
|
+
const context = new AppContext(
|
|
123
|
+
{ user_id: 'user-1', thread_id: 'thread-1' },
|
|
124
|
+
emitter,
|
|
125
|
+
);
|
|
126
|
+
const startResult = await runner.start({
|
|
127
|
+
inputData: { id: '123' },
|
|
128
|
+
context,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (startResult.status === 'finished') {
|
|
132
|
+
console.log('output', startResult.output);
|
|
133
|
+
} else if (startResult.status === 'suspended') {
|
|
134
|
+
// persist startResult.snapshot and prompt the user; resume later:
|
|
135
|
+
const resumeResult = await runner.resume({ resumeData: { reply: 'go' } });
|
|
136
|
+
console.log(resumeResult.status, resumeResult.output);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
You can also skip YAML and use `Workflow.fromDefinition` with a typed object that matches `WorkflowDefinition`.
|
|
141
|
+
Attach an event emitter to your workflow context (via the constructor or by setting `context.eventEmitter`); it accepts any object with `emit` and `on` methods. `WorkflowEventEmitter` is a small, dependency-free helper with typed payloads (`WorkflowEventEmitterLike` describes the shape).
|
|
142
|
+
|
|
143
|
+
If your YAML declares `defs.*.bindings`, pass the same `bindingKinds` registry:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
const workflow = Workflow.fromYaml(yamlSource, {
|
|
147
|
+
actions,
|
|
148
|
+
bindingKinds,
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Minimal YAML example
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
inputs:
|
|
156
|
+
schema:
|
|
157
|
+
user_id:
|
|
158
|
+
type: string
|
|
159
|
+
defs:
|
|
160
|
+
greet_user:
|
|
161
|
+
kind: task
|
|
162
|
+
action: call_api
|
|
163
|
+
inputs:
|
|
164
|
+
id: "=$input.user_id"
|
|
165
|
+
flow:
|
|
166
|
+
- do: greet_user
|
|
167
|
+
outputs:
|
|
168
|
+
reply: "='Hello ' & $output.greet_user.body"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Custom JSONata functions
|
|
172
|
+
|
|
173
|
+
You can inject additional JSONata functions when compiling a workflow:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const workflow = Workflow.fromYaml(yamlSource, {
|
|
177
|
+
actions,
|
|
178
|
+
jsonataFunctions: {
|
|
179
|
+
i18n: (text: string) => translate(text, 'fr'),
|
|
180
|
+
slugify: { implementation: (value: string) => value.toLowerCase(), signature: 's' },
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
These helpers are registered on every expression and can be referenced from YAML, e.g. `text: "=$i18n('Bye bye')"` inside `defs.<task>.inputs`.
|
|
186
|
+
|
|
187
|
+
## Suspension and human-in-the-loop
|
|
188
|
+
|
|
189
|
+
Inside an action you can pause execution and surface metadata to the caller:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
export const await_user = defineAction<unknown, { reply?: string }, AppContext, Settings>({
|
|
193
|
+
name: 'await_user',
|
|
194
|
+
execute: async ({ context }) => {
|
|
195
|
+
const resumeData = await context.workflow.suspend({
|
|
196
|
+
reason: 'awaiting_user',
|
|
197
|
+
data: { prompt: 'Please confirm' },
|
|
198
|
+
});
|
|
199
|
+
return { reply: (resumeData as { reply?: string })?.reply };
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`Workflow.run` throws an error with suspension details (`stepId`, `reason`, `data`) when this happens; `WorkflowRunner.start` instead returns `{ status: 'suspended', ... }` so hosts can persist state and resume later with `runner.resume`.
|
|
205
|
+
|
|
206
|
+
## Events and observability
|
|
207
|
+
|
|
208
|
+
`WorkflowRunner` can publish lifecycle hooks to any emitter-like object with `emit`/`on` (`WorkflowEventEmitterLike`); `WorkflowEventEmitter` is the built-in helper and mirrors these events:
|
|
209
|
+
|
|
210
|
+
- `hook:workflow:start | finish | failure | suspended`
|
|
211
|
+
- `hook:step:start | success | error | suspended | skipped`
|
|
212
|
+
|
|
213
|
+
Attach listeners to stream logs, emit metrics, or capture snapshots for debugging.
|
|
214
|
+
|
|
215
|
+
## Examples and scripts
|
|
216
|
+
|
|
217
|
+
- Full DSL walkthrough and runnable demo: `packages/agentic/DSL.md`, `packages/agentic/examples/full/workflow.yml`, `packages/agentic/examples/full/workflow.ts`, with mock actions in `packages/agentic/examples/full/actions/*`.
|
|
218
|
+
- Loop quickstart (`while` loop + suspend/resume): `packages/agentic/examples/loop/workflow.yml` and `packages/agentic/examples/loop/workflow.ts`.
|
|
219
|
+
- Suspend/resume quickstart: `packages/agentic/examples/suspend-resume/workflow.yml` and `packages/agentic/examples/suspend-resume/workflow.ts` show pausing a run and resuming with reply data.
|
|
220
|
+
- Run the demos with ts-node: `pnpm dlx ts-node packages/agentic/examples/full/workflow.ts`, `pnpm dlx ts-node packages/agentic/examples/loop/workflow.ts`, or `pnpm dlx ts-node packages/agentic/examples/suspend-resume/workflow.ts`.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
From the repository root:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
pnpm --filter @hexabot-ai/agentic build
|
|
228
|
+
pnpm --filter @hexabot-ai/agentic test
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The codebase is TypeScript-first and validated with Zod; expressions use JSONata under the hood.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
4
|
+
* Copyright (c) 2025 Hexastack.
|
|
5
|
+
* Full terms: see LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AbstractAction = void 0;
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const dsl_types_1 = require("../dsl.types");
|
|
11
|
+
const naming_1 = require("../utils/naming");
|
|
12
|
+
const timeout_1 = require("../utils/timeout");
|
|
13
|
+
const BASE_SETTINGS_KEYS = Object.keys(dsl_types_1.BaseSettingsSchema.shape);
|
|
14
|
+
/**
|
|
15
|
+
* Base implementation that enforces schema-validated input/output.
|
|
16
|
+
*/
|
|
17
|
+
class AbstractAction {
|
|
18
|
+
/**
|
|
19
|
+
* Sets up core metadata and schemas for the action.
|
|
20
|
+
*
|
|
21
|
+
* @param metadata - Describes the action name, description, and schemas.
|
|
22
|
+
* @param options - Optional configuration or definition override.
|
|
23
|
+
*/
|
|
24
|
+
constructor(metadata) {
|
|
25
|
+
if (metadata.settingsSchema instanceof zod_1.z.ZodObject) {
|
|
26
|
+
const actionSettingsKeys = Object.keys(metadata.settingsSchema.shape);
|
|
27
|
+
const overlappingKeys = actionSettingsKeys.filter((key) => BASE_SETTINGS_KEYS.includes(key));
|
|
28
|
+
if (overlappingKeys.length > 0) {
|
|
29
|
+
throw new Error(`settingsSchema cannot redefine base settings keys: ${overlappingKeys.join(', ')}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
(0, naming_1.assertSnakeCaseName)(metadata.name, 'action');
|
|
33
|
+
this.name = metadata.name;
|
|
34
|
+
this.description = metadata.description;
|
|
35
|
+
this.inputSchema = metadata.inputSchema;
|
|
36
|
+
this.outputSchema = metadata.outputSchema;
|
|
37
|
+
this.settingSchema = metadata.settingsSchema;
|
|
38
|
+
this.supportedBindings = metadata.supportedBindings ?? [];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parses incoming payloads using the input schema.
|
|
42
|
+
*
|
|
43
|
+
* @param payload - Raw input received by the action.
|
|
44
|
+
* @returns Validated input typed as `I`.
|
|
45
|
+
*/
|
|
46
|
+
parseInput(payload) {
|
|
47
|
+
return this.inputSchema.parse(payload);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validates and returns the raw action output.
|
|
51
|
+
*
|
|
52
|
+
* @param payload - Raw output produced by {@link execute}.
|
|
53
|
+
* @returns Output typed as `O` after schema validation.
|
|
54
|
+
*/
|
|
55
|
+
parseOutput(payload) {
|
|
56
|
+
return this.outputSchema.parse(payload);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Executes the action with retry, timeout, and schema safety.
|
|
60
|
+
*
|
|
61
|
+
* @param payload - Raw input being provided to the action.
|
|
62
|
+
* @param context - Workflow context used during execution.
|
|
63
|
+
* @returns Validated output produced by the action.
|
|
64
|
+
* @throws Error when retries are exhausted or validation fails.
|
|
65
|
+
*/
|
|
66
|
+
parseSettings(payload) {
|
|
67
|
+
const settings = zod_1.z
|
|
68
|
+
.intersection(dsl_types_1.BaseSettingsSchema, this.settingSchema)
|
|
69
|
+
.parse(payload ?? {});
|
|
70
|
+
return (settings ?? {});
|
|
71
|
+
}
|
|
72
|
+
async run(payload, context, settings, bindings) {
|
|
73
|
+
const input = this.parseInput(payload);
|
|
74
|
+
const parsedSettings = this.parseSettings(settings);
|
|
75
|
+
const parsedBindings = (bindings ?? {});
|
|
76
|
+
this.assertSupportedBindings(parsedBindings);
|
|
77
|
+
const timeoutMs = parsedSettings.timeout_ms ?? 0;
|
|
78
|
+
const retrySettings = parsedSettings.retries ?? {
|
|
79
|
+
enabled: false,
|
|
80
|
+
max_attempts: 1,
|
|
81
|
+
backoff_ms: 0,
|
|
82
|
+
max_delay_ms: 0,
|
|
83
|
+
jitter: 0,
|
|
84
|
+
multiplier: 1,
|
|
85
|
+
};
|
|
86
|
+
const retriesEnabled = retrySettings.enabled ?? true;
|
|
87
|
+
const maxAttempts = retriesEnabled ? retrySettings.max_attempts : 1;
|
|
88
|
+
let attempt = 0;
|
|
89
|
+
let currentDelay = retrySettings.backoff_ms ?? 0;
|
|
90
|
+
const maxDelayMs = retrySettings.max_delay_ms;
|
|
91
|
+
const jitter = retrySettings.jitter;
|
|
92
|
+
const multiplier = retrySettings.multiplier;
|
|
93
|
+
while (attempt < maxAttempts) {
|
|
94
|
+
try {
|
|
95
|
+
const result = await (0, timeout_1.withTimeout)(this.execute({
|
|
96
|
+
input,
|
|
97
|
+
context,
|
|
98
|
+
settings: parsedSettings,
|
|
99
|
+
bindings: parsedBindings,
|
|
100
|
+
}), timeoutMs);
|
|
101
|
+
return this.parseOutput(result);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
attempt += 1;
|
|
105
|
+
if (attempt >= maxAttempts) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
let delay = currentDelay;
|
|
109
|
+
if (maxDelayMs > 0) {
|
|
110
|
+
delay = Math.min(delay, maxDelayMs);
|
|
111
|
+
}
|
|
112
|
+
if (delay > 0) {
|
|
113
|
+
const jitterFactor = jitter > 0 ? 1 + (Math.random() * 2 - 1) * jitter : 1;
|
|
114
|
+
const jitteredDelay = Math.max(0, Math.round(delay * jitterFactor));
|
|
115
|
+
if (jitteredDelay > 0) {
|
|
116
|
+
await (0, timeout_1.sleep)(jitteredDelay);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const nextDelay = currentDelay * multiplier;
|
|
120
|
+
currentDelay =
|
|
121
|
+
maxDelayMs > 0 ? Math.min(nextDelay, maxDelayMs) : nextDelay;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
throw new Error('Action failed after exhausting retry attempts.');
|
|
125
|
+
}
|
|
126
|
+
assertSupportedBindings(bindings) {
|
|
127
|
+
const bindingKinds = Object.keys((bindings ?? {}));
|
|
128
|
+
if (bindingKinds.length === 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const unsupportedKinds = bindingKinds.filter((bindingKind) => !this.supportedBindings.includes(bindingKind));
|
|
132
|
+
if (unsupportedKinds.length === 0) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const supported = this.supportedBindings.length > 0
|
|
136
|
+
? this.supportedBindings.join(', ')
|
|
137
|
+
: '<none>';
|
|
138
|
+
throw new Error(`Action "${this.name}" does not support binding kind(s): ${unsupportedKinds.join(', ')}. Supported binding kinds: ${supported}.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.AbstractAction = AbstractAction;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
4
|
+
* Copyright (c) 2025 Hexastack.
|
|
5
|
+
* Full terms: see LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.defineAction = defineAction;
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const abstract_action_1 = require("./abstract-action");
|
|
11
|
+
/**
|
|
12
|
+
* Builds an {@link AbstractAction} subclass from simple configuration.
|
|
13
|
+
*
|
|
14
|
+
* @param params - Action definition containing metadata and runtime logic.
|
|
15
|
+
* @returns Instantiated action ready to be used by a workflow.
|
|
16
|
+
* @typeParam I - Action input type.
|
|
17
|
+
* @typeParam O - Action output type.
|
|
18
|
+
* @typeParam Ctx - Workflow context type.
|
|
19
|
+
*/
|
|
20
|
+
function defineAction(params) {
|
|
21
|
+
const defaultSettingsSchema = zod_1.z.any();
|
|
22
|
+
const defaultInputSchema = zod_1.z.any();
|
|
23
|
+
const defaultOutputSchema = zod_1.z.any();
|
|
24
|
+
class FnAction extends abstract_action_1.AbstractAction {
|
|
25
|
+
constructor() {
|
|
26
|
+
const metadata = {
|
|
27
|
+
name: params.name,
|
|
28
|
+
description: params.description ?? '',
|
|
29
|
+
inputSchema: params.inputSchema ?? defaultInputSchema,
|
|
30
|
+
outputSchema: params.outputSchema ?? defaultOutputSchema,
|
|
31
|
+
settingsSchema: params.settingSchema ?? defaultSettingsSchema,
|
|
32
|
+
supportedBindings: params.supportedBindings,
|
|
33
|
+
};
|
|
34
|
+
super(metadata);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Delegates to the user supplied execute callback.
|
|
38
|
+
*
|
|
39
|
+
* @param args - Action execution arguments supplied by the runner.
|
|
40
|
+
* @returns Result of the user callback as a promise.
|
|
41
|
+
*/
|
|
42
|
+
async execute(args) {
|
|
43
|
+
return await Promise.resolve(params.execute(args));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return new FnAction();
|
|
47
|
+
}
|