Pydantic AI resends full conversation history every step, causing quadratic token costs
Pydantic AI's agent loop appends each request and response to a single growing message list, then resends the entire accumulated history to the model on every subsequent step. This means a run with n steps transmits roughly O(n²) cumulative tokens, as each tool output — such as file contents or API responses — is re-uploaded on every later step. A developer analyzed the framework's source code and found the same pattern in OpenAI Agents SDK and smolagents. The cost impact is invisible during testing since runs still succeed, but shows up as inflated token usage on billing statements. Developers can mitigate this by passing trimmed or summarized history between runs using Pydantic AI's built-in message_history parameter.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in