ai icon indicating copy to clipboard operation
ai copied to clipboard

(v6) convertToModelMessages is not compatible with agent stream helpers

Open JustinTulloss opened this issue 1 month ago • 2 comments

Description

In createAgentUIStream, no options are given for passing on to convertToModelMessages, which means custom data parts are difficult to use as there's no way to pass in a convertDataPart function (at least that I can find... it may make sense to have it on the Agent itself but it isn't there).

In addition, messages is typed as unknown even though it should be some sort of UIMessage[] type. So passing in the results of convertToModelMessages (ie copying from a non-agent example) will type check successfully and fail at runtime.

https://github.com/vercel/ai/blob/aa69f0a4f307b8f2d85d2daacab6f81494a4979f/packages/ai/src/agent/create-agent-ui-stream.ts#L47

AI SDK Version

  "@ai-sdk/google": "^3.0.0-beta.40",
  "@ai-sdk/openai": "^3.0.0-beta.55",
  "ai": "^6.0.0-beta.94",

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

JustinTulloss avatar Nov 10 '25 20:11 JustinTulloss

Can you share on a higher level what you are trying to achieve, maybe share an example if you can, and how you think it could become easier with API changes to createAgentUIStream ?

gr2m avatar Nov 11 '25 01:11 gr2m

What I'm specifically trying to do is have the client inject DataUIPart messages with a bunch of client state back to the server. See the cursor example PromptInput here. I'm not doing exactly that, but the idea is similar... there's a bunch of different stuff that might get selected by the client either in the prompt or in other parts of the UI that will be attached to the prompt as additional metadata.

Then I want to convert those to text the model has a chance of understanding. Some of the state evolves and some of it should replace the previous messages (ie by having the same ID)

I hacked around this by just injecting the state into the instructions in some cases and building my own UIMessage parts (ie doing the convertDataPart work on my own beforehand. It's fine.

I think the thing that bothered me most about this is that the docs are pretty excited about DataUIPart messages but then they aren't supported in the agent APIs and useChat's sendMessage doesn't really have a good way of working with them either, so you end up side loading them up in body. I like the DataUIPart idea but it doesn't seem fully threaded through yet!

JustinTulloss avatar Nov 11 '25 05:11 JustinTulloss