Pydantic AI CodeMode speculatively runs tools mid-generation, cutting 3 lookups from 8.7s to 4.7s

samuelcolvin · x · 2026-10-18

Pydantic AI's CodeMode now supports speculative tool execution: declare tools via CodeMode(speculate=['getweather']) and a call with literal keyword arguments launches as soon as its line streams in — no need to wait for the model to finish writing code. The author measured 3 slow lookups dropping from 8.7s to 4.7s. The pattern parallelizes model output streaming with tool execution, useful for agents with multiple independent slow I/O calls.

Original post →

More from coding & agent

coding & agent channel →