Skip to main content

Getting Started with AI Workflow

This guide will help you get up and running with AI Workflow quickly.

Prerequisites

Before you begin, ensure you have:

  • Node.js 20.0 or higher
  • npm or yarn package manager
  • Git installed
  • Access to AI services (OpenAI, Anthropic, etc.)

Installation

Step 1: Install Dependencies

npm install ai-workflow

Step 2: Configure Environment

Create a .env file in your project root:

AI_WORKFLOW_API_KEY=your_api_key_here
AI_WORKFLOW_ENV=development
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key

Step 3: Initialize Project

npx ai-workflow init

Basic Usage

Example 1: Create a Workflow

import { AIWorkflow } from 'ai-workflow';

const workflow = new AIWorkflow({
apiKey: process.env.AI_WORKFLOW_API_KEY
});

// Create a new workflow
const myWorkflow = await workflow.create({
name: 'Data Processing Workflow',
description: 'Processes and analyzes data using AI'
});

Example 2: Add Steps to Workflow

// Add steps to your workflow
await workflow.addStep(myWorkflow.id, {
name: 'Data Ingestion',
type: 'data-input',
config: {
source: 'database',
table: 'raw_data'
}
});

await workflow.addStep(myWorkflow.id, {
name: 'AI Analysis',
type: 'ai-process',
config: {
model: 'gpt-4',
prompt: 'Analyze the following data...'
}
});

Example 3: Execute Workflow

// Execute the workflow
const result = await workflow.execute(myWorkflow.id, {
input: { data: 'your data here' }
});

console.log('Workflow result:', result);

Configuration Options

OptionDescriptionDefaultRequired
apiKeyYour API key-Yes
environmentEnvironment modedevelopmentNo
timeoutRequest timeout (ms)30000No
maxRetriesMaximum retry attempts3No

Managing Multiple Workflows

AI Workflow supports managing multiple workflows simultaneously:

// List all workflows
const workflows = await workflow.list();

// Get a specific workflow
const workflow1 = await workflow.get('workflow-id-1');
const workflow2 = await workflow.get('workflow-id-2');

// Execute multiple workflows in parallel
const results = await Promise.all([
workflow.execute('workflow-id-1', { input: data1 }),
workflow.execute('workflow-id-2', { input: data2 })
]);

Verification

Verify your installation:

npx ai-workflow verify

You should see:

✓ AI Workflow is configured correctly
✓ Connection to API successful
✓ Workflow engine ready

Troubleshooting

Common Issues

Issue: API key not recognized

  • Solution: Check your .env file and ensure the key is correct

Issue: Workflow execution fails

  • Solution: Verify all workflow steps are properly configured

Issue: Timeout errors

  • Solution: Increase the timeout value in configuration

Next Steps