Export AI Agent Conversation Logs to Spreadsheets - n8n Workflow

Use this powerful n8n workflow to automatically export AI agent chat memory logs from Postgres (or Supabase) to Google Sheets, creating one dynamic sheet per session ID for easy analysis.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Product teams building and monitoring AI agents or conversational assistants.

  • Developers needing an accessible way to analyze AI agent memory and chat transcripts.

  • Data analysts who require conversation logs centralized in Google Sheets for reporting.

  • Users running custom n8n workflow agents and storing memory in Postgres/Supabase.

Overview

This n8n workflow provides a robust solution for auditing and analyzing conversations processed by your AI agents. By retrieving structured chat memory stored in a Postgres database (often used for n8n AI agent memory persistence, including Supabase users), the n8n template centralizes this data. It handles large datasets efficiently by iterating through unique session IDs and creating a dedicated, clean Google Sheet tab for each conversation transcript. This allows teams to easily review conversation flows, monitor performance, and ensure logs are always up-to-date by clearing and rebuilding the sheets during each execution of the n8n trigger.

How it Works

This automation can be started using a manual n8n trigger for testing or a recurring schedule n8n trigger (set daily at noon in this n8n workflow).


  1. Initial Setup (Optional): An initial PostgreSQL n8n node allows developers to execute a query to ensure the n8nchathistories table includes a createdat timestamp column necessary for logging.

  2. Retrieve Session IDs: The workflow uses a PostgreSQL n8n node to execute an SQL query (select distinct(sessionid)) to fetch every unique conversation ID currently logged.

  3. Loop and Prepare Sheets: The Loop Over Session IDs n8n node iterates through each unique session ID.

  4. Google Sheets Preparation: For the current session ID, the n8n workflow attempts to clear any existing sheet content using the Google Sheets n8n node. It then uses HTTP Request n8n nodes calling the Google Sheets API to duplicate a predefined template sheet and rename the newly created sheet using the current session ID.

  5. Fetch Conversation Data: A subsequent PostgreSQL n8n node, Get conversations by sessionId, retrieves all individual messages associated with the current session ID.

  6. Write Data: Finally, the Add conversations Google Sheets n8n node appends all retrieved messages to the corresponding, newly prepared Google Sheet tab. It maps the message type (Who), content (Message), and formatted timestamp (Date) to the spreadsheet columns.

Installation Guide


  1. Import the n8n Workflow: Copy the provided JSON data and paste it directly into your n8n instance via the 'Workflows' section and the 'New' button (or drag and drop).

  2. PostgreSQL Credentials: You must configure and connect your PostgreSQL credentials. Ensure these credentials have read access to your AI agent's chat memory table (n8nchathistories). Supabase users should use the connection pooler parameters for optimal stability.

  3. Google Sheets Credentials: Create and configure OAuth 2.0 credentials for Google Sheets. These credentials must have permission to manage (read, write, and create/rename tabs) the target spreadsheet.

  4. Prepare Google Sheet: Create a target Google Sheets document. This n8n workflow relies on the first tab (index 0) acting as a template, with headers like 'Who', 'Message', and 'Date'. Replace the documentId parameter in the Google Sheets n8n nodes with your specific spreadsheet ID.

  5. Run Setup Query (First Time): If you haven't already, ensure the created_at column exists by running the initial PostgreSQL query manually.

  6. Activate: Choose your preferred n8n trigger (Manual or Schedule) and activate the n8n workflow.

Node Details

Schedule Trigger / Manual Trigger: These n8n trigger nodes initiate the periodic or on-demand execution of the entire n8n workflow.
Postgres - Get session ids (Postgres n8n node): Executes a query (select distinct(sessionid)) to gather a list of all unique conversation IDs that need exporting.
Loop Over Session IDs (Split In Batches n8n node): Splits the incoming list of session IDs, ensuring that subsequent steps are executed sequentially for each conversation.
Clear Sheet Content (Google Sheets n8n node): Attempts to clear old data from the sheet named after the current session
id. It's configured to continue gracefully even if the sheet does not yet exist (onError: continueErrorOutput).
Duplicate template sheet (HTTP Request n8n node): Uses the Google Sheets API to copy the template sheet (index 0) into the same spreadsheet.
Rename Sheet (HTTP Request n8n node): Renames the newly created sheet tab using the current sessionid, making the conversation log easily identifiable.
Get conversations by sessionId (Postgres n8n node): Queries the database to retrieve all messages where the sessionid matches the current looped item.
Add conversations (Google Sheets n8n node): Appends the retrieved messages as new rows in the corresponding sheet, performing data transformation to map message.type, message.content, and formatted created_at fields.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

We are a product studio that helps organizations leverage no-code and generative AI to automate internal processes and launch new digital products. LinkedIn: https://www.linkedin.com/in/baptistej/

Featured*