Spaces:
Sleeping
Sleeping
Delete workflow.py
Browse files- workflow.py +0 -75
workflow.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
LangGraph Workflow Orchestration
|
| 3 |
-
Updated for dictionary-based state and persistence.
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
from typing import Dict, Any, List
|
| 7 |
-
from langgraph.graph import StateGraph, END
|
| 8 |
-
from langgraph.checkpoint.memory import MemorySaver
|
| 9 |
-
from state_schema import WorkflowState, create_initial_state
|
| 10 |
-
from agents import (
|
| 11 |
-
agent_0_node,
|
| 12 |
-
agent_1_node,
|
| 13 |
-
agent_2_node,
|
| 14 |
-
agent_3_integrated_node
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
def create_workflow():
|
| 18 |
-
"""Create the LangGraph workflow."""
|
| 19 |
-
workflow = StateGraph(WorkflowState)
|
| 20 |
-
|
| 21 |
-
# Add Nodes
|
| 22 |
-
workflow.add_node("setup", agent_0_node)
|
| 23 |
-
workflow.add_node("capture_design", agent_1_node)
|
| 24 |
-
workflow.add_node("capture_website", agent_2_node)
|
| 25 |
-
workflow.add_node("analysis", agent_3_integrated_node)
|
| 26 |
-
|
| 27 |
-
# Define Edges
|
| 28 |
-
workflow.set_entry_point("setup")
|
| 29 |
-
workflow.add_edge("setup", "capture_design")
|
| 30 |
-
workflow.add_edge("capture_design", "capture_website")
|
| 31 |
-
|
| 32 |
-
# Human-in-the-loop breakpoint before analysis
|
| 33 |
-
workflow.add_edge("capture_website", "analysis")
|
| 34 |
-
workflow.add_edge("analysis", END)
|
| 35 |
-
|
| 36 |
-
# Add persistence
|
| 37 |
-
checkpointer = MemorySaver()
|
| 38 |
-
|
| 39 |
-
return workflow.compile(
|
| 40 |
-
checkpointer=checkpointer,
|
| 41 |
-
interrupt_before=["analysis"]
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
def run_workflow_step_1(figma_id, figma_key, url, execution_id, thread_id, hf_token=""):
|
| 45 |
-
"""Run the first part of the workflow until the breakpoint."""
|
| 46 |
-
app = create_workflow()
|
| 47 |
-
config = {"configurable": {"thread_id": thread_id}}
|
| 48 |
-
|
| 49 |
-
initial_state = create_initial_state(
|
| 50 |
-
figma_file_key=figma_id,
|
| 51 |
-
figma_access_token=figma_key,
|
| 52 |
-
website_url=url,
|
| 53 |
-
hf_token=hf_token,
|
| 54 |
-
execution_id=execution_id
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
# Run until interrupt
|
| 58 |
-
for event in app.stream(initial_state, config, stream_mode="values"):
|
| 59 |
-
state = event
|
| 60 |
-
|
| 61 |
-
return app.get_state(config)
|
| 62 |
-
|
| 63 |
-
def resume_workflow(thread_id, user_approval=True):
|
| 64 |
-
"""Resume the workflow after human approval."""
|
| 65 |
-
app = create_workflow()
|
| 66 |
-
config = {"configurable": {"thread_id": thread_id}}
|
| 67 |
-
|
| 68 |
-
# Update state with approval
|
| 69 |
-
app.update_state(config, {"user_approval": user_approval})
|
| 70 |
-
|
| 71 |
-
# Resume execution
|
| 72 |
-
for event in app.stream(None, config, stream_mode="values"):
|
| 73 |
-
state = event
|
| 74 |
-
|
| 75 |
-
return app.get_state(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|