Skip to content

Commit 22f775b

Browse files
authored
Revert "feat: enforce message history starts with user message (#3440)"
This reverts commit 468e60a.
1 parent 556ee09 commit 22f775b

File tree

3 files changed

+1
-25
lines changed

3 files changed

+1
-25
lines changed

pydantic_ai_slim/pydantic_ai/_agent_graph.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ async def run( # noqa: C901
216216
ctx.state.message_history = messages
217217
ctx.deps.new_message_index = len(messages)
218218

219-
# Validate that message history starts with a user message
220-
if messages and isinstance(messages[0], _messages.ModelResponse):
221-
raise exceptions.UserError(
222-
'Message history cannot start with a `ModelResponse`. Conversations must begin with a user message.'
223-
)
224-
225219
if self.deferred_tool_results is not None:
226220
return await self._handle_deferred_tool_results(self.deferred_tool_results, messages, ctx)
227221

tests/models/test_outlines.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ def test_input_format(transformers_multimodal_model: OutlinesModel, binary_image
577577

578578
# unsupported: tool calls
579579
tool_call_message_history: list[ModelMessage] = [
580-
ModelRequest(parts=[UserPromptPart(content='some user prompt')]),
581580
ModelResponse(parts=[ToolCallPart(tool_call_id='1', tool_name='get_location')]),
582581
ModelRequest(parts=[ToolReturnPart(tool_name='get_location', content='London', tool_call_id='1')]),
583582
]
@@ -593,8 +592,7 @@ def test_input_format(transformers_multimodal_model: OutlinesModel, binary_image
593592

594593
# unsupported: non-image file parts
595594
file_part_message_history: list[ModelMessage] = [
596-
ModelRequest(parts=[UserPromptPart(content='some user prompt')]),
597-
ModelResponse(parts=[FilePart(content=BinaryContent(data=b'test', media_type='text/plain'))]),
595+
ModelResponse(parts=[FilePart(content=BinaryContent(data=b'test', media_type='text/plain'))])
598596
]
599597
with pytest.raises(
600598
UserError, match='File parts other than `BinaryImage` are not supported for Outlines models yet.'

tests/test_agent.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6132,19 +6132,3 @@ def llm(messages: list[ModelMessage], _info: AgentInfo) -> ModelResponse:
61326132
]
61336133
)
61346134
assert run.all_messages_json().startswith(b'[{"parts":[{"content":"Hello",')
6135-
6136-
6137-
def test_message_history_cannot_start_with_model_response():
6138-
"""Test that message history starting with ModelResponse raises UserError."""
6139-
6140-
agent = Agent('test')
6141-
6142-
invalid_history = [
6143-
ModelResponse(parts=[TextPart(content='ai response')]),
6144-
]
6145-
6146-
with pytest.raises(
6147-
UserError,
6148-
match='Message history cannot start with a `ModelResponse`.',
6149-
):
6150-
agent.run_sync('hello', message_history=invalid_history)

0 commit comments

Comments
 (0)