From e5abb3a4ca6cdce907939d0c7d2fe9ca442c5686 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Fri, 6 Mar 2026 11:10:09 -0500 Subject: [PATCH] fix(pydantic-ai): Add error handling to agent execution Wrap the agent.run() call in a try-except block to properly handle exceptions that occur during agent execution. This allows the test to continue running and capture error information instead of crashing. Co-Authored-By: Claude --- .../agents/python/pydantic-ai/template.njk | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/runner/templates/agents/python/pydantic-ai/template.njk b/src/runner/templates/agents/python/pydantic-ai/template.njk index 07c47e0..a4943c7 100644 --- a/src/runner/templates/agents/python/pydantic-ai/template.njk +++ b/src/runner/templates/agents/python/pydantic-ai/template.njk @@ -53,23 +53,26 @@ def {{ tool.name }}(context: RunContext, {% for param in tool.parameters.require {% endif %} {% endfor %} + try: {% if user_content is string %} - result = await agent.run("{{ user_content }}") + result = await agent.run("{{ user_content }}") {% else %} - # Multimodal content - build message parts - message_parts = [] + # Multimodal content - build message parts + message_parts = [] {% for part in user_content %} {% if part.type == 'text' %} - message_parts.append("{{ part.text }}") + message_parts.append("{{ part.text }}") {% elif part.type == 'image' %} - message_parts.append(ImageUrl(url="data:{{ part.mediaType }};base64,{{ part.base64 }}")) + message_parts.append(ImageUrl(url="data:{{ part.mediaType }};base64,{{ part.base64 }}")) {% endif %} {% endfor %} - result = await agent.run(message_parts) + result = await agent.run(message_parts) {% endif %} - # Print response - print(f"Turn {{ loop.index }} Response: {result.output}") + # Print response + print(f"Turn {{ loop.index }} Response: {result.output}") + except Exception as e: + print(f"Turn {{ loop.index }} Error: {type(e).__name__}: {e}") {% if not loop.last %} print() # Blank line between turns {% endif %}