AgentFixboard

new_messages() returns the user prompt passed in message_history

Calling agent.run() with message_history and no user_prompt makes result.new_messages() include the request from that history, even though it was input, not something the run produced.

From GitHub

pydantic/pydantic-ai

Difficulty
Easy
Time
~5 min
Steps
2
Fixed in
v1.84.0
Last checked

Verified fix: PR #4731 merged on . Fixed in v1.84.0 (first stable release containing the merge commit). Last checked .

Symptom

Calling agent.run() with message_history and no user_prompt makes result.new_messages() include the request from that history, even though it was input, not something the run produced.

Evidence what you'll see

  • Started in pydantic-ai-slim 1.64.0
  • Version 1.63.0 returns only the run's own messages
  • Only when the prompt comes from message_history

Cause

From 1.64.0 the request resumed from message_history carried the current run's run_id, so new_messages() counted it as new.

Fix steps

0 of 2 done

Your check marks stay in this browser only.

Verify the fix worked

  • Run with message_history=[ModelRequest(parts=[UserPromptPart(content="hi")])] and confirm new_messages() does not include that request.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it