Rename project, enhance documentation, and add error handling.
Updated project name and description in package.json for clearer purpose. Enhanced README with a detailed table of contents and error handling section. Improved error handling in index.js with comprehensive logging for various failure scenarios.
This commit is contained in:
53
README.md
53
README.md
@@ -5,6 +5,19 @@
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
|
## 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` enables you to create dynamic workflows that:
|
||||||
@@ -241,6 +254,46 @@ class CustomLLMService {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### **Error Handling**
|
||||||
|
|
||||||
|
This library includes basic error handling to ensure workflows continue running smoothly, even when unexpected issues arise.
|
||||||
|
|
||||||
|
#### **Navigation Errors**
|
||||||
|
|
||||||
|
If a prompt doesn't match a valid adjacent region, the system will:
|
||||||
|
- Log a warning: `No valid region found for prompt: "<prompt>"`
|
||||||
|
- Continue without changing the current region.
|
||||||
|
|
||||||
|
#### **Operator Execution Errors**
|
||||||
|
|
||||||
|
If no matching operator is found for a prompt, or an operator encounters an error during execution:
|
||||||
|
- Log a warning: `No matching operator found for intent: <intent>`
|
||||||
|
- Log an error if execution fails: `Error during workflow execution for prompt "<prompt>": <error message>`
|
||||||
|
|
||||||
|
#### **LLM Query Errors**
|
||||||
|
|
||||||
|
In case of issues querying the LLM service:
|
||||||
|
- Log an error: `Error during navigation for prompt "<prompt>": <error message>`
|
||||||
|
|
||||||
|
#### **Example Error Logging**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const manifold = new WorkflowFunctionManifold(new DummyLlmService());
|
||||||
|
|
||||||
|
try {
|
||||||
|
await manifold.navigate('unknown command');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Critical navigation error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await manifold.executeWorkflow('perform unknown action');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Critical execution error:', error);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork the repository
|
1. Fork the repository
|
||||||
|
23
index.js
23
index.js
@@ -66,32 +66,45 @@ class WorkflowFunctionManifold {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async navigate(prompt) {
|
async navigate(prompt) {
|
||||||
|
try {
|
||||||
const intent = await this.llmService.query(prompt);
|
const intent = await this.llmService.query(prompt);
|
||||||
|
|
||||||
// Find best region based on intent
|
// Find the best matching adjacent region
|
||||||
const nextRegion = Array.from(this.currentRegion.adjacentRegions)
|
const nextRegion = Array.from(this.currentRegion.adjacentRegions)
|
||||||
.find(region => region.name.toLowerCase().includes(intent.action));
|
.find(region => region.name.toLowerCase().includes(intent.action));
|
||||||
|
|
||||||
if (nextRegion && intent.confidence > 0.5) {
|
if (nextRegion && intent.confidence > 0.5) {
|
||||||
this.currentRegion = nextRegion;
|
this.currentRegion = nextRegion;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
console.warn(`No valid region found for prompt: "${prompt}"`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error during navigation for prompt "${prompt}":`, error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async executeWorkflow(prompt) {
|
async executeWorkflow(prompt) {
|
||||||
|
try {
|
||||||
const operators = await this.currentRegion.getValidOperators(this.state);
|
const operators = await this.currentRegion.getValidOperators(this.state);
|
||||||
const intent = await this.llmService.query(prompt);
|
const intent = await this.llmService.query(prompt);
|
||||||
|
|
||||||
const matchedOperator = operators
|
const matchedOperator = operators.find(op => op.name.toLowerCase().includes(intent.action));
|
||||||
.find(op => op.name.toLowerCase().includes(intent.action));
|
|
||||||
|
|
||||||
if (matchedOperator) {
|
if (matchedOperator) {
|
||||||
this.state = await matchedOperator.execute(this.state);
|
this.state = await matchedOperator.execute(this.state);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
console.warn(`No matching operator found for intent: ${intent.action}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error during workflow execution for prompt "${prompt}":`, error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usage Example
|
// Usage Example
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "manifold",
|
"name": "workflow-function-manifold",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "for building dynamic, LLM-driven workflows using a region-based execution model",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user