Skip to content

Commit d32995d

Browse files
committed
feat: add option to include conversation history in N8N requests
1 parent 57631e8 commit d32995d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

pipelines/n8n/n8n.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
project_url: https://github.com/owndev/Open-WebUI-Functions
66
funding_url: https://github.com/sponsors/owndev
77
n8n_template: https://github.com/owndev/Open-WebUI-Functions/blob/main/pipelines/n8n/Open_WebUI_Test_Agent_Streaming.json
8-
version: 2.1.1
8+
version: 2.1.2
99
license: Apache License 2.0
1010
description: An optimized streaming-enabled pipeline for interacting with N8N workflows, consistent response handling for both streaming and non-streaming modes, robust error handling, and simplified status management. Supports Server-Sent Events (SSE) streaming and various N8N workflow formats.
1111
features:
@@ -286,6 +286,10 @@ class Valves(BaseModel):
286286
default="output",
287287
description="Field name for the response message in the N8N payload",
288288
)
289+
SEND_CONVERSATION_HISTORY: bool = Field(
290+
default=False,
291+
description="Whether to include conversation history when sending requests to N8N",
292+
)
289293
CF_ACCESS_CLIENT_ID: EncryptedStr = Field(
290294
default="",
291295
description="Only if behind Cloudflare: https://developers.cloudflare.com/cloudflare-one/identity/service-tokens/",
@@ -544,18 +548,24 @@ async def pipe(
544548
if messages and messages[0].get("role") == "system":
545549
system_prompt = self.dedupe_system_prompt(messages[0]["content"])
546550

547-
# Include full conversation history like in stream-example.py
551+
# Optionally include full conversation history (controlled by valve)
548552
conversation_history = []
549-
for msg in messages:
550-
if msg.get("role") in ["user", "assistant"]:
551-
conversation_history.append(
552-
{"role": msg["role"], "content": msg["content"]}
553-
)
553+
if self.valves.SEND_CONVERSATION_HISTORY:
554+
for msg in messages:
555+
if msg.get("role") in ["user", "assistant"]:
556+
conversation_history.append(
557+
{"role": msg["role"], "content": msg["content"]}
558+
)
554559

555560
# Prepare payload for N8N workflow (improved version)
556561
payload = {
557562
"systemPrompt": system_prompt,
558-
"messages": conversation_history, # Full conversation context
563+
# Include messages only when enabled in valves for privacy/control
564+
"messages": (
565+
conversation_history
566+
if self.valves.SEND_CONVERSATION_HISTORY
567+
else []
568+
),
559569
"currentMessage": question, # Current user message
560570
"user_id": __user__.get("id") if __user__ else None,
561571
"user_email": __user__.get("email") if __user__ else None,

0 commit comments

Comments
 (0)