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.
Download this n8n workflow template and start using it instantly.
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.
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).
n8nchathistories table includes a createdat timestamp column necessary for logging.select distinct(sessionid)) to fetch every unique conversation ID currently logged.Loop Over Session IDs n8n node iterates through each unique session ID.Get conversations by sessionId, retrieves all individual messages associated with the current session ID.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.n8nchathistories). Supabase users should use the connection pooler parameters for optimal stability.documentId parameter in the Google Sheets n8n nodes with your specific spreadsheet ID.created_at column exists by running the initial PostgreSQL query manually. 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 sessionid. 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.
Automate technology stack research by integrating the BuiltWith API with Google Sheets using this powerful n8n workflow. Extract domain tech and update your CRM data automatically.

Explore the complete range of capabilities in this reference n8n workflow. This n8n template visualizes essential n8n node types: triggers, AI agents, data flow, and core logic components.

Use this comprehensive n8n workflow to automate expense logging. Send transactions via Telegram (text or voice), transcribe audio with OpenAI, and instantly append structured data to Google Sheets.

Use this powerful n8n workflow to bulk scrape thousands of Amazon product reviews via RapidAPI and automatically store the structured data in Google Sheets for analysis.

Automate bulk data export from Cloudflare to Google Sheets using this powerful n8n workflow. Capture domain settings, DNS records, and TLD metadata efficiently.

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/







































