chain.stream executes a LangChain runnable chain and exposes generated results incrementally. A chain can fetch data, apply a prompt template, call an LLM, and parse output before returning streamed values. section 6.1.2
In a Next.js conversation handler, await the stream, iterate with for await, accumulate generated text, and push each update into createStreamableUI. The server then renders the changing response in real time. section 6.1.2
Streaming a weather response
Build a chain with RunnableLambda.from(fetchWeatherData).pipe(promptTemplate).pipe(llm).pipe(new StringOutputParser()), then call chain.stream({ city }). Iterate over the returned stream, append each item to textContent, and update a ChatBubble until stream.done().
