diff --git a/AgentReact/start.py b/AgentReact/start.py index 92932ce..a02e13e 100644 --- a/AgentReact/start.py +++ b/AgentReact/start.py @@ -22,4 +22,4 @@ initial_input = { config={"configurable": {"thread_id": 'yes'}} # Et je lance ! -streamGraph(initial_input, config, getGraph(), showSysMessages=False) \ No newline at end of file +streamGraph(initial_input, config, getGraph(), showSysMessages=True, showToolMessages=True) \ No newline at end of file diff --git a/AgentReact/utils/StreamGraph.py b/AgentReact/utils/StreamGraph.py index 86ba0bc..af155f7 100644 --- a/AgentReact/utils/StreamGraph.py +++ b/AgentReact/utils/StreamGraph.py @@ -6,7 +6,7 @@ from langchain.messages import SystemMessage from .InterruptPayload import InterruptPayload # Une fonction pour stream et gérer proprement le graphe -def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0, showSysMessages=True): +def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0, showSysMessages=True, showToolMessages=True): # https://docs.langchain.com/oss/python/langgraph/interrupts#stream-with-human-in-the-loop-hitl-interrupts for mode, state in graphe.stream( initial_input, @@ -18,7 +18,9 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, last # Handle streaming message content i=0 for msg in state['messages'][lastMsgIndex:]: # Permet de gérer plusieurs nouveaux messages d'un coup - if showSysMessages or not msg.type == "system": msg.pretty_print() + if msg.type == "system" and showSysMessages: msg.pretty_print() + elif msg.type == "tool" and showToolMessages: msg.pretty_print() + elif msg.type != "tool" and msg.type != "system": msg.pretty_print() # User et IA i+=1 lastMsgIndex+=i @@ -29,7 +31,7 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, last payload = InterruptPayload.fromJSON(payload) # Chargement de la requête depuis sa version JSON payload.humanDisplay() # L'utilisateur peut accepter/modifier/refuser ici - streamGraph(Command(resume=payload.toJSON()), config, graphe, lastMsgIndex, showSysMessages) # Je renvois la chaîne JSON, qui sera reconvertie en objet dans l'outil, et je relance le stream récursivement + streamGraph(Command(resume=payload.toJSON()), config, graphe, lastMsgIndex, showSysMessages, showToolMessages) # Je renvois la chaîne JSON, qui sera reconvertie en objet dans l'outil, et je relance le stream récursivement return # Fin de cette fonction récursive else: