{"slug": "introducing-ai-transport-v0-4-0", "title": "Introducing AI Transport v0.4.0", "summary": "Ably released AI Transport v0.4.0, adding optional database hydration support for storing and reconciling AI conversation history. The feature allows developers to persist completed runs to an external database and rebuild agent context and client UI from stored history combined with live session data.", "body_md": "AI Transport [v0.4.0](https://github.com/ably/ably-ai-transport-js/releases/tag/0.4.0) includes changes to optionally support [database hydration](https://ably.com/docs/ai-transport/features/database-hydration).\n\nSome applications may wish to store AI conversation history in an external store, such as a database. AI Transport's support for database hydration allows applications to reconcile that stored history with the live activity in the AI session.\n\nWhen using database hydration, your application persists messages for *completed* runs to the database. This allows developers to build additional functionality, such as search or analytics, on top of the persisted state.\n\nThe AI Transport session provides realtime visibility over live activity, including support for multi-device continuity, resumable streaming and bidirectional control between clients and agents.\n\n## How database hydration works\n\nHydration is symmetric: the agent rebuilds the model context and the client rebuilds the UI, both from the same two sources. The flow has two parts:\n\n**Persist completed runs.** As each run completes, your agent writes its messages to your database. Once a run completes, its messages are immutable, so it is the natural atomic unit to store.**Hydrate the conversation state.** On load, both agents and client reads the conversation history from your database, then call`loadUntil`\n\nto fetch only the messages newer than the latest one that was stored.\n\n## Persist the completed run\n\nPersist a run once it completes, because a completed run is immutable: while it is in flight messages can be mutated as tokens are appended and tool calls are resolved. `run.messages`\n\nreturns the run's whole contribution, its triggering input plus all of its streamed output across any suspend and resume, so a turn that pauses for a client-side tool result and resumes under the same run still persists as one unit.\n\n``` js\nconst runMessages = run.messages;\nawait run.end(outcome);\nif (outcome.reason === 'complete') await appendMessagesInDB(invocation.sessionName, runMessages);\n```\n\n## Hydrate the agent\n\nThe agent seeds the prior conversation from your store, takes the newest stored id as the seam, and lets `run.view.loadUntil`\n\npage back to it and return the not-yet-stored tail:\n\n``` js\nconst session = createAgentSession({ client: ably, channelName: invocation.sessionName });\nawait session.connect();\nconst run = session.createRun(invocation, { signal: req.signal });\n\nconst seed = loadMessages(invocation.sessionName);\nconst seamId = seed.at(-1)?.id;\n\n// loadUntil pages run.view back to the seam and returns only the messages newer than it.\nconst tail = await run.view.loadUntil((m) => m.message.id === seamId);\nawait run.start();\n\nconst conversation = [...seed, ...tail.map((m) => m.message)];\n// ...stream the model response with `conversation` as the message history...\n```\n\n## Hydrate the client\n\nThe client reconciles the same way, over its own session view.\n\n``` js\nconst seed = loadStoredMessages(conversationId);\nconst seamId = seed.at(-1)?.id;\n\nconst tail = await session.view.loadUntil((m) => m.message.id === seamId);\nconst conversation = [...seed, ...tail.map((m) => m.message)];\n```\n\nIn React, `useMessagesWithSeed`\n\nwraps that walk. Give it your session view and the stored seed, and it returns the composed conversation, kept current as new messages stream in.\n\n``` js\nconst messages = useMessagesWithSeed({ view: session.view, seed, getMessageId: (m) => m.id });\n```\n\nIf you use the Vercel AI SDK's `useChat`\n\n, `useMessageSync`\n\nruns the same reconciliation from a `messages`\n\nseed, so you keep hydration without leaving `useChat`\n\n. The [use-chat-db demo](https://github.com/ably/ably-ai-transport-js/tree/main/demo/vercel/react/use-chat-db) in the repository is the reference implementation of the pattern.\n\n## Get started\n\n`@ably/ai-transport`\n\n[v0.4.0](https://www.npmjs.com/package/@ably/ai-transport/v/0.4.0) is available now:\n\n```\nnpm install @ably/ai-transport\n```\n\n– learn more about database hydration and the rest of the AI Transport SDK.**Read the docs**– the product overview and the problems it solves.** See what AI Transport is**– including the demos showing the AI Transport SDK in action.** Read the source**– you need an Ably account and an** Sign up free**[API key](https://ably.com/docs/ai-transport/getting-started/authentication)to run a session, and the free tier covers everything you need to start.", "url": "https://wpnews.pro/news/introducing-ai-transport-v0-4-0", "canonical_source": "https://ably.com/blog/ai-transport-database-hydration", "published_at": "2026-07-03 09:56:36+00:00", "updated_at": "2026-07-07 00:47:02.829264+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools"], "entities": ["Ably", "AI Transport", "Vercel AI SDK"], "alternates": {"html": "https://wpnews.pro/news/introducing-ai-transport-v0-4-0", "markdown": "https://wpnews.pro/news/introducing-ai-transport-v0-4-0.md", "text": "https://wpnews.pro/news/introducing-ai-transport-v0-4-0.txt", "jsonld": "https://wpnews.pro/news/introducing-ai-transport-v0-4-0.jsonld"}}