@q1k-oss/btree-workflows 0.0.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/.claude/settings.local.json +31 -0
- package/CLAUDE.md +181 -0
- package/LICENSE +21 -0
- package/README.md +920 -0
- package/behaviour-tree-workflows-landing/index.html +16 -0
- package/behaviour-tree-workflows-landing/package-lock.json +2074 -0
- package/behaviour-tree-workflows-landing/package.json +31 -0
- package/behaviour-tree-workflows-landing/public/favicon.svg +17 -0
- package/behaviour-tree-workflows-landing/src/App.css +103 -0
- package/behaviour-tree-workflows-landing/src/App.tsx +176 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +89 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +34 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +107 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +85 -0
- package/behaviour-tree-workflows-landing/src/components/Header.css +50 -0
- package/behaviour-tree-workflows-landing/src/components/Header.tsx +26 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +45 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +15 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.css +74 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +53 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +67 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +192 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +18 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +96 -0
- package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +11 -0
- package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +96 -0
- package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +136 -0
- package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +549 -0
- package/behaviour-tree-workflows-landing/src/main.tsx +9 -0
- package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +18 -0
- package/behaviour-tree-workflows-landing/src/stubs/fs.ts +24 -0
- package/behaviour-tree-workflows-landing/src/stubs/path.ts +16 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +6 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +22 -0
- package/behaviour-tree-workflows-landing/tsconfig.json +25 -0
- package/behaviour-tree-workflows-landing/vite.config.ts +40 -0
- package/demo-google-sheets.ts +181 -0
- package/demo-runtime-variables.ts +174 -0
- package/demo-template.ts +208 -0
- package/docs/ARCHITECTURE_SUMMARY.md +613 -0
- package/docs/NODE_REFERENCE.md +504 -0
- package/docs/README.md +53 -0
- package/docs/custom-nodes-architecture.md +826 -0
- package/docs/observability.md +175 -0
- package/docs/yaml-specification.md +990 -0
- package/examples/temporal/README.md +117 -0
- package/examples/temporal/activities.ts +373 -0
- package/examples/temporal/client.ts +115 -0
- package/examples/temporal/python-worker/activities.py +339 -0
- package/examples/temporal/python-worker/requirements.txt +12 -0
- package/examples/temporal/python-worker/worker.py +106 -0
- package/examples/temporal/worker.ts +66 -0
- package/examples/temporal/workflows.ts +6 -0
- package/examples/temporal/yaml-workflow-loader.ts +105 -0
- package/examples/yaml-test.ts +97 -0
- package/examples/yaml-workflows/01-simple-sequence.yaml +25 -0
- package/examples/yaml-workflows/02-parallel-timeout.yaml +45 -0
- package/examples/yaml-workflows/03-ecommerce-checkout.yaml +94 -0
- package/examples/yaml-workflows/04-ai-agent-workflow.yaml +346 -0
- package/examples/yaml-workflows/05-order-processing.yaml +146 -0
- package/examples/yaml-workflows/06-activity-test.yaml +71 -0
- package/examples/yaml-workflows/07-activity-simple-test.yaml +43 -0
- package/examples/yaml-workflows/08-file-processing.yaml +141 -0
- package/examples/yaml-workflows/09-http-request.yaml +137 -0
- package/examples/yaml-workflows/README.md +211 -0
- package/package.json +38 -0
- package/src/actions/code-execution.schema.ts +27 -0
- package/src/actions/code-execution.ts +218 -0
- package/src/actions/generate-file.test.ts +516 -0
- package/src/actions/generate-file.ts +166 -0
- package/src/actions/http-request.test.ts +784 -0
- package/src/actions/http-request.ts +228 -0
- package/src/actions/index.ts +20 -0
- package/src/actions/parse-file.test.ts +448 -0
- package/src/actions/parse-file.ts +139 -0
- package/src/actions/python-script.test.ts +439 -0
- package/src/actions/python-script.ts +154 -0
- package/src/base-node.test.ts +511 -0
- package/src/base-node.ts +605 -0
- package/src/behavior-tree.test.ts +431 -0
- package/src/behavior-tree.ts +283 -0
- package/src/blackboard.test.ts +222 -0
- package/src/blackboard.ts +192 -0
- package/src/composites/conditional.schema.ts +19 -0
- package/src/composites/conditional.test.ts +309 -0
- package/src/composites/conditional.ts +129 -0
- package/src/composites/for-each.schema.ts +23 -0
- package/src/composites/for-each.test.ts +254 -0
- package/src/composites/for-each.ts +132 -0
- package/src/composites/index.ts +15 -0
- package/src/composites/memory-sequence.schema.ts +19 -0
- package/src/composites/memory-sequence.test.ts +223 -0
- package/src/composites/memory-sequence.ts +98 -0
- package/src/composites/parallel.schema.ts +28 -0
- package/src/composites/parallel.test.ts +502 -0
- package/src/composites/parallel.ts +157 -0
- package/src/composites/reactive-sequence.schema.ts +19 -0
- package/src/composites/reactive-sequence.test.ts +170 -0
- package/src/composites/reactive-sequence.ts +85 -0
- package/src/composites/recovery.schema.ts +19 -0
- package/src/composites/recovery.test.ts +366 -0
- package/src/composites/recovery.ts +90 -0
- package/src/composites/selector.schema.ts +19 -0
- package/src/composites/selector.test.ts +387 -0
- package/src/composites/selector.ts +85 -0
- package/src/composites/sequence.schema.ts +19 -0
- package/src/composites/sequence.test.ts +337 -0
- package/src/composites/sequence.ts +72 -0
- package/src/composites/sub-tree.schema.ts +21 -0
- package/src/composites/sub-tree.test.ts +893 -0
- package/src/composites/sub-tree.ts +177 -0
- package/src/composites/while.schema.ts +24 -0
- package/src/composites/while.test.ts +381 -0
- package/src/composites/while.ts +149 -0
- package/src/data-store/index.ts +10 -0
- package/src/data-store/memory-store.ts +161 -0
- package/src/data-store/types.ts +94 -0
- package/src/debug/breakpoint.test.ts +47 -0
- package/src/debug/breakpoint.ts +30 -0
- package/src/debug/index.ts +17 -0
- package/src/debug/resume-point.test.ts +49 -0
- package/src/debug/resume-point.ts +29 -0
- package/src/decorators/delay.schema.ts +21 -0
- package/src/decorators/delay.test.ts +261 -0
- package/src/decorators/delay.ts +140 -0
- package/src/decorators/force-result.schema.ts +32 -0
- package/src/decorators/force-result.test.ts +133 -0
- package/src/decorators/force-result.ts +63 -0
- package/src/decorators/index.ts +13 -0
- package/src/decorators/invert.schema.ts +19 -0
- package/src/decorators/invert.test.ts +135 -0
- package/src/decorators/invert.ts +42 -0
- package/src/decorators/keep-running.schema.ts +20 -0
- package/src/decorators/keep-running.test.ts +105 -0
- package/src/decorators/keep-running.ts +49 -0
- package/src/decorators/precondition.schema.ts +19 -0
- package/src/decorators/precondition.test.ts +351 -0
- package/src/decorators/precondition.ts +139 -0
- package/src/decorators/repeat.schema.ts +21 -0
- package/src/decorators/repeat.test.ts +187 -0
- package/src/decorators/repeat.ts +94 -0
- package/src/decorators/run-once.schema.ts +19 -0
- package/src/decorators/run-once.test.ts +140 -0
- package/src/decorators/run-once.ts +61 -0
- package/src/decorators/soft-assert.schema.ts +19 -0
- package/src/decorators/soft-assert.test.ts +107 -0
- package/src/decorators/soft-assert.ts +68 -0
- package/src/decorators/timeout.schema.ts +21 -0
- package/src/decorators/timeout.test.ts +274 -0
- package/src/decorators/timeout.ts +159 -0
- package/src/errors.test.ts +63 -0
- package/src/errors.ts +34 -0
- package/src/events.test.ts +347 -0
- package/src/events.ts +183 -0
- package/src/index.ts +80 -0
- package/src/integrations/index.ts +30 -0
- package/src/integrations/integration-action.test.ts +571 -0
- package/src/integrations/integration-action.ts +233 -0
- package/src/integrations/piece-executor.ts +320 -0
- package/src/observability/execution-tracker.ts +320 -0
- package/src/observability/index.ts +23 -0
- package/src/observability/sinks.ts +138 -0
- package/src/observability/types.ts +130 -0
- package/src/registry-utils.ts +147 -0
- package/src/registry.test.ts +466 -0
- package/src/registry.ts +334 -0
- package/src/schemas/base.schema.ts +104 -0
- package/src/schemas/index.ts +223 -0
- package/src/schemas/integration.test.ts +238 -0
- package/src/schemas/tree-definition.schema.ts +170 -0
- package/src/schemas/validation.test.ts +146 -0
- package/src/schemas/validation.ts +122 -0
- package/src/scripting/index.ts +22 -0
- package/src/templates/template-loader.test.ts +281 -0
- package/src/templates/template-loader.ts +152 -0
- package/src/temporal-integration.test.ts +213 -0
- package/src/test-nodes.ts +259 -0
- package/src/types.ts +503 -0
- package/src/utilities/index.ts +17 -0
- package/src/utilities/log-message.test.ts +275 -0
- package/src/utilities/log-message.ts +134 -0
- package/src/utilities/regex-extract.test.ts +138 -0
- package/src/utilities/regex-extract.ts +108 -0
- package/src/utilities/variable-resolver.test.ts +416 -0
- package/src/utilities/variable-resolver.ts +318 -0
- package/src/utils/error-handler.test.ts +117 -0
- package/src/utils/error-handler.ts +48 -0
- package/src/utils/signal-check.test.ts +234 -0
- package/src/utils/signal-check.ts +140 -0
- package/src/yaml/errors.ts +143 -0
- package/src/yaml/index.ts +30 -0
- package/src/yaml/loader.ts +39 -0
- package/src/yaml/parser.ts +286 -0
- package/src/yaml/validation/semantic-validator.ts +196 -0
- package/templates/google-sheets/insert-row.yaml +76 -0
- package/templates/notification-sender.yaml +33 -0
- package/templates/order-validation.yaml +44 -0
- package/tsconfig.json +24 -0
- package/vitest.config.ts +25 -0
- package/workflows/order-processor.yaml +59 -0
- package/workflows/process-order-workflow.yaml +142 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test loading YAML workflows
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Registry } from "../src/registry.js";
|
|
6
|
+
import { Sequence } from "../src/composites/sequence.js";
|
|
7
|
+
import { Timeout } from "../src/decorators/timeout.js";
|
|
8
|
+
import { PrintAction } from "../src/test-nodes.js";
|
|
9
|
+
import { loadTreeFromYaml } from "../src/yaml/index.js";
|
|
10
|
+
import { readFileSync } from "fs";
|
|
11
|
+
|
|
12
|
+
// Setup registry with required node types
|
|
13
|
+
const registry = new Registry();
|
|
14
|
+
registry.register("Sequence", Sequence as any, { category: "composite" });
|
|
15
|
+
registry.register("Timeout", Timeout as any, { category: "decorator" });
|
|
16
|
+
registry.register("PrintAction", PrintAction as any, { category: "action" });
|
|
17
|
+
|
|
18
|
+
// Test 1: Load from YAML string
|
|
19
|
+
const yamlString = `
|
|
20
|
+
type: Sequence
|
|
21
|
+
id: simple-notification
|
|
22
|
+
name: Send Notification
|
|
23
|
+
|
|
24
|
+
children:
|
|
25
|
+
- type: PrintAction
|
|
26
|
+
id: log-start
|
|
27
|
+
props:
|
|
28
|
+
message: "Starting notification workflow..."
|
|
29
|
+
|
|
30
|
+
- type: Timeout
|
|
31
|
+
id: notification-timeout
|
|
32
|
+
props:
|
|
33
|
+
timeoutMs: 5000
|
|
34
|
+
children:
|
|
35
|
+
- type: PrintAction
|
|
36
|
+
id: send-notification
|
|
37
|
+
props:
|
|
38
|
+
message: "Sending notification to user..."
|
|
39
|
+
|
|
40
|
+
- type: PrintAction
|
|
41
|
+
id: log-success
|
|
42
|
+
props:
|
|
43
|
+
message: "Notification sent successfully!"
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
console.log("Test 1: Loading from YAML string...");
|
|
47
|
+
try {
|
|
48
|
+
const tree = loadTreeFromYaml(yamlString, registry);
|
|
49
|
+
console.log("✓ Tree loaded successfully!");
|
|
50
|
+
console.log(" Root type:", tree.type);
|
|
51
|
+
console.log(" Root ID:", tree.id);
|
|
52
|
+
console.log(" Root name:", tree.name);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("✗ Failed to load tree:", error);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Test 2: Load from YAML file
|
|
59
|
+
console.log("\nTest 2: Loading from YAML file...");
|
|
60
|
+
try {
|
|
61
|
+
const yamlFile = readFileSync(
|
|
62
|
+
"./examples/yaml-workflows/01-simple-notification.yaml",
|
|
63
|
+
"utf-8",
|
|
64
|
+
);
|
|
65
|
+
const tree = loadTreeFromYaml(yamlFile, registry);
|
|
66
|
+
console.log("✓ Tree loaded from file successfully!");
|
|
67
|
+
console.log(" Root type:", tree.type);
|
|
68
|
+
console.log(" Root ID:", tree.id);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error("✗ Failed to load tree from file:", error);
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
console.error(" Error:", error.message);
|
|
73
|
+
}
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Test 3: Invalid YAML (should fail)
|
|
78
|
+
console.log("\nTest 3: Testing invalid YAML (negative timeout)...");
|
|
79
|
+
const invalidYaml = `
|
|
80
|
+
type: Timeout
|
|
81
|
+
id: invalid
|
|
82
|
+
props:
|
|
83
|
+
timeoutMs: -100
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const tree = loadTreeFromYaml(invalidYaml, registry);
|
|
88
|
+
console.error("✗ Should have thrown validation error!");
|
|
89
|
+
process.exit(1);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.log("✓ Correctly caught validation error");
|
|
92
|
+
if (error instanceof Error) {
|
|
93
|
+
console.log(" Error:", error.message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log("\n✓ All tests passed!");
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Simple Sequence Workflow
|
|
2
|
+
# Demonstrates basic sequential execution in Temporal
|
|
3
|
+
|
|
4
|
+
type: Sequence
|
|
5
|
+
id: simple-sequence
|
|
6
|
+
name: Simple Sequence Workflow
|
|
7
|
+
|
|
8
|
+
children:
|
|
9
|
+
- type: PrintAction
|
|
10
|
+
id: step1
|
|
11
|
+
name: Start Step
|
|
12
|
+
props:
|
|
13
|
+
message: "Starting workflow..."
|
|
14
|
+
|
|
15
|
+
- type: PrintAction
|
|
16
|
+
id: step2
|
|
17
|
+
name: Process Step
|
|
18
|
+
props:
|
|
19
|
+
message: "Processing data..."
|
|
20
|
+
|
|
21
|
+
- type: PrintAction
|
|
22
|
+
id: step3
|
|
23
|
+
name: Complete Step
|
|
24
|
+
props:
|
|
25
|
+
message: "Workflow complete!"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Parallel Execution with Timeout
|
|
2
|
+
# Demonstrates concurrent task execution with timeout protection
|
|
3
|
+
|
|
4
|
+
type: Sequence
|
|
5
|
+
id: parallel-timeout-root
|
|
6
|
+
name: Parallel with Timeout Workflow
|
|
7
|
+
|
|
8
|
+
children:
|
|
9
|
+
# Execute tasks in parallel with timeout protection
|
|
10
|
+
- type: Timeout
|
|
11
|
+
id: timeout
|
|
12
|
+
name: 5 Second Timeout
|
|
13
|
+
props:
|
|
14
|
+
timeoutMs: 5000
|
|
15
|
+
children:
|
|
16
|
+
- type: Parallel
|
|
17
|
+
id: parallelTasks
|
|
18
|
+
name: Parallel Tasks
|
|
19
|
+
props:
|
|
20
|
+
strategy: "strict"
|
|
21
|
+
children:
|
|
22
|
+
- type: PrintAction
|
|
23
|
+
id: task1
|
|
24
|
+
name: Task 1
|
|
25
|
+
props:
|
|
26
|
+
message: "Task 1: Fetching data..."
|
|
27
|
+
|
|
28
|
+
- type: PrintAction
|
|
29
|
+
id: task2
|
|
30
|
+
name: Task 2
|
|
31
|
+
props:
|
|
32
|
+
message: "Task 2: Processing..."
|
|
33
|
+
|
|
34
|
+
- type: PrintAction
|
|
35
|
+
id: task3
|
|
36
|
+
name: Task 3
|
|
37
|
+
props:
|
|
38
|
+
message: "Task 3: Validating..."
|
|
39
|
+
|
|
40
|
+
# Completion message
|
|
41
|
+
- type: PrintAction
|
|
42
|
+
id: complete
|
|
43
|
+
name: Completion Message
|
|
44
|
+
props:
|
|
45
|
+
message: "All tasks completed successfully!"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# E-commerce Checkout Workflow
|
|
2
|
+
# Complexity: Medium (UI-Moderate, LLM-Easy)
|
|
3
|
+
# Use case: Process order with validation, payment, and post-checkout tasks
|
|
4
|
+
|
|
5
|
+
type: Sequence
|
|
6
|
+
id: checkout-workflow
|
|
7
|
+
name: E-commerce Checkout
|
|
8
|
+
|
|
9
|
+
children:
|
|
10
|
+
# Step 1: Validate cart and inventory
|
|
11
|
+
- type: Sequence
|
|
12
|
+
id: validation-phase
|
|
13
|
+
name: Validation Phase
|
|
14
|
+
children:
|
|
15
|
+
- type: PrintAction
|
|
16
|
+
id: validate-cart
|
|
17
|
+
props:
|
|
18
|
+
message: "Validating shopping cart..."
|
|
19
|
+
|
|
20
|
+
- type: CheckCondition
|
|
21
|
+
id: check-cart-items
|
|
22
|
+
props:
|
|
23
|
+
key: cart.items
|
|
24
|
+
operator: ">"
|
|
25
|
+
value: 0
|
|
26
|
+
|
|
27
|
+
- type: CheckCondition
|
|
28
|
+
id: check-inventory
|
|
29
|
+
props:
|
|
30
|
+
key: inventory.available
|
|
31
|
+
operator: "=="
|
|
32
|
+
value: true
|
|
33
|
+
|
|
34
|
+
# Step 2: Process payment with timeout and retry
|
|
35
|
+
- type: Timeout
|
|
36
|
+
id: payment-timeout
|
|
37
|
+
props:
|
|
38
|
+
timeoutMs: 30000
|
|
39
|
+
children:
|
|
40
|
+
- type: Sequence
|
|
41
|
+
id: payment-sequence
|
|
42
|
+
children:
|
|
43
|
+
- type: PrintAction
|
|
44
|
+
id: init-payment
|
|
45
|
+
props:
|
|
46
|
+
message: "Initializing payment gateway..."
|
|
47
|
+
|
|
48
|
+
- type: PrintAction
|
|
49
|
+
id: charge-card
|
|
50
|
+
props:
|
|
51
|
+
message: "Charging credit card..."
|
|
52
|
+
|
|
53
|
+
- type: CheckCondition
|
|
54
|
+
id: verify-payment
|
|
55
|
+
props:
|
|
56
|
+
key: payment.status
|
|
57
|
+
operator: "=="
|
|
58
|
+
value: "success"
|
|
59
|
+
|
|
60
|
+
# Step 3: Post-checkout tasks (parallel)
|
|
61
|
+
- type: Parallel
|
|
62
|
+
id: post-checkout-tasks
|
|
63
|
+
name: Post-Checkout Tasks
|
|
64
|
+
props:
|
|
65
|
+
strategy: strict
|
|
66
|
+
children:
|
|
67
|
+
- type: Sequence
|
|
68
|
+
id: order-confirmation
|
|
69
|
+
children:
|
|
70
|
+
- type: PrintAction
|
|
71
|
+
id: send-confirmation-email
|
|
72
|
+
props:
|
|
73
|
+
message: "Sending order confirmation email..."
|
|
74
|
+
|
|
75
|
+
- type: PrintAction
|
|
76
|
+
id: send-sms
|
|
77
|
+
props:
|
|
78
|
+
message: "Sending SMS notification..."
|
|
79
|
+
|
|
80
|
+
- type: PrintAction
|
|
81
|
+
id: update-inventory
|
|
82
|
+
props:
|
|
83
|
+
message: "Updating inventory levels..."
|
|
84
|
+
|
|
85
|
+
- type: PrintAction
|
|
86
|
+
id: create-shipment
|
|
87
|
+
props:
|
|
88
|
+
message: "Creating shipment record..."
|
|
89
|
+
|
|
90
|
+
# Step 4: Completion
|
|
91
|
+
- type: PrintAction
|
|
92
|
+
id: checkout-complete
|
|
93
|
+
props:
|
|
94
|
+
message: "Checkout completed successfully!"
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# AI Agent Decision Workflow
|
|
2
|
+
# Complexity: Very High (UI-Very Hard, LLM-Easy!)
|
|
3
|
+
# Use case: Multi-step AI agent with fallbacks, decision trees, and context management
|
|
4
|
+
# This showcases LLM's strength in generating complex decision logic
|
|
5
|
+
|
|
6
|
+
type: Sequence
|
|
7
|
+
id: ai-agent-workflow
|
|
8
|
+
name: AI Agent Task Execution
|
|
9
|
+
|
|
10
|
+
children:
|
|
11
|
+
# Step 1: Initialize agent context
|
|
12
|
+
- type: Sequence
|
|
13
|
+
id: agent-initialization
|
|
14
|
+
name: Agent Initialization
|
|
15
|
+
children:
|
|
16
|
+
- type: PrintAction
|
|
17
|
+
id: load-agent
|
|
18
|
+
props:
|
|
19
|
+
message: "Initializing AI agent..."
|
|
20
|
+
|
|
21
|
+
- type: CounterAction
|
|
22
|
+
id: init-retry-count
|
|
23
|
+
props:
|
|
24
|
+
key: agent.retryCount
|
|
25
|
+
increment: 0
|
|
26
|
+
|
|
27
|
+
- type: CounterAction
|
|
28
|
+
id: init-step-count
|
|
29
|
+
props:
|
|
30
|
+
key: agent.stepCount
|
|
31
|
+
increment: 0
|
|
32
|
+
|
|
33
|
+
- type: PrintAction
|
|
34
|
+
id: load-context
|
|
35
|
+
props:
|
|
36
|
+
message: "Loading conversation context..."
|
|
37
|
+
|
|
38
|
+
# Step 2: Task planning (decision tree)
|
|
39
|
+
- type: Selector
|
|
40
|
+
id: task-router
|
|
41
|
+
name: Task Type Router
|
|
42
|
+
children:
|
|
43
|
+
# Route 1: Code generation task
|
|
44
|
+
- type: Sequence
|
|
45
|
+
id: code-generation-path
|
|
46
|
+
children:
|
|
47
|
+
- type: CheckCondition
|
|
48
|
+
id: is-code-task
|
|
49
|
+
props:
|
|
50
|
+
key: task.type
|
|
51
|
+
operator: "=="
|
|
52
|
+
value: "code_generation"
|
|
53
|
+
|
|
54
|
+
- type: Sequence
|
|
55
|
+
id: code-gen-pipeline
|
|
56
|
+
name: Code Generation Pipeline
|
|
57
|
+
children:
|
|
58
|
+
- type: PrintAction
|
|
59
|
+
id: analyze-requirements
|
|
60
|
+
props:
|
|
61
|
+
message: "Analyzing code requirements..."
|
|
62
|
+
|
|
63
|
+
- type: Timeout
|
|
64
|
+
id: generation-timeout
|
|
65
|
+
props:
|
|
66
|
+
timeoutMs: 120000
|
|
67
|
+
children:
|
|
68
|
+
- type: Sequence
|
|
69
|
+
id: generate-code
|
|
70
|
+
children:
|
|
71
|
+
- type: PrintAction
|
|
72
|
+
id: call-llm
|
|
73
|
+
props:
|
|
74
|
+
message: "Calling LLM for code generation..."
|
|
75
|
+
|
|
76
|
+
- type: PrintAction
|
|
77
|
+
id: validate-syntax
|
|
78
|
+
props:
|
|
79
|
+
message: "Validating syntax..."
|
|
80
|
+
|
|
81
|
+
- type: CheckCondition
|
|
82
|
+
id: check-quality
|
|
83
|
+
props:
|
|
84
|
+
key: code.qualityScore
|
|
85
|
+
operator: ">"
|
|
86
|
+
value: 0.7
|
|
87
|
+
|
|
88
|
+
- type: PrintAction
|
|
89
|
+
id: format-code
|
|
90
|
+
props:
|
|
91
|
+
message: "Formatting generated code..."
|
|
92
|
+
|
|
93
|
+
# Route 2: Data analysis task
|
|
94
|
+
- type: Sequence
|
|
95
|
+
id: data-analysis-path
|
|
96
|
+
children:
|
|
97
|
+
- type: CheckCondition
|
|
98
|
+
id: is-analysis-task
|
|
99
|
+
props:
|
|
100
|
+
key: task.type
|
|
101
|
+
operator: "=="
|
|
102
|
+
value: "data_analysis"
|
|
103
|
+
|
|
104
|
+
- type: Recovery
|
|
105
|
+
id: analysis-with-recovery
|
|
106
|
+
children:
|
|
107
|
+
# Try: Complex analysis
|
|
108
|
+
- type: Parallel
|
|
109
|
+
id: parallel-analysis
|
|
110
|
+
props:
|
|
111
|
+
strategy: strict
|
|
112
|
+
children:
|
|
113
|
+
- type: PrintAction
|
|
114
|
+
id: statistical-analysis
|
|
115
|
+
props:
|
|
116
|
+
message: "Running statistical analysis..."
|
|
117
|
+
|
|
118
|
+
- type: PrintAction
|
|
119
|
+
id: pattern-detection
|
|
120
|
+
props:
|
|
121
|
+
message: "Detecting patterns..."
|
|
122
|
+
|
|
123
|
+
- type: PrintAction
|
|
124
|
+
id: anomaly-detection
|
|
125
|
+
props:
|
|
126
|
+
message: "Detecting anomalies..."
|
|
127
|
+
|
|
128
|
+
# Catch: Simplified analysis
|
|
129
|
+
- type: PrintAction
|
|
130
|
+
id: fallback-analysis
|
|
131
|
+
props:
|
|
132
|
+
message: "Running simplified analysis due to error..."
|
|
133
|
+
|
|
134
|
+
# Finally: Save results
|
|
135
|
+
- type: PrintAction
|
|
136
|
+
id: save-analysis
|
|
137
|
+
props:
|
|
138
|
+
message: "Saving analysis results..."
|
|
139
|
+
|
|
140
|
+
# Route 3: Research task (default)
|
|
141
|
+
- type: Sequence
|
|
142
|
+
id: research-path
|
|
143
|
+
name: Research & Information Gathering
|
|
144
|
+
children:
|
|
145
|
+
- type: PrintAction
|
|
146
|
+
id: default-route
|
|
147
|
+
props:
|
|
148
|
+
message: "Executing research task..."
|
|
149
|
+
|
|
150
|
+
- type: While
|
|
151
|
+
id: research-loop
|
|
152
|
+
props:
|
|
153
|
+
condition:
|
|
154
|
+
key: agent.stepCount
|
|
155
|
+
operator: "<"
|
|
156
|
+
value: 5
|
|
157
|
+
children:
|
|
158
|
+
- type: Sequence
|
|
159
|
+
id: research-step
|
|
160
|
+
children:
|
|
161
|
+
- type: CounterAction
|
|
162
|
+
id: increment-step
|
|
163
|
+
props:
|
|
164
|
+
key: agent.stepCount
|
|
165
|
+
increment: 1
|
|
166
|
+
|
|
167
|
+
- type: Selector
|
|
168
|
+
id: information-gathering
|
|
169
|
+
name: Multi-Source Information Gathering
|
|
170
|
+
children:
|
|
171
|
+
# Try web search first
|
|
172
|
+
- type: Sequence
|
|
173
|
+
id: web-search
|
|
174
|
+
children:
|
|
175
|
+
- type: Timeout
|
|
176
|
+
id: search-timeout
|
|
177
|
+
props:
|
|
178
|
+
timeoutMs: 10000
|
|
179
|
+
children:
|
|
180
|
+
- type: PrintAction
|
|
181
|
+
id: execute-search
|
|
182
|
+
props:
|
|
183
|
+
message: "Searching web for information..."
|
|
184
|
+
|
|
185
|
+
- type: CheckCondition
|
|
186
|
+
id: verify-results
|
|
187
|
+
props:
|
|
188
|
+
key: search.resultsCount
|
|
189
|
+
operator: ">"
|
|
190
|
+
value: 0
|
|
191
|
+
|
|
192
|
+
# Fallback to knowledge base
|
|
193
|
+
- type: Sequence
|
|
194
|
+
id: knowledge-base-lookup
|
|
195
|
+
children:
|
|
196
|
+
- type: PrintAction
|
|
197
|
+
id: query-kb
|
|
198
|
+
props:
|
|
199
|
+
message: "Querying internal knowledge base..."
|
|
200
|
+
|
|
201
|
+
- type: ForceSuccess
|
|
202
|
+
id: ensure-progress
|
|
203
|
+
children:
|
|
204
|
+
- type: PrintAction
|
|
205
|
+
id: use-cached
|
|
206
|
+
props:
|
|
207
|
+
message: "Using cached knowledge..."
|
|
208
|
+
|
|
209
|
+
- type: PrintAction
|
|
210
|
+
id: synthesize-info
|
|
211
|
+
props:
|
|
212
|
+
message: "Synthesizing information from step {{agent.stepCount}}..."
|
|
213
|
+
|
|
214
|
+
- type: Delay
|
|
215
|
+
id: rate-limit
|
|
216
|
+
props:
|
|
217
|
+
delayMs: 1000
|
|
218
|
+
|
|
219
|
+
# Step 3: Quality assurance (parallel checks)
|
|
220
|
+
- type: Parallel
|
|
221
|
+
id: quality-checks
|
|
222
|
+
name: Quality Assurance
|
|
223
|
+
props:
|
|
224
|
+
strategy: strict
|
|
225
|
+
children:
|
|
226
|
+
- type: Sequence
|
|
227
|
+
id: accuracy-check
|
|
228
|
+
children:
|
|
229
|
+
- type: PrintAction
|
|
230
|
+
id: verify-accuracy
|
|
231
|
+
props:
|
|
232
|
+
message: "Verifying accuracy of results..."
|
|
233
|
+
|
|
234
|
+
- type: SoftAssert
|
|
235
|
+
id: soft-accuracy-check
|
|
236
|
+
children:
|
|
237
|
+
- type: CheckCondition
|
|
238
|
+
id: accuracy-threshold
|
|
239
|
+
props:
|
|
240
|
+
key: result.accuracy
|
|
241
|
+
operator: ">"
|
|
242
|
+
value: 0.8
|
|
243
|
+
|
|
244
|
+
- type: Sequence
|
|
245
|
+
id: completeness-check
|
|
246
|
+
children:
|
|
247
|
+
- type: PrintAction
|
|
248
|
+
id: verify-completeness
|
|
249
|
+
props:
|
|
250
|
+
message: "Checking completeness of response..."
|
|
251
|
+
|
|
252
|
+
- type: CheckCondition
|
|
253
|
+
id: completeness-threshold
|
|
254
|
+
props:
|
|
255
|
+
key: result.completeness
|
|
256
|
+
operator: ">"
|
|
257
|
+
value: 0.7
|
|
258
|
+
|
|
259
|
+
- type: Sequence
|
|
260
|
+
id: safety-check
|
|
261
|
+
children:
|
|
262
|
+
- type: PrintAction
|
|
263
|
+
id: run-safety-filters
|
|
264
|
+
props:
|
|
265
|
+
message: "Running safety and content filters..."
|
|
266
|
+
|
|
267
|
+
- type: CheckCondition
|
|
268
|
+
id: safety-passed
|
|
269
|
+
props:
|
|
270
|
+
key: result.safetyScore
|
|
271
|
+
operator: ">"
|
|
272
|
+
value: 0.9
|
|
273
|
+
|
|
274
|
+
# Step 4: Response formatting with retry
|
|
275
|
+
- type: Timeout
|
|
276
|
+
id: formatting-timeout
|
|
277
|
+
props:
|
|
278
|
+
timeoutMs: 30000
|
|
279
|
+
children:
|
|
280
|
+
- type: Sequence
|
|
281
|
+
id: format-response
|
|
282
|
+
children:
|
|
283
|
+
- type: PrintAction
|
|
284
|
+
id: structure-response
|
|
285
|
+
props:
|
|
286
|
+
message: "Structuring response..."
|
|
287
|
+
|
|
288
|
+
- type: Conditional
|
|
289
|
+
id: check-format-preference
|
|
290
|
+
props:
|
|
291
|
+
condition:
|
|
292
|
+
key: user.preferMarkdown
|
|
293
|
+
operator: "=="
|
|
294
|
+
value: true
|
|
295
|
+
children:
|
|
296
|
+
# If markdown preferred
|
|
297
|
+
- type: PrintAction
|
|
298
|
+
id: format-markdown
|
|
299
|
+
props:
|
|
300
|
+
message: "Formatting as markdown..."
|
|
301
|
+
|
|
302
|
+
# Else: plain text
|
|
303
|
+
- type: PrintAction
|
|
304
|
+
id: format-plaintext
|
|
305
|
+
props:
|
|
306
|
+
message: "Formatting as plain text..."
|
|
307
|
+
|
|
308
|
+
- type: PrintAction
|
|
309
|
+
id: add-citations
|
|
310
|
+
props:
|
|
311
|
+
message: "Adding citations and sources..."
|
|
312
|
+
|
|
313
|
+
# Step 5: Delivery and feedback loop
|
|
314
|
+
- type: Sequence
|
|
315
|
+
id: delivery
|
|
316
|
+
name: Response Delivery
|
|
317
|
+
children:
|
|
318
|
+
- type: PrintAction
|
|
319
|
+
id: send-response
|
|
320
|
+
props:
|
|
321
|
+
message: "Sending response to user..."
|
|
322
|
+
|
|
323
|
+
- type: Parallel
|
|
324
|
+
id: post-delivery
|
|
325
|
+
props:
|
|
326
|
+
strategy: any # Best effort
|
|
327
|
+
children:
|
|
328
|
+
- type: PrintAction
|
|
329
|
+
id: log-interaction
|
|
330
|
+
props:
|
|
331
|
+
message: "Logging interaction for analytics..."
|
|
332
|
+
|
|
333
|
+
- type: PrintAction
|
|
334
|
+
id: update-context
|
|
335
|
+
props:
|
|
336
|
+
message: "Updating conversation context..."
|
|
337
|
+
|
|
338
|
+
- type: PrintAction
|
|
339
|
+
id: store-feedback
|
|
340
|
+
props:
|
|
341
|
+
message: "Storing feedback signals..."
|
|
342
|
+
|
|
343
|
+
- type: PrintAction
|
|
344
|
+
id: agent-complete
|
|
345
|
+
props:
|
|
346
|
+
message: "AI agent workflow completed successfully!"
|