mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
|
|
from langgraph.graph import StateGraph, END
|
||
|
|
from .state import AlisonState
|
||
|
|
from .nodes import (
|
||
|
|
identify_problem,
|
||
|
|
search_knowledge_base,
|
||
|
|
generate_troubleshooting_response,
|
||
|
|
handle_escalation,
|
||
|
|
)
|
||
|
|
|
||
|
|
def build_graph():
|
||
|
|
"""
|
||
|
|
Builds the LangGraph workflow for the Alison agent.
|
||
|
|
"""
|
||
|
|
workflow = StateGraph(AlisonState)
|
||
|
|
|
||
|
|
workflow.add_node("identify_problem", identify_problem)
|
||
|
|
workflow.add_node("search_knowledge_base", search_knowledge_base)
|
||
|
|
workflow.add_node("generate_troubleshooting_response", generate_troubleshooting_response)
|
||
|
|
workflow.add_node("handle_escalation", handle_escalation)
|
||
|
|
|
||
|
|
workflow.set_entry_point("identify_problem")
|
||
|
|
|
||
|
|
workflow.add_edge("identify_problem", "search_knowledge_base")
|
||
|
|
workflow.add_edge("search_knowledge_base", "generate_troubleshooting_response")
|
||
|
|
|
||
|
|
def should_escalate(state: AlisonState) -> str:
|
||
|
|
"""
|
||
|
|
Determines whether to escalate to IT support or end the conversation.
|
||
|
|
"""
|
||
|
|
if state.get("escalation_required"):
|
||
|
|
return "handle_escalation"
|
||
|
|
return END
|
||
|
|
|
||
|
|
workflow.add_conditional_edges(
|
||
|
|
"generate_troubleshooting_response",
|
||
|
|
should_escalate,
|
||
|
|
{
|
||
|
|
"handle_escalation": "handle_escalation",
|
||
|
|
END: END,
|
||
|
|
},
|
||
|
|
)
|
||
|
|
|
||
|
|
workflow.add_edge("handle_escalation", END)
|
||
|
|
|
||
|
|
graph = workflow.compile()
|
||
|
|
graph.name = "Alison IT Support Assistant"
|
||
|
|
return graph
|
||
|
|
|
||
|
|
graph = build_graph()
|