Skip to content

✨ Langfuse Agentic Workflow Editor + MCP 구현#1

Draft
TaehyeungKim wants to merge 23 commits intomainfrom
feat/workflow-editor-mvp
Draft

✨ Langfuse Agentic Workflow Editor + MCP 구현#1
TaehyeungKim wants to merge 23 commits intomainfrom
feat/workflow-editor-mvp

Conversation

@TaehyeungKim
Copy link
Collaborator

What does this PR do?

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • This change requires a documentation update

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project (pnpm run format)
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my PR needs changes to the documentation
  • I haven't checked if my changes generate no new warnings (npm run lint)
  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

TaehyeungKim and others added 23 commits March 7, 2026 03:45
Add Workflow table with versioning support similar to Prompt model:
- Stores workflow DAG as JSON (nodes + edges)
- Version tracking (unique constraint on projectId + name + version)
- Input schema support for workflow variables
- Tags for categorization
- Audit trail with createdAt/updatedAt/createdBy

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add RBAC scopes for workflow management:
- workflows:CUD - Create, update, delete workflows
- workflows:read - Read workflow definitions

Add "workflow" to auditable resource types for audit logging.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add multi-agent workflow editor with React Flow canvas:

Backend (tRPC):
- CRUD operations for workflow management
- Execute workflow nodes via chatCompletion endpoint
- Parameterized SQL queries (SQL injection protection)
- RBAC scope enforcement (workflows:CUD, workflows:read)
- Audit logging for all mutations

Frontend:
- React Flow canvas with custom node types (agent, input, output)
- Node configuration panel with model params, messages, retry config
- Prompt import from existing Langfuse prompts
- Save/load workflows with versioning
- Real-time execution with node state visualization
- Cycle detection for DAG validation
- Variable resolution (mustache {{variable}} syntax)
- Field mapping between nodes

UX Fixes:
- Debounced message updates (300ms) to prevent focus loss during typing
- All hooks before early return (fixes "Rendered more hooks" error)
- Disabled ReactFlow keyboard deletion (deleteKeyCode: null)
- Props sync with useEffect for dynamic node/edge updates

Execution:
- Topological sort for parallel layer execution
- Variable substitution with node output references
- Retry logic per node (configurable max retries + delay)
- UIModelParams → ModelParams conversion for server compatibility

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add Workflows page to navigation sidebar under Prompt Management section.
Uses GitBranch icon for visual consistency with workflow concept.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Increase CodeMirrorEditor height in ChatMessages:
- minHeight: 120px → 150px
- maxHeight: 400px → 500px

Improves prompt editing experience in workflow node configuration
and playground, similar to Langsmith's document-style textarea.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add React Flow library v12.10.1 for visual workflow editor:
- Provides DAG canvas with pan/zoom/minimap
- Custom node types (agent, input, output)
- Edge routing with cycle detection
- Built-in accessibility features

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Type Safety Improvements:
- Remove all `as any` castings across workflow editor
- Replace with proper types from @langfuse/shared and @xyflow/react
- Use ChatMessage, UIModelParams, NodeChange, EdgeChange types
- Fix SimplifiedNode to use ChatMessage[] instead of any[]

Code Quality:
- Extract duplicated convertUIModelParamsToModelParams to shared utility
- Add support for maxReasoningTokens and providerOptions fields
- Proper type narrowing for message handlers
- Fix all TypeScript strict type checks

React Compliance:
- All hooks properly ordered before early returns
- Proper useCallback/useMemo dependency arrays
- No Rules of Hooks violations

Verification:
- All typechecks pass
- Build succeeds without errors
- Architect approved

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Map HTTP status codes to appropriate tRPC error codes
  - 401/403 → UNAUTHORIZED with IP restriction hint
  - 429 → TOO_MANY_REQUESTS with retry guidance
  - 400 → BAD_REQUEST
  - Others → INTERNAL_SERVER_ERROR with status code
- Extract detailed error messages from tRPC responses
- Improve client-side error message display

This helps users identify issues like API key IP restrictions
instead of seeing generic 500 errors.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Parse HTTP status codes from LLM errors and map to appropriate
tRPC error codes:
- 401/403 → UNAUTHORIZED with IP restriction hint
- 429 → TOO_MANY_REQUESTS with retry guidance
- 400 → BAD_REQUEST
- Others → INTERNAL_SERVER_ERROR with status code

Added regex parsing to extract status codes from error messages
like "401 Your IP is not authorized to make this request".

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added visual configuration for passing data between workflow nodes:

Features:
- Select upstream nodes from dropdown
- Configure field paths (e.g., "output.topic" for nested data)
- Set target variable names for use in messages ({{variable}})
- Choose mapping type (full output or field extraction)
- Add/remove multiple mappings per node

UI Components:
- Integrated into Node Configuration Panel
- Shows only when upstream nodes are connected
- Visual indicators for each mapping configuration

Technical:
- Uses existing FieldMapping infrastructure
- Filters upstream nodes based on edges
- Updates node data with inputMapping array

This enables users to chain agents together by passing outputs
from one agent as variables to the next agent's messages.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixes Rules of Hooks violation where useMemo and useCallback hooks
for input mapping were called after the early return statement.

All hooks must be called unconditionally before any early returns
per React's Rules of Hooks.

Changes:
- Move upstreamNodes useMemo before early return
- Move handleAddInputMapping, handleUpdateInputMapping,
  handleRemoveInputMapping callbacks before early return
- Update dependency arrays to avoid accessing nodeData before
  early return check

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds comprehensive Input/Output node functionality to workflow editor:

## Input Node Features
- Key-Value variable definition UI in NodeConfigPanel
- Visual display of variables inside Input node (bullet list)
- Integration with workflow execution engine
- Variables stored as Array<{name, value}> in node.data

## Output Node Features
- WorkflowOutputDialog component with JSON syntax highlighting
- View Results button on Output node after execution
- Results stored in WorkflowExecutionContext
- Auto-opens dialog on completion

## Agent Node Enhancement
- Structured Output Schema UI in NodeConfigPanel
- Optional JSON Schema input for enforcing output format
- Integrated with existing execution endpoint

## Type System Improvements
- Split WorkflowNodeData into discriminated union
- InputNodeData, AgentNodeData, OutputNodeData interfaces
- Centralized WorkflowResult type
- Proper type assertions throughout

## Architecture Fixes
- Merged runtime and Input node variables in execution
- Removed dead onExecute code path
- Clear workflow results between runs
- Eliminated duplicate type definitions

All features follow existing patterns (shadcn/ui, React hooks rules).
TypeScript compilation passes with full turbo cache.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add workflow list landing page with DataTable showing all saved workflows
- Restructure routing: /workflows -> list, /workflows/[id] -> editor
- Add execution history tracking in database (lastExecutionAt, lastExecutionResults, lastExecutionStatus)
- Auto-save execution results after workflow completion
- Load and display last execution when opening workflow
- Add saveExecutionResults tRPC mutation with RBAC and audit logging
- Update WorkflowExecutionContext to support execution history
- Add WorkflowListPage component with status badges and formatting
- Migration: 20260307171547_add_workflow_execution_history

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Move import type statement for PromptImportDialog
- Remove unused Textarea import from NodeConfigPanel

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Re-add Textarea import for structured output schema field
- Add execution history fields to getAll query (last_execution_at, last_execution_results, last_execution_status)
- Update SQL SELECT and TypeScript types to include execution metadata
- Fix WorkflowListPage to display execution history data

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…n history fields

- Replace raw SQL with Prisma findMany to avoid column not found errors
- Execution history fields gracefully handle missing columns before migration
- Maintains DISTINCT ON name behavior with Map-based deduplication

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove 'load' and 'router' from useEffect dependency array
- These dependencies were causing infinite re-renders
- Load function uses utils which creates new reference on each render
- Now only triggers when workflowId, isNewWorkflow, or projectId changes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Register workflow feature module with 11 MCP tools (CRUD, node management,
connections) and remove unsupported enableDnsRebindingProtection option.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix MCP transport: convert Next.js IncomingMessage to Web Standard Request
  for WebStandardStreamableHTTPServerTransport compatibility
- Add importPromptToNode workflow tool for importing Langfuse prompts into nodes
- Enhance addNode/connectNodes tools with improved error handling and validation
- Add workflow tool exports and helper utilities

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… evaluation, and model params fix

- Add RouterNode component for visual conditional routing in workflow canvas
- Add conditionEvaluator utility for evaluating edge conditions at runtime
- Enhance graphValidation with cycle detection and edge validation
- Fix NodeConfigPanel: normalize flat modelParams (from DB) to UIModelParams format
  so saved provider/model values display correctly in the UI
- Add conditional/loop edge support with custom edge rendering
- Expand workflow execution to support full LangGraph-style node execution
- Add router, output node types and extended workflow definition schema
- Add workflow execution context with result tracking

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…arch

Implement extensible tool node system for workflow editor:
- Generic tool registry with self-registration pattern
- Neo4j vector search tool (ported from Python standard_service.py)
- Execution mode selector (LLM/Tool/Passthrough) in node config UI
- tRPC endpoints for tool execution and listing
- Hybrid scoring: 80% vector similarity + 20% word overlap

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… execution engine

- Add Run tab with chat UI and execution tree in right side panel
- Implement multi-turn conversation state persistence (workflowContext across turns)
- Fix router condition evaluation: strip output. prefix, handle markdown JSON
- Fix template resolution: unresolved {{vars}} default to empty string
- Fix zod v4 validation: use z.record(z.string(), z.unknown()) syntax
- Add neo4j-driver to serverExternalPackages for native module bundling
- Refactor NodeConfigPanel to embed within tabbed panel layout

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ector-search

Replace direct Neo4j driver dependency with a generic HTTP API call tool
that delegates business logic to the Python service. This eliminates
native module bundling issues and establishes a single source of truth
for vector search logic.

- Add http-api-call tool with env var security gating (WORKFLOW_TOOL_ prefix)
- Add template substitution (${fieldName}) for request body construction
- Register http-api-call in tool bootstrap
- Deprecate neo4j-vector-search tool (kept for backward compatibility)
- Update NodeConfigPanel placeholder/help text for new tool
- Add tool-related fields to SimplifiedNode type in persistence hook
- Document WORKFLOW_TOOL_SEARCH_API_URL/KEY env vars in .env.dev.example

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant