Hi everyone.
AI chat persistence seems to be a common issue here. People talk a lot about storing messages, files and attachments, and about running compaction on long histories. The compaction thread alone has over 1,700 views!
To help remedy some of these issues, we've made an AI SDK integration for our API, Twigg, which handles this layer. Basically it runs the model routing + chat persistence + compaction + prompt caching all in one integration. It gives you persistent chats and agents without any database setup and works the same whether you're running locally, or in prod.
To show the differences, we've ported Vercel's chat persistence example: https://github.com/Twigg-AI-Ltd/twigg-ai-sdk/tree/main/examples/no-database
Changes from the original:
- No database or storage code.
chat-store.tsis gone, and so areresumable-stream,throttleitand@vercel/blob. The only setting it needs isTWIGG_API_KEY. - About 30 lines for the chat route, down from 95, using
readChatRequest,toUIMessageStreamResponseandloadUIMessages. - Chats survive refreshes, redeploys and restarts, with no database.
- Long chats stay within the model's context window, with automatic compaction.
- You can switch models while keeping the same history.
There's a Deploy button in the README if you want to try it. It's deliberately minimal, like the original, but hopefully it helps solve some of the the long-standing persistence and compaction issues!
You can get more info at twigg.ai
Love to hear what you think, and if it's solved a problem for you.