update README.md
This commit is contained in:
284
README.md
284
README.md
@@ -2,74 +2,42 @@
|
|||||||
|
|
||||||
> A TypeScript/JavaScript library for building dynamic, LLM-driven workflows using a region-based execution model.
|
> A TypeScript/JavaScript library for building dynamic, LLM-driven workflows using a region-based execution model.
|
||||||
|
|
||||||
|

|
||||||

|

|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
### Used in production by:
|
|
||||||
- [AI](https://geoff.seemueller.io) 🫣
|
|
||||||
|
|
||||||
|
|
||||||
CLI: `npx workflow-function-manifold`
|
|
||||||
|
|
||||||
## Table of Contents
|
|
||||||
|
|
||||||
- [Overview](#overview)
|
|
||||||
- [Installation](#installation)
|
|
||||||
- [Quick Start](#quick-start)
|
|
||||||
- [Core Components](#core-components)
|
|
||||||
- [Complete Example](#complete-example)
|
|
||||||
- [API Reference](#api-reference)
|
|
||||||
- [State Management](#state-management)
|
|
||||||
- [LLM Integration](#llm-integration)
|
|
||||||
- [Error Handling](#error-handling)
|
|
||||||
- [Contributing](#contributing)
|
|
||||||
- [License](#license)
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
`workflow-function-manifold` enables you to create dynamic workflows that:
|
`workflow-function-manifold` is a powerful library for creating dynamic, LLM-driven workflows that leverage a region-based execution model. It enables seamless navigation between different execution regions based on natural language prompts and maintains consistent workflow state throughout the execution process.
|
||||||
|
|
||||||
- Navigate between different execution regions based on LLM-interpreted intents.
|
### Key Features
|
||||||
- Execute operations within regions using state and context.
|
|
||||||
- Maintain workflow state across operations.
|
|
||||||
- Support flexible region-to-region connections.
|
|
||||||
|
|
||||||
```mermaid
|
- **LLM-Driven Navigation**: Navigate between workflow regions using natural language prompts
|
||||||
graph TD
|
- **Region-Based Architecture**: Organize workflow logic into discrete, connected regions
|
||||||
MF[Workflow Function Manifold] -->|Initialize| CR[Current Region]
|
- **State Management**: Maintain and propagate state across workflow operations
|
||||||
MF -->|Navigate| AR[Adjacent Regions]
|
- **Nested Workflows**: Support for hierarchical workflow structures
|
||||||
MF -->|Execute| OP[Operators]
|
- **Intent Matching**: Built-in intent recognition system with confidence scoring
|
||||||
OP -->|Use| Intent[Intent Service]
|
- **TypeScript/Javascript Support**
|
||||||
LLM -->|Match| INT[Intent]
|
|
||||||
INT --> OP
|
### _Try it_
|
||||||
OP -->|Update| ST[Workflow State]
|
```bash
|
||||||
ST -->|Inform| AR
|
npx workflow-function-manifold
|
||||||
AR -->|Check| NR[Next Region]
|
|
||||||
NR -->|If Valid| CR
|
|
||||||
CR -->|Continue| OP
|
|
||||||
NR -->|If Invalid| END[End]
|
|
||||||
style MF fill:#000000,stroke:#FFFFFF,stroke-width:4px,color:#ffffff
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install the library via npm:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install workflow-function-manifold
|
npm install workflow-function-manifold
|
||||||
```
|
```
|
||||||
|
|
||||||
Run a basic demonstration using the CLI:
|
Or using Bun:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx workflow-function-manifold
|
bun add workflow-function-manifold
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import {
|
import {
|
||||||
WorkflowFunctionManifold,
|
WorkflowFunctionManifold,
|
||||||
ManifoldRegion,
|
ManifoldRegion,
|
||||||
@@ -77,168 +45,186 @@ import {
|
|||||||
DummyIntentMap,
|
DummyIntentMap,
|
||||||
} from 'workflow-function-manifold';
|
} from 'workflow-function-manifold';
|
||||||
|
|
||||||
const llm = new DummyIntentMap();
|
// Create a new manifold instance
|
||||||
const manifold = new WorkflowFunctionManifold(llm);
|
const intentService = new DummyIntentMap();
|
||||||
|
const manifold = new WorkflowFunctionManifold(intentService);
|
||||||
|
|
||||||
|
// Define operators
|
||||||
const analysisOperator = new WorkflowOperator('analysis', async state => ({
|
const analysisOperator = new WorkflowOperator('analysis', async state => ({
|
||||||
...state,
|
...state,
|
||||||
analyzed: true,
|
analyzed: true,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Create regions
|
||||||
const analysisRegion = new ManifoldRegion('analysis', [analysisOperator]);
|
const analysisRegion = new ManifoldRegion('analysis', [analysisOperator]);
|
||||||
|
|
||||||
manifold.addRegion(analysisRegion);
|
manifold.addRegion(analysisRegion);
|
||||||
|
|
||||||
|
// Execute workflow
|
||||||
await manifold.navigate('analyze the data');
|
await manifold.navigate('analyze the data');
|
||||||
await manifold.executeWorkflow('analyze the data');
|
await manifold.executeWorkflow('analyze the data');
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** `DummyIntentMap` uses basic keyword matching. Include keywords like `'analyze'`, `'process'`, or `'transform'` for default operators to work.
|
|
||||||
|
|
||||||
## Core Components
|
## Core Components
|
||||||
|
|
||||||
### `WorkflowFunctionManifold`
|
### WorkflowFunctionManifold
|
||||||
|
|
||||||
The main orchestrator for workflow execution.
|
The main orchestrator that manages workflow execution and region navigation.
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
const manifold = new WorkflowFunctionManifold(llmService);
|
const manifold = new WorkflowFunctionManifold(intentService);
|
||||||
manifold.addRegion(region);
|
manifold.addRegion(region);
|
||||||
await manifold.navigate(prompt);
|
await manifold.navigate(prompt);
|
||||||
await manifold.executeWorkflow(prompt);
|
await manifold.executeWorkflow(prompt);
|
||||||
```
|
```
|
||||||
|
|
||||||
### `ManifoldRegion`
|
### ManifoldRegion
|
||||||
|
|
||||||
Represents a workflow region containing operators and connections to other regions.
|
Represents a discrete workflow area containing operators and connections to other regions.
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
const region = new ManifoldRegion('regionName', [operator1, operator2]);
|
const region = new ManifoldRegion('regionName', [operator1, operator2]);
|
||||||
region.connectTo(otherRegion);
|
region.connectTo(otherRegion);
|
||||||
region.addOperator(newOperator);
|
region.addOperator(newOperator);
|
||||||
```
|
```
|
||||||
|
|
||||||
### `WorkflowOperator`
|
### WorkflowOperator
|
||||||
|
|
||||||
Defines an operation that can be executed within a region.
|
Defines executable operations within regions.
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
const operator = new WorkflowOperator('operatorName', async state => newState);
|
const operator = new WorkflowOperator('operatorName', async state => {
|
||||||
|
return { ...state, processed: true };
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### `DummyIntentMap`
|
### NestedManifoldRegion
|
||||||
|
|
||||||
A basic intent-matching service.
|
Enables hierarchical workflow structures by embedding one manifold within another.
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
const intentService = new DummyIntentMap();
|
const nestedManifold = new WorkflowFunctionManifold(intentService);
|
||||||
const intent = await intentService.query('analyze the data');
|
const nestedRegion = new NestedManifoldRegion('preprocessing', nestedManifold);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Complete Example
|
## Complete Example
|
||||||
|
|
||||||
Here's a complete workflow demonstration:
|
Here's a comprehensive example demonstrating nested workflows:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {
|
||||||
|
WorkflowFunctionManifold,
|
||||||
|
ManifoldRegion,
|
||||||
|
WorkflowOperator,
|
||||||
|
NestedManifoldRegion,
|
||||||
|
DummyIntentMap,
|
||||||
|
} from 'workflow-function-manifold';
|
||||||
|
|
||||||
```javascript
|
|
||||||
async function createWorkflow() {
|
async function createWorkflow() {
|
||||||
const intentService = new DummyIntentMap();
|
// Create nested workflow for preprocessing
|
||||||
const manifold = new WorkflowFunctionManifold(intentService);
|
const nestedIntentService = new DummyIntentMap();
|
||||||
|
const nestedManifold = new WorkflowFunctionManifold(nestedIntentService);
|
||||||
|
|
||||||
|
const validateOp = new WorkflowOperator('validation', async state => ({
|
||||||
|
...state,
|
||||||
|
validated: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const cleanOp = new WorkflowOperator('cleaning', async state => ({
|
||||||
|
...state,
|
||||||
|
cleaned: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const validateRegion = new ManifoldRegion('validation', [validateOp]);
|
||||||
|
const cleanRegion = new ManifoldRegion('cleaning', [cleanOp]);
|
||||||
|
|
||||||
|
validateRegion.connectTo(cleanRegion);
|
||||||
|
nestedManifold.addRegion(validateRegion);
|
||||||
|
nestedManifold.addRegion(cleanRegion);
|
||||||
|
|
||||||
const analysisOp = new WorkflowOperator('analysis', async state => ({
|
// Create main workflow
|
||||||
...state,
|
const mainIntentService = new DummyIntentMap();
|
||||||
analyzed: true,
|
const mainManifold = new WorkflowFunctionManifold(mainIntentService);
|
||||||
}));
|
|
||||||
|
const nestedPreprocessRegion = new NestedManifoldRegion('preprocessing', nestedManifold);
|
||||||
const processingOp = new WorkflowOperator('processing', async state => ({
|
const analysisRegion = new ManifoldRegion('analysis', [
|
||||||
...state,
|
new WorkflowOperator('analysis', async state => ({
|
||||||
processed: true,
|
...state,
|
||||||
}));
|
analyzed: true,
|
||||||
|
})),
|
||||||
const transformOp = new WorkflowOperator('transformation', async state => ({
|
]);
|
||||||
...state,
|
|
||||||
transformed: true,
|
nestedPreprocessRegion.connectTo(analysisRegion);
|
||||||
}));
|
mainManifold.addRegion(nestedPreprocessRegion);
|
||||||
|
mainManifold.addRegion(analysisRegion);
|
||||||
const analysisRegion = new ManifoldRegion('analysis', [analysisOp]);
|
|
||||||
const processingRegion = new ManifoldRegion('processing', [processingOp]);
|
return mainManifold;
|
||||||
const transformRegion = new ManifoldRegion('transformation', [transformOp]);
|
|
||||||
|
|
||||||
analysisRegion.connectTo(processingRegion);
|
|
||||||
processingRegion.connectTo(transformRegion);
|
|
||||||
|
|
||||||
manifold.addRegion(analysisRegion);
|
|
||||||
manifold.addRegion(processingRegion);
|
|
||||||
manifold.addRegion(transformRegion);
|
|
||||||
|
|
||||||
return manifold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute workflow
|
||||||
const manifold = await createWorkflow();
|
const manifold = await createWorkflow();
|
||||||
|
const prompts = [
|
||||||
const prompts = ['analyze the data', 'process the results', 'transform the output'];
|
'validate the input',
|
||||||
|
'clean the data',
|
||||||
|
'analyze the results',
|
||||||
|
];
|
||||||
|
|
||||||
for (const prompt of prompts) {
|
for (const prompt of prompts) {
|
||||||
await manifold.navigate(prompt);
|
await manifold.navigate(prompt);
|
||||||
await manifold.executeWorkflow(prompt);
|
await manifold.executeWorkflow(prompt);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## API Reference
|
|
||||||
|
|
||||||
### `WorkflowFunctionManifold`
|
|
||||||
|
|
||||||
#### Constructor
|
|
||||||
|
|
||||||
- `constructor(intentService: IntentService)`
|
|
||||||
|
|
||||||
#### Methods
|
|
||||||
|
|
||||||
- `addRegion(region: ManifoldRegion | NestedManifoldRegion): void`
|
|
||||||
- `navigate(prompt: string): Promise<boolean>`
|
|
||||||
- `executeWorkflow(prompt: string): Promise<boolean>`
|
|
||||||
|
|
||||||
### `ManifoldRegion`
|
|
||||||
|
|
||||||
#### Constructor
|
|
||||||
|
|
||||||
- `constructor(name: string, operators: WorkflowOperator[] = [])`
|
|
||||||
|
|
||||||
#### Methods
|
|
||||||
|
|
||||||
- `addOperator(operator: WorkflowOperator): void`
|
|
||||||
- `connectTo(region: ManifoldRegion): void`
|
|
||||||
|
|
||||||
## State Management
|
## State Management
|
||||||
|
|
||||||
Operators access and modify the state persistently:
|
The library maintains workflow state across operations and regions. Each operator can access and modify the state:
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
const operator = new WorkflowOperator('example', async state => ({
|
const operator = new WorkflowOperator('example', async state => {
|
||||||
...state,
|
// Access existing state
|
||||||
newValue: 'updated',
|
const currentValue = state.someValue;
|
||||||
}));
|
|
||||||
|
// Return modified state
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
newValue: 'updated',
|
||||||
|
processed: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Error Handling
|
## Error Handling
|
||||||
|
|
||||||
### Navigation Errors
|
The library includes built-in error handling for:
|
||||||
|
|
||||||
- Logs warnings for unmatched prompts.
|
- Invalid navigation attempts
|
||||||
|
- Unmatched intents
|
||||||
### Operator Execution Errors
|
- Operation execution failures
|
||||||
|
- State management errors
|
||||||
- Logs warnings for unmatched operators.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork the repository.
|
1. Fork the repository
|
||||||
2. Create a new branch: `git checkout -b feature/my-feature`.
|
2. Create your feature branch: `git checkout -b feature/my-feature`
|
||||||
3. Commit changes: `git commit -m "Add my feature"`.
|
3. Commit your changes: `git commit -m 'Add my feature'`
|
||||||
4. Push the branch: `git push origin feature/my-feature`.
|
4. Push to the branch: `git push origin feature/my-feature`
|
||||||
5. Open a pull request.
|
5. Submit a pull request
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT © 2024 Geoff Seemueller
|
MIT © 2024 Geoff Seemueller
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install dependencies
|
||||||
|
bun install
|
||||||
|
|
||||||
|
# Run development mode
|
||||||
|
bun dev
|
||||||
|
|
||||||
|
# Build for production
|
||||||
|
bun run build
|
||||||
|
|
||||||
|
# Fix formatting and lint issues
|
||||||
|
bun run fix
|
||||||
|
```
|
Reference in New Issue
Block a user