Sécurité prompt injection

This commit is contained in:
2026-02-12 10:39:21 +01:00
parent 2da71f8c51
commit 7fa447ff35
4 changed files with 29 additions and 11 deletions

View File

@@ -1,11 +1,12 @@
from typing import Dict
from langgraph.graph.state import CompiledStateGraph
from langgraph.types import Command
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):
def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0, showSysMessages=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,
@@ -17,7 +18,7 @@ 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
msg.pretty_print()
if showSysMessages or not msg.type == "system": msg.pretty_print()
i+=1
lastMsgIndex+=i
@@ -28,7 +29,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) # 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) # 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: