Include YouTube links from metadata in RAG agent responses

Describe the problem/error/question

I’m using an AI Agent in n8n that retrieves answers from a Qdrant vector store.
Each chunk contains metadata, including a youtube link.
But in the final response from the agent, this link never appears, even though I’m sure the metadata is stored correctly and returned by the Qdrant search.
I want the agent to include the YouTube link from metadata in its final answer, either inline or appended below.

What is the error message (if any)?

There is no error. The response works, but the metadata is ignored in the output.

Share the output returned by the last node

json

CopierModifier

{
  "choices": [
    {
      "message": {
        "content": "The answer is XYZ."
      }
    }
  ],
  "documents": [
    {
      "metadata": {
        "youtube": "https://www.youtube.com/watch?v=xxxxx",
        "title": "Example Title"
      }
    }
  ]
}

Information on your n8n setup

  • n8n version: 1.89.2
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • **Running n8n via Docker VPS
  • Operating system: Ubuntu 22.04

Hi i guess you can describe it on system prompt to output as json format and make a clear structure example like this:

{
"answer": "Your answer",
"link": "Always put metadata filed \"youtube\" here"
}

Please share your workflow in a code block.

Ive used a similar solution once where I explicitly mapped out the citations I had stored which is effectively the metadata using a structured output sub-node output parser. This however worked as I used the Q & A AI node

In the last node I map out the “staffId” I had stored in the metadata

Thank you for your reply. Here is my workflow :blush:

I didn’t quite understand what you meant, sorry :sweat_smile: Here’s my workflow.
It’s funny to find yourself in the novice’s shoes when you yourself are a teacher in another field.

I think the better solution for your specific use case here is to maybe create a new wrokflow which will act as a sub-agent which specifically specializes in doing the RAG part. Then this main agent just calls the workflow as a tool. This way your sub-agent can always return content and metadata in a structure manner for your main agent to consume. Unfortunately I dont understand your language in your promtps so I cant quite figure out what your main agent does.

So your sub-agent will look something like this: