Skip to main content

Overview

The user_workflows table stores workflow configurations for each user. Each user can have one workflow that contains elements (agents) and their connections.

Table Schema

id
string
required
Unique identifier for the workflow record (auto-generated UUID)
user_id
string
required
Foreign key reference to the authenticated user
name
string
required
Display name of the workflow (default: “My Workflow”)
data
object
required
Complete workflow data structure containing elements and connections
created_at
string
ISO 8601 timestamp of when the workflow was created
updated_at
string
ISO 8601 timestamp of the last workflow update

TypeScript Interface

export interface WorkflowElement {
  id: string;
  type: 'agent';
  agentId: string;
  position: Position;
  data: {
    name: string;
    description: string;
    color?: string;
    icon?: string;
  };
}

export interface Connection {
  id: string;
  sourceId: string;
  targetId: string;
  type: string;
  data?: any;
}

export interface Workflow {
  id: string;
  name: string;
  elements: WorkflowElement[];
  connections: Connection[];
}

export interface Position {
  x: number;
  y: number;
}

CRUD Operations

Save Workflow

Saves or updates the user’s workflow. If a workflow already exists for the user, it will be updated; otherwise, a new workflow is created. Endpoint: manage-workflows Request:
{
  "action": "save",
  "workflowData": {
    "id": "workflow-1",
    "name": "My Workflow",
    "elements": [
      {
        "id": "element-1",
        "type": "agent",
        "agentId": "agent-1",
        "position": { "x": 100, "y": 100 },
        "data": {
          "name": "Data Processor",
          "description": "Processes incoming data",
          "color": "#3B82F6",
          "icon": "processor"
        }
      }
    ],
    "connections": [
      {
        "id": "conn-1",
        "sourceId": "element-1",
        "targetId": "element-2",
        "type": "default"
      }
    ]
  }
}
Response:
{
  "message": "Workflow saved successfully",
  "workflow": {
    "id": "uuid",
    "user_id": "user-uuid",
    "name": "My Workflow",
    "data": { /* workflow data */ },
    "created_at": "2026-03-03T10:00:00Z",
    "updated_at": "2026-03-03T10:00:00Z"
  }
}

Load Workflow

Retrieves the user’s saved workflow. Endpoint: manage-workflows Request:
{
  "action": "load"
}
Response:
{
  "success": true,
  "workflow": {
    "id": "uuid",
    "user_id": "user-uuid",
    "name": "My Workflow",
    "data": { /* workflow data */ },
    "created_at": "2026-03-03T10:00:00Z",
    "updated_at": "2026-03-03T10:00:00Z"
  }
}
If no workflow exists:
{
  "success": true,
  "workflow": null
}

Relationships

  • user_id → References the authenticated user’s ID
  • elements[].agentId → References agent configurations in the agent_configs table
  • connections → Links workflow elements together, stored separately in agent_connections table

Constraints

  • Each user can have only one workflow record (enforced by checking existing workflows before insert/update)
  • The user_id field must reference a valid authenticated user
  • The data field must contain valid JSON with the Workflow interface structure

Build docs developers (and LLMs) love