Spaces:
Runtime error
Runtime error
File size: 2,049 Bytes
2cfaa45 | 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 | """
LangGraph workflow setup for the customer support system.
"""
from langgraph.graph import StateGraph, END
from typing import Dict
from .models import State
from .handlers import (
categorize, analyze_sentiment, handle_technical,
handle_billing, handle_general, escalate, route_query
)
def create_workflow() -> StateGraph:
"""Create and configure the LangGraph workflow"""
# Create the graph
workflow = StateGraph(State)
# Add nodes
workflow.add_node("categorize", categorize)
workflow.add_node("analyze_sentiment", analyze_sentiment)
workflow.add_node("handle_technical", handle_technical)
workflow.add_node("handle_billing", handle_billing)
workflow.add_node("handle_general", handle_general)
workflow.add_node("escalate", escalate)
# Add edges
workflow.add_edge("categorize", "analyze_sentiment")
workflow.add_conditional_edges(
"analyze_sentiment",
route_query,
{
"handle_technical": "handle_technical",
"handle_billing": "handle_billing",
"handle_general": "handle_general",
"escalate": "escalate"
}
)
workflow.add_edge("handle_technical", END)
workflow.add_edge("handle_billing", END)
workflow.add_edge("handle_general", END)
workflow.add_edge("escalate", END)
# Set entry point
workflow.set_entry_point("categorize")
return workflow.compile()
def run_customer_support(query: str) -> Dict[str, str]:
"""Process a customer query through the LangGraph workflow.
Args:
query (str): The customer's query
Returns:
Dict[str, str]: A dictionary containing the query's category, sentiment, and response
"""
# Create a fresh instance of the workflow
app = create_workflow()
# Invoke the workflow with the query
results = app.invoke({"query": query})
return {
"query": query,
"category": results["category"],
"sentiment": results["sentiment"],
"response": results["response"]
}
|