Skip to content

Extra ModelRequest message when using only message_history #1943

@slmnsh

Description

@slmnsh

Initial Checks

Description

When you try to generate with just message_history, The result contains one additional message with no parts and just instructions.

Example Code

from pydantic_ai import Agent
from pydantic_ai.messages import ModelMessagesTypeAdapter

agent = Agent("openai:gpt-4o-mini", instructions="You are an Agent")

messages = [
    {
        "parts": [
            {
                "content": "How are you?",
                "timestamp": "2025-06-08T14:27:04.870961Z",
                "part_kind": "user-prompt",
            }
        ],
        "instructions": "You are an Agent",
        "kind": "request",
    },
]

history = ModelMessagesTypeAdapter.validate_python(messages)

result = agent.run_sync(message_history=history)

print(result.all_messages_json())

# [
#     {
#         "parts": [
#             {
#                 "content": "How are you?",
#                 "timestamp": "2025-06-08T14:27:04.870961Z",
#                 "part_kind": "user-prompt",
#             }
#         ],
#         "instructions": "You are an Agent",
#         "kind": "request",
#     },
#     {"parts": [], "instructions": "You are an Agent", "kind": "request"},
#     {
#         "parts": [
#             {
#                 "content": "I'm just a program, but thanks for asking! How can I assist you today?",
#                 "part_kind": "text",
#             }
#         ],
#         "model_name": "gpt-4o-mini-2024-07-18",
#         "timestamp": "2025-06-08T14:39:00Z",
#         "kind": "response",
#     },
# ]

Python, Pydantic AI & LLM client version

Python 3.13.2
Pydantic AI >=0.2.14

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions