Streaming and structured responses
Streaming and structured responses
An agent run takes seconds, sometimes tens of them, and two readers are waiting on it. One is a person watching the Relay chat window who needs to see something within the first half second. The other is your code, which needs the result in a shape it can act on: a category, a flag, a ticket id. Streaming serves the first reader. Structured responses serve the second. A good /chat endpoint does both, and keeps them separate.
Both come from the same runtime. Every LangGraph graph, including the one create_agent builds, has stream and astream methods that yield events while the run is in progress, and create_agent takes a response_format that makes the final state carry a validated object.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.