32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from langgraph.graph import START, END
|
|
from langgraph.graph.state import CompiledStateGraph
|
|
|
|
from utils.nodes import reponse_question, tool_node, should_continue
|
|
from utils.state import getState
|
|
|
|
def getGraph()->CompiledStateGraph:
|
|
"""
|
|
Récupérer le graphe compilé et prêt à invoquer
|
|
|
|
Returns:
|
|
CompiledStateGraph: Graphe compilé
|
|
"""
|
|
workflow = getState() # State prêt à utiliser
|
|
|
|
# Définition des sommets du graphe
|
|
workflow.add_node(reponse_question)
|
|
workflow.add_node("tool_node", tool_node) # N'est pas une fonction, mais une classe instanciée, je dois précisier le nom du node
|
|
|
|
# Arrêtes
|
|
workflow.set_entry_point("reponse_question")
|
|
workflow.add_edge("tool_node", "reponse_question")
|
|
workflow.add_conditional_edges("reponse_question", should_continue, {
|
|
"tools":"tool_node",
|
|
END:END
|
|
})
|
|
|
|
return workflow.compile()
|
|
|
|
if __name__ == "__main__":
|
|
# Affichage du graphe
|
|
getGraph().get_graph().draw_mermaid_png(output_file_path="agent.png") |