Asked about Streaming from the model to the screen
How do you handle a tool call that arrives in a stream?
An answer that works
The arguments come as fragments of a JSON string, split at points that respect nothing about JSON, so you accumulate them keyed by the call index and parse once the block is finished. Parsing each fragment as it arrives fails on nearly all of them. Show the tool name in the interface as soon as it arrives, and the result when the tool returns, so the user sees progress without seeing half-formed JSON.
What gets marked up
Marked up for keying by index, which is what makes parallel tool calls work, and for knowing that the name arrives before the arguments.
Reading an answer is not being able to give one. The section that teaches this is Streaming from the model to the screen, 4 hours of Streaming responses.
Learn this properlyAlso asked about Streaming responses