Spec: Task Builder β Visual Workflow Editor with MongoDB Persistence
Overviewβ
Build a visual Task Builder UI for creating and managing task_config.yaml-style self-service workflows, persist them in MongoDB (task_configs collection), and modify the supervisor agent to read task configs from MongoDB instead of the YAML file. On first boot, the existing task_config.yaml seeds MongoDB; after that, MongoDB is the source of truth.
Motivationβ
Currently there is a disconnect between the UI and the supervisor:
- The UI has an Agent Builder / Skills Builder that saves workflow configs to MongoDB (
agent_skillscollection), but the supervisor never reads from it. - The supervisor (
deep_agent_single.py) reads workflows exclusively fromtask_config.yamlon disk viaload_task_config(). - There is no bridge between them β workflows created in the UI are not available to
invoke_self_service_task.
This means:
- Adding or editing a workflow requires modifying
task_config.yaml, rebuilding the Helm chart, and redeploying. - Non-developer users cannot create custom self-service workflows.
- The UI and backend have divergent workflow inventories.
The Task Builder feature solves this by:
- Providing a visual flow editor for building multi-step workflows with
@xyflow/react. - Storing all task configs in a dedicated MongoDB collection (
task_configs). - Making the supervisor read from MongoDB (with YAML as fallback), so newly created workflows are immediately available without redeployment.
Scopeβ
In Scopeβ
- MongoDB
task_configscollection: New collection with schema mirroringtask_config.yamlstructure plus metadata (owner, visibility, timestamps). - YAML seeding: On first boot, seed MongoDB from the bundled
task_config.yamlasis_system: truedocuments. Idempotent β skip if collection is non-empty. - Next.js API (
/api/task-configs): Full CRUD (GET, POST, PUT, DELETE) plus/api/task-configs/seedand YAML export (?format=yaml). - Zustand store (
task-config-store.ts): Client-side state management for task configs. - Visual Task Builder UI (
/task-builder): Flow-based editor using@xyflow/reactwith custom node types (UserInput, Generate, Output), sidebar property editor, save/export/import. - Navigation update: Add "Task Builder" to the app sidebar/header.
- Supervisor MongoDB integration: Modify
load_task_config()indeep_agent_single.pyto read from MongoDB via pymongo (with in-memory TTL cache), falling back to YAML. - Shared pymongo client: New
ai_platform_engineering/utils/mongodb_client.pysingleton. - Documentation: Spec (this document) and ADR.
Out of Scopeβ
- Replacing or modifying the existing Agent Builder / Skills Builder (those remain as-is for skill/quick-start template management).
- Real-time collaboration / multi-user editing of the same workflow.
- Version history / diff for task configs (future).
- Workflow execution preview / dry-run from the builder UI (future).
- Migrating existing
agent_skillsdata intotask_configs(they serve different purposes).
Designβ
Architectureβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β First Boot β
β task_config.yaml ββseedβββΆ MongoDB (task_configs collection) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js UI β
β Task Builder (visual flow editor) β
β β β
β βΌ β
β /api/task-configs (CRUD) βββΆ MongoDB (task_configs) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Python Supervisor β
β deep_agent_single.py β
β β β
β βββpymongoβββΆ MongoDB (task_configs) [primary] β
β βββfallbackβββΆ task_config.yaml [if MongoDB down] β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Data Modelβ
MongoDB task_configs collection:
interface TaskConfig {
id: string; // unique ID (e.g., "task-config-<timestamp>-<random>")
name: string; // workflow name, unique (e.g., "Create GitHub Repo")
category: string; // e.g., "GitHub Operations", "AWS Operations"
description?: string;
tasks: TaskStep[]; // ordered list of workflow steps
owner_id: string; // "system" for YAML-seeded, user email for custom
is_system: boolean; // true for YAML-seeded configs
visibility: "private" | "team" | "global";
shared_with_teams?: string[];
metadata?: {
env_vars_required?: string[];
estimated_duration?: string;
tags?: string[];
};
created_at: Date;
updated_at: Date;
}
interface TaskStep {
display_text: string; // UI label (e.g., "Collect repository details")
llm_prompt: string; // LLM instructions with ${VAR} substitution
subagent: string; // target subagent (caipe, github, backstage, etc.)
}
Indexes:
name: uniquecategory: non-uniqueowner_id: non-uniqueis_system: non-uniquecreated_at: non-unique (descending)
Task Builder UI Designβ
The Task Builder uses @xyflow/react (already a project dependency) for a visual flow canvas:
Node types (color-coded):
- UserInput (yellow):
subagent: "caipe"β collects user input via forms - Generate (purple): processing subagents (github, backstage, jira, aws, argocd, aigateway)
- Output (green): notification/completion steps (webex, jira close)
Layout:
- Left: Step Templates palette (searchable, categorized, 154 draggable tool templates) + flow canvas with connected task step nodes (S-curve layout, bezier edges)
- Right: sidebar property editor for the selected node (display_text, llm_prompt code editor or CAIPE Form Builder, subagent selector); Environment variable panel
- Top: two-row toolbar with workflow metadata (name, category, description), grouped Import/Preview/Download bar, save
UX flow:
- User opens
/task-builder, sees empty canvas with "Add Step" button (or picks a workflow template) - Add nodes via drag-and-drop from Step Templates palette or "Add Step"; each represents a task step with display_text, subagent badge
- Connect nodes to define linear execution order (S-curve layout with bezier edges)
- Click a node to edit its properties in the sidebar (or CAIPE Form Builder for
caipesubagent steps) - Set workflow name, category, description in the toolbar
- Save β POST
/api/task-configsβ MongoDB - Workflow is immediately available to the supervisor
UX Enhancements (post-initial implementation):
- S-curve node layout: Nodes alternate left-right in an S-curve pattern with bezier curved edges instead of a straight vertical line.
- Step Templates palette: Left sidebar with 154 draggable tool templates from all integrated agents (CAIPE, GitHub, Jira, Webex, ArgoCD, AWS, AI Gateway, Backstage, Slack, PagerDuty, Splunk, Komodor, Confluence), searchable, categorized, with drag-and-drop onto canvas.
- CAIPE Form Builder: Structured form editor for
caipesubagent steps. - File I/O visualization: Nodes show file read/write badges extracted from
llm_prompt; edges between nodes sharing files are highlighted green. - Environment variable panel: Shows env vars referenced in workflow with step locations.
- Unsaved changes guard: In-app styled dialog (not browser confirm) when navigating away with unsaved changes; works on Back button AND header tab navigation via Zustand global store +
GuardedLinkwrapper in AppHeader. - Import dialog: Load saved configs from MongoDB, upload YAML file, or import from raw HTTP URL.
- YAML preview dialog: Syntax-highlighted YAML preview with copy/download, line numbers.
- YAML export: Download uses YAML format (js-yaml) instead of JSON.
- Workflow templates: Template picker dialog when creating new workflow.
- Clone workflow: Clone button on existing workflow cards.
- Theme-aware nodes: Nodes use dark vibrant colors in dark mode, pastel colors in light mode via
useTheme()runtime detection. - Custom canvas controls: Replaced React Flow default Controls with custom Panel-based controls using primary theme color.
- Toolbar redesign: Two-row layout with grouped Import/Preview/Download button bar to prevent overflow.
- Scrollbar fix: Transparent track with thin rounded thumb globally.
Supervisor Integrationβ
load_task_config() in deep_agent_single.py is modified to:
- Check if
MONGODB_URIis set - If yes, query MongoDB
task_configscollection via pymongo, transform documents into the dict format expected byinvoke_self_service_task - Cache results in-memory with configurable TTL (default 60s) to avoid per-request DB queries
- If MongoDB is unavailable or returns empty, fall back to reading
task_config.yaml
Components Affectedβ
- Multi-Agents (
ai_platform_engineering/multi_agents/) βdeep_agent_single.py(modifyload_task_config()) - Utils (
ai_platform_engineering/utils/) β newmongodb_client.py - UI (
ui/) β new/task-builderpage, components, Zustand store, API routes, types - Documentation (
docs/) β ADR - Helm Charts (
charts/) β no changes needed (YAML remains for seeding)
Acceptance Criteriaβ
MongoDB & APIβ
-
task_configscollection created with proper indexes on first connection - YAML seeding populates MongoDB with all existing workflows as
is_system: true(idempotent) - GET
/api/task-configsreturns all visible task configs (system + user's own + shared) - POST
/api/task-configscreates a new task config with validation - PUT
/api/task-configs?id=<id>updates (owner or admin only) - DELETE
/api/task-configs?id=<id>deletes (owner or admin, not system configs) - GET
/api/task-configs?format=yamlexports intask_config.yamlformat - Auth middleware enforced on all endpoints
Task Builder UIβ
-
/task-builderpage renders a flow canvas with@xyflow/react - Users can add, remove, and reorder task step nodes
- Each node displays display_text, subagent badge, and connection handles
- Clicking a node opens a sidebar editor with display_text input, llm_prompt code editor, subagent selector
- Workflow metadata (name, category, description) editable in toolbar
- Save persists to MongoDB via API
- Import from YAML parses
task_config.yamlformat into nodes - Export to YAML generates valid
task_config.yamlformat - "Task Builder" link appears in app navigation
- S-curve node layout with bezier curved edges
- Step Templates palette (left sidebar) with 154 draggable tool templates, searchable and categorized
- CAIPE Form Builder for structured editing of
caipesubagent steps - File I/O visualization: file read/write badges on nodes, green-highlighted edges for shared files
- Environment variable panel showing referenced env vars with step locations
- Unsaved changes guard: in-app styled dialog on Back button and header tab navigation
- Import dialog: load from MongoDB, upload YAML, or import from HTTP URL
- YAML preview dialog with syntax highlighting, copy/download, line numbers
- YAML export (js-yaml) instead of JSON
- Workflow templates picker when creating new workflow
- Clone workflow button on workflow cards
- Theme-aware nodes (dark vibrant / light pastel via useTheme)
- Custom canvas controls using primary theme color
- Two-row toolbar with grouped Import/Preview/Download bar
- Global scrollbar: transparent track, thin rounded thumb
Supervisor Integrationβ
-
load_task_config()reads from MongoDB whenMONGODB_URIis set - Results are cached in-memory with configurable TTL
- Falls back to YAML when MongoDB is unavailable
-
invoke_self_service_taskworks with MongoDB-sourced configs identically to YAML-sourced ones - Environment variable substitution (
${VAR_NAME}) still works
Documentationβ
- Spec created (this document)
- ADR created with decision rationale
Implementation Planβ
Phase 1: Types, MongoDB, and APIβ
- Create
ui/src/types/task-config.tswith TaskConfig, TaskStep interfaces - Add
task_configscollection indexes inui/src/lib/mongodb.ts - Create
ui/src/app/api/task-configs/route.ts(CRUD) - Create
ui/src/app/api/task-configs/seed/route.ts(YAML seeding) - Create
ui/src/store/task-config-store.ts(Zustand store)
Phase 2: Visual Task Builder UIβ
- Create
ui/src/app/(app)/task-builder/page.tsx(main page) - Create
ui/src/components/task-builder/TaskBuilderCanvas.tsx(React Flow canvas) - Create
ui/src/components/task-builder/TaskStepNode.tsx(custom node) - Create
ui/src/components/task-builder/TaskBuilderSidebar.tsx(property editor) - Create
ui/src/components/task-builder/TaskBuilderToolbar.tsx(top bar) - Create
ui/src/components/task-builder/SubagentSelector.tsx(dropdown) - Add "Task Builder" to navigation in
AppHeader.tsx
Phase 2.5: UX Enhancementsβ
- Implement S-curve node layout with bezier edges
- Create
StepPalette.tsxwith 154 draggable tool templates, search, categories - Create
step-templates.tsdata for all integrated agents - Create
CaipeFormBuilder.tsxfor structuredcaipesubagent step editing - Add file I/O badges to nodes, green-highlight edges for shared files
- Create
EnvVarsPanel.tsxfor env var references with step locations - Create
unsaved-changes-store.tsandGuardedLinkwrapper - Create
UnsavedChangesDialog.tsx(in-app styled, not browser confirm) - Create
ImportDialog.tsx(MongoDB, YAML upload, HTTP URL) - Create
YamlPreviewDialog.tsxwith syntax highlighting, copy/download - Switch export to YAML (js-yaml) instead of JSON
- Create
WorkflowTemplateDialog.tsxfor template picker - Add clone workflow button on workflow cards
- Theme-aware node colors via
useTheme() - Custom canvas controls (Panel-based, primary theme color)
- Two-row toolbar redesign with grouped Import/Preview/Download
- Global scrollbar styling (transparent track, thin rounded thumb)
Phase 3: Supervisor MongoDB Integrationβ
- Create
ai_platform_engineering/utils/mongodb_client.py(shared pymongo singleton) - Modify
load_task_config()indeep_agent_single.pyfor MongoDB-first with YAML fallback - Add in-memory TTL cache for task config reads
Phase 4: Documentationβ
- Create ADR at 2026-03-03-task-builder-mongodb
Testing Strategyβ
- Unit tests: API route handlers (CRUD validation, auth, seeding), Zustand store actions, pymongo client, modified
load_task_config()with MongoDB/YAML fallback - Integration tests: End-to-end flow from UI save β MongoDB β supervisor read
- Manual verification: Create a workflow in the Task Builder UI, verify it appears in the supervisor's available tasks, execute it via chat
- UX verification: Step palette drag-and-drop, CAIPE Form Builder, file I/O visualization, env vars panel, unsaved changes guard (Back + tab nav), import (MongoDB/YAML/URL), YAML preview/export, workflow templates, clone, theme-aware nodes, custom controls, toolbar layout, scrollbar styling
Rollout Planβ
- Deploy with YAML seeding on first boot β existing workflows available immediately
- Users can create new workflows via the Task Builder UI
- System workflows (
is_system: true) are protected from deletion - Future: version history, workflow templates gallery, dry-run preview
Relatedβ
- ADR: 2026-03-03-task-builder-mongodb
- Existing task_config.yaml:
charts/ai-platform-engineering/data/task_config.yaml - Existing Agent Builder:
ui/src/components/agent-builder/ - Supervisor entry point:
ai_platform_engineering/multi_agents/platform_engineer/deep_agent_single.py