11.04

Streaming and structured responses

skillmaxingPython with AIStreaming and structured responses
Visual lesson

Streaming and structured responses

Included with Pro · 4:25
Lessons · 970 words

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.

Pro

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.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online