Première version agent
Dérivé TP3
This commit is contained in:
32
AgentReact/agent.py
Normal file
32
AgentReact/agent.py
Normal file
@@ -0,0 +1,32 @@
|
||||
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")
|
||||
Reference in New Issue
Block a user