home / skills / andrelandgraf / fullstackrecipes / ai-chat-persistence
This skill helps persist AI chat conversations in Neon Postgres, including AI SDK message parts, tools, reasoning, and streaming for reliable history.
npx playbooks add skill andrelandgraf/fullstackrecipes --skill ai-chat-persistenceReview the files below or copy the command above to add this skill to your agents.
---
name: ai-chat-persistence
description: Persist AI chat conversations to Neon Postgres with full support for AI SDK message parts including tools, reasoning, and streaming. Uses UUID v7 for chronologically-sortable IDs.
---
# AI Chat Persistence with Neon
To set up AI Chat Persistence with Neon, refer to the fullstackrecipes MCP server resource:
**Resource URI:** `recipe://fullstackrecipes.com/ai-chat-persistence`
If the MCP server is not configured, fetch the recipe directly:
```bash
curl -H "Accept: text/plain" https://fullstackrecipes.com/api/recipes/ai-chat-persistence
```
This skill persists AI chat conversations to Neon Postgres with full support for AI SDK message parts, including tool calls, chain-of-thought reasoning, and streaming fragments. It uses UUID v7 for chronologically-sortable IDs and is implemented in TypeScript as a production-ready pattern and recipe collection. The implementation fits modern full-stack web AI apps and pairs well with Shadcn UI conventions.
The skill captures incoming and outgoing AI messages, decomposes them into SDK-supported parts (content, tool calls, reasoning metadata, and stream deltas), and writes structured records to Neon Postgres. Each message and message part is assigned a UUID v7 to preserve chronological order and enable efficient range queries. Streaming segments are appended incrementally so you can reconstruct partial outputs in real time.
Why use UUID v7?
UUID v7 embeds sortable timestamps so records can be ordered chronologically without relying solely on database timestamps, improving distributed write patterns and range queries.
Does it support streaming responses?
Yes. Streaming fragments are stored incrementally so you can reconstruct partial outputs and mark completion when the final segment arrives.