Sending Chat History to a Workflow via Tool

Describe the problem/error/question

I’ve adapted an AI workflow template, that passes a user’s query to a workflow tool when the answer isn’t known. That tool then responds asking the user to repeat their question and include their Email address so that a human can get in touch. This is working, but I’d like to avoid the user having to repeat the question by passing the full conversation history to the tool once the Email address has been supplied (this is to raise a support ticket.) However I can’t work out how to pass the chat history to the Tool; can anyone provide pointers?

What is the error message (if any)?

No error, I just need to refine the workflow

Please share your workflow

Share the output returned by the last node

{
  "action": "saveContext",
  "input": {
    "input": "Respond to this query as though you don't know the answer. What's the square root of an orange? [email protected]",
    "system_message": "You are a helpful and friendly assistant for students and staff at the Open College of the Arts. When asked questions you should refer to the provided Vector Store Tool context. When you can't answer from the context, or you're not confident of the answer, use the dont_know_tool. When you use the dont_know_tool, always respond with the message from the tool.",
    "formatting_instructions": "IMPORTANT: Always call `format_final_response` to format your final response!"
  },
  "output": {
    "input": "Respond to this query as though you don't know the answer. What's the square root of an orange? [email protected]",
    "system_message": "You are a helpful and friendly assistant for students and staff at the Open College of the Arts. When asked questions you should refer to the provided Vector Store Tool context. When you can't answer from the context, or you're not confident of the answer, use the dont_know_tool. When you use the dont_know_tool, always respond with the message from the tool.",
    "formatting_instructions": "IMPORTANT: Always call `format_final_response` to format your final response!",
    "chat_history": [
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "Respond to this query as though you don't know the answer",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],
        "kwargs": {
          "content": "I'm sorry, I don't know the answer. Please repeat your question and include your email address so I can request help.",
          "tool_calls": [],
          "invalid_tool_calls": [],
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "Respond to this query as though you don't know the answer. What's the square root of an apple?",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],
        "kwargs": {
          "content": "I'm sorry, I don't know the answer. Please repeat your question and include your email address so I can request help.",
          "tool_calls": [],
          "invalid_tool_calls": [],
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "[email protected]",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],
        "kwargs": {
          "content": "Thank you for getting in touch. I've raised a ticket for a human to help.",
          "tool_calls": [],
          "invalid_tool_calls": [],
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "Respond to this query as though you don't know the answer. What's the square root of an orange?",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],
        "kwargs": {
          "content": "I'm sorry, I don't know the answer. Please repeat your question and include your email address so I can request help.",
          "tool_calls": [],
          "invalid_tool_calls": [],
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "HumanMessage"
        ],
        "kwargs": {
          "content": "Respond to this query as though you don't know the answer. What's the square root of an orange? [email protected]",
          "additional_kwargs": {},
          "response_metadata": {}
        }
      },
      {
        "lc": 1,
        "type": "constructor",
        "id": [
          "langchain_core",
          "messages",
          "AIMessage"
        ],
        "kwargs": {
          "content": "Thank you for getting in touch. I've raised a ticket for a human to help.",
          "tool_calls": [],
          "invalid_tool_calls": [],
          "additional_kwargs": {},
          "response_metadata": {}
        }
      }
    ],
    "output": "Thank you for getting in touch. I've raised a ticket for a human to help."
  }
}

Information on your n8n setup

  • n8n version: 1.62.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu 22.04.4

Hi @Paul_Vincent

Thanks for posting here and welcome to the community! :cake:

It can be a tricky and unreliable to rely on the LLM to pass on the full chat history to the sub-workflow tool (and also prone to hallucinations).

But this could be a great use-case for the Memory Manager Node. You’d connect the same memory type, provide the same session key and just get the memory inside the tool. The customer email can be sent by the Agent as a parameter to the tool.

Here’s a basic demo:

4 Likes

Many thanks for the help with this @ria - I’m quite new to n8n and still getting to grips with what the various nodes do. So the buffer memory persists across workflows - I’d assumed it would somehow need connecting up; I’ll give that a try on Monday. Thanks again!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.