File size: 2,078 Bytes
b6ed6f7
0aa8e87
b6ed6f7
 
 
 
 
 
f41ca4f
b6ed6f7
 
0aa8e87
b6ed6f7
 
 
 
 
 
 
f41ca4f
b6ed6f7
 
 
0aa8e87
b6ed6f7
 
 
 
f41ca4f
0aa8e87
 
 
 
 
 
 
 
b6ed6f7
 
 
 
 
 
 
 
 
 
0aa8e87
 
b6ed6f7
 
 
 
f41ca4f
 
0aa8e87
 
 
 
 
b6ed6f7
0aa8e87
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from langgraph.graph import StateGraph, END
from langchain_core.runnables import RunnableLambda
from src.agents import (
    CallState,
    IntakeAgent,
    TranscriptionAgent,
    SummarizationAgent,
    QualityScoringAgent,
    ModerationAgent,
    Router
)
from src.agents.Router import PostSummarizeRouter

def build_workflow():
    workflow = StateGraph(CallState)
    
    # Initialize agents
    intake_agent = IntakeAgent()
    transcription_agent = TranscriptionAgent()
    moderation_agent = ModerationAgent()
    summarization_agent = SummarizationAgent()
    quality_scoring_agent = QualityScoringAgent()
    router = Router()
    post_summarize_router = PostSummarizeRouter()
    
    # Add nodes
    workflow.add_node("intake", intake_agent)
    workflow.add_node("transcribe", transcription_agent)
    workflow.add_node("moderate", moderation_agent)
    summarize_node = RunnableLambda(summarization_agent).with_fallbacks(
        [RunnableLambda(SummarizationAgent.fallback)]
    )
    score_node = RunnableLambda(quality_scoring_agent).with_fallbacks(
        [RunnableLambda(QualityScoringAgent.fallback)]
    )
    workflow.add_node("summarize", summarize_node)
    workflow.add_node("score", score_node)
    
    # Define entry point
    workflow.set_entry_point("intake")
    
    # Add conditional edges from intake
    workflow.add_conditional_edges(
        "intake",
        router,
        {
            "transcribe": "transcribe",
            "summarize": "moderate",
            "end": END
        }
    )
    
    # Add standard edges
    workflow.add_edge("transcribe", "moderate")
    workflow.add_edge("moderate", "summarize")
    workflow.add_conditional_edges(
        "summarize",
        post_summarize_router,
        {"score": "score", "end": END},
    )
    workflow.add_edge("score", END)

    # Compile with a MemorySaver checkpointer when available.
    try:
        from langgraph.checkpoint.memory import MemorySaver

        return workflow.compile(checkpointer=MemorySaver())
    except Exception:
        return workflow.compile()