Streaming Agents with Pydantic AI over Typed WebSockets: Tools, Approvals, and a Generated Client

https://hackernoon.imgix.net/images/zVjkyxMw8wMXdtd791QOTmlledp2-3v83chl.png

I’ve been building realtime products for years: group chat, voice pipelines, streaming AI assistants. Two kinds of pain kept following me around.

The first was WebSockets. Every project grew the same untyped receive_json handler with an if/else chain, hand-written validation, and no contract the frontend could rely on. Messages were stringly-typed, bugs surfaced at runtime, and onboarding a teammate meant “read the consumer, end to end”. That pain is why I built chanx: typed messages, automatic routing, AsyncAPI docs.

The second was agent frameworks. I shipped my first LLM features on LangChain and spent more time debugging its abstractions than my own code. Pydantic AI won me over the first time I tried it: typed tools, typed outputs, typed dependency injection. It applies to agents the same philosophy chanx applies to WebSockets, and since both are built on Pydantic they snap together with almost no glue.

There’s just one...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more