diff --git a/pydantic_ai_slim/pydantic_ai/messages.py b/pydantic_ai_slim/pydantic_ai/messages.py index 922943317..ec2f3016f 100644 --- a/pydantic_ai_slim/pydantic_ai/messages.py +++ b/pydantic_ai_slim/pydantic_ai/messages.py @@ -501,7 +501,10 @@ class RetryPromptPart: def model_response(self) -> str: """Return a string message describing why the retry is requested.""" if isinstance(self.content, str): - description = self.content + if self.tool_name is None: + description = f'Validation feedback:\n{self.content}' + else: + description = self.content else: json_errors = error_details_ta.dump_json(self.content, exclude={'__all__': {'ctx'}}, indent=2) description = f'{len(self.content)} validation errors: {json_errors.decode()}' diff --git a/tests/models/test_instrumented.py b/tests/models/test_instrumented.py index f2d12b829..c0befafef 100644 --- a/tests/models/test_instrumented.py +++ b/tests/models/test_instrumented.py @@ -240,6 +240,7 @@ async def test_instrumented_model(capfire: CaptureLogfire): { 'body': { 'content': """\ +Validation feedback: retry_prompt2 Fix the errors and try again.\ @@ -619,6 +620,7 @@ async def test_instrumented_model_attributes_mode(capfire: CaptureLogfire): { 'event.name': 'gen_ai.user.message', 'content': """\ +Validation feedback: retry_prompt2 Fix the errors and try again.\ diff --git a/tests/test_agent.py b/tests/test_agent.py index fa5f166cb..b85a9f5d8 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -301,7 +301,7 @@ def return_tuple(_: list[ModelMessage], info: AgentInfo) -> ModelResponse: parts=[ ToolCallPart(tool_name='final_result', args='{"response": ["foo", "bar"]}', tool_call_id=IsStr()) ], - usage=Usage(requests=1, request_tokens=72, response_tokens=8, total_tokens=80), + usage=Usage(requests=1, request_tokens=74, response_tokens=8, total_tokens=82), model_name='function:return_tuple:', timestamp=IsNow(tz=timezone.utc), ), @@ -930,7 +930,7 @@ def call_tool(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse: ), ModelResponse( parts=[TextPart(content='Mexico City')], - usage=Usage(requests=1, request_tokens=68, response_tokens=5, total_tokens=73), + usage=Usage(requests=1, request_tokens=70, response_tokens=5, total_tokens=75), model_name='function:call_tool:', timestamp=IsDatetime(), ), @@ -1584,7 +1584,7 @@ def call_tool(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse: ), ModelResponse( parts=[TextPart(content='{"city": "Mexico City"}')], - usage=Usage(requests=1, request_tokens=68, response_tokens=11, total_tokens=79), + usage=Usage(requests=1, request_tokens=70, response_tokens=11, total_tokens=81), model_name='function:call_tool:', timestamp=IsDatetime(), ),