Geoff Seemueller 67542301be Refactor project structure and update build scripts
Moved main files to the "src" directory and updated paths accordingly. Adjusted build, start, and dev scripts to use Bun. Added "dist" directory to .gitignore to prevent it from being tracked.
2024-11-14 23:09:37 -05:00
2024-11-09 11:40:25 -05:00
2024-11-09 11:40:25 -05:00
2024-11-09 13:12:26 -05:00
2024-11-14 22:58:59 -05:00
2024-11-14 22:58:59 -05:00
2024-11-14 22:58:59 -05:00

workflow-function-manifold

A TypeScript/JavaScript library for building dynamic, LLM-driven workflows using a region-based execution model.

License: MIT
Node Version

Used in production by:

CLI: npx workflow-function-manifold

Table of Contents

Overview

workflow-function-manifold enables you to create dynamic workflows that:

  • Navigate between different execution regions based on LLM-interpreted intents.
  • Execute operations within regions using state and context.
  • Maintain workflow state across operations.
  • Support flexible region-to-region connections.
graph TD
   MF[Workflow Function Manifold] -->|Initialize| CR[Current Region]
   MF -->|Navigate| AR[Adjacent Regions]
   MF -->|Execute| OP[Operators]
   OP -->|Use| Intent[Intent Service]
   LLM -->|Match| INT[Intent]
   INT --> OP
   OP -->|Update| ST[Workflow State]
   ST -->|Inform| AR
   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

Install the library via npm:

npm install workflow-function-manifold

Run a basic demonstration using the CLI:

npx workflow-function-manifold

Quick Start

import {
  WorkflowFunctionManifold,
  ManifoldRegion,
  WorkflowOperator,
  DummyIntentMap,
} from 'workflow-function-manifold';

const llm = new DummyIntentMap();
const manifold = new WorkflowFunctionManifold(llm);

const analysisOperator = new WorkflowOperator('analysis', async state => ({
  ...state,
  analyzed: true,
}));

const analysisRegion = new ManifoldRegion('analysis', [analysisOperator]);

manifold.addRegion(analysisRegion);

await manifold.navigate('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

WorkflowFunctionManifold

The main orchestrator for workflow execution.

const manifold = new WorkflowFunctionManifold(llmService);
manifold.addRegion(region);
await manifold.navigate(prompt);
await manifold.executeWorkflow(prompt);

ManifoldRegion

Represents a workflow region containing operators and connections to other regions.

const region = new ManifoldRegion('regionName', [operator1, operator2]);
region.connectTo(otherRegion);
region.addOperator(newOperator);

WorkflowOperator

Defines an operation that can be executed within a region.

const operator = new WorkflowOperator('operatorName', async state => newState);

DummyIntentMap

A basic intent-matching service.

const intentService = new DummyIntentMap();
const intent = await intentService.query('analyze the data');

Complete Example

Here's a complete workflow demonstration:

async function createWorkflow() {
    const intentService = new DummyIntentMap();
    const manifold = new WorkflowFunctionManifold(intentService);

    const analysisOp = new WorkflowOperator('analysis', async state => ({
        ...state,
        analyzed: true,
    }));

    const processingOp = new WorkflowOperator('processing', async state => ({
        ...state,
        processed: true,
    }));

    const transformOp = new WorkflowOperator('transformation', async state => ({
        ...state,
        transformed: true,
    }));

    const analysisRegion = new ManifoldRegion('analysis', [analysisOp]);
    const processingRegion = new ManifoldRegion('processing', [processingOp]);
    const transformRegion = new ManifoldRegion('transformation', [transformOp]);

    analysisRegion.connectTo(processingRegion);
    processingRegion.connectTo(transformRegion);

    manifold.addRegion(analysisRegion);
    manifold.addRegion(processingRegion);
    manifold.addRegion(transformRegion);

    return manifold;
}

const manifold = await createWorkflow();

const prompts = ['analyze the data', 'process the results', 'transform the output'];

for (const prompt of prompts) {
    await manifold.navigate(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

Operators access and modify the state persistently:

const operator = new WorkflowOperator('example', async state => ({
  ...state,
  newValue: 'updated',
}));

Error Handling

Navigation Errors

  • Logs warnings for unmatched prompts.

Operator Execution Errors

  • Logs warnings for unmatched operators.

Contributing

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/my-feature.
  3. Commit changes: git commit -m "Add my feature".
  4. Push the branch: git push origin feature/my-feature.
  5. Open a pull request.

License

MIT © 2024 Geoff Seemueller

Description
for building dynamic, LLM-driven workflows using a region-based execution model
Readme 415 KiB
Languages
TypeScript 75.8%
JavaScript 24.2%