Add support for nested manifolds

Introduced the `NestedManifoldRegion` class to enable embedding of `WorkflowFunctionManifold` inside regions, allowing hierarchical workflows. Updated `bin.js` to demonstrate the new functionality and adjusted `lib.js` for nested region navigation and execution logic. Updated `package.json` to specify "type": "module" for ES module support.
This commit is contained in:
2024-11-09 14:01:59 -05:00
parent 7abd62046a
commit 41f4151d41
4 changed files with 173 additions and 120 deletions

View File

@@ -153,6 +153,43 @@ const intent = await llm.query('analyze the data');
// Returns: { confidence: 0.9, action: 'analysis' }
```
## Nested Manifolds
### NestedManifoldRegion
A `NestedManifoldRegion` allows embedding a `WorkflowFunctionManifold` inside a region. This enables creating hierarchical workflows where regions themselves contain sub-workflows.
```javascript
import {
WorkflowFunctionManifold,
NestedManifoldRegion,
ManifoldRegion,
WorkflowOperator,
DummyLlmService,
} from 'workflow-function-manifold';
// Sub-workflow
const nestedLlm = new DummyLlmService();
const nestedManifold = new WorkflowFunctionManifold(nestedLlm);
const nestedOperator = new WorkflowOperator('nestedOperation', async state => {
return { ...state, nested: true };
});
const nestedRegion = new ManifoldRegion('nestedRegion', [nestedOperator]);
nestedManifold.addRegion(nestedRegion);
// Main workflow
const mainLlm = new DummyLlmService();
const mainManifold = new WorkflowFunctionManifold(mainLlm);
const nestedManifoldRegion = new NestedManifoldRegion('nestedManifoldRegion', nestedManifold);
mainManifold.addRegion(nestedManifoldRegion);
await mainManifold.navigate('perform nested operation');
await mainManifold.executeWorkflow('perform nested operation');
```
## Complete Example
Here's a full example demonstrating a three-stage workflow:
@@ -241,6 +278,10 @@ console.log(manifold.state); // Final state after all operations
- `async execute(state: any): Promise<any>`
### NestedManifoldRegion
- Extends `ManifoldRegion` and embeds a `WorkflowFunctionManifold`.
## State Management
The workflow maintains state across operations. Each operator can access and