Repository: UKGovernmentBEIS/inspect_ai
Issue: Agent Bridge yields no content for pydantic-ai agent with an output_type
Root cause: Interface Contract Mismatch

A benefit of using pydantic-ai is how easy it is to give an agent a structured output type that it should return as its final result. When using the agent bridge, if my pydantic-ai agent has an output_type, then inspect fails to extract the answer as content and the evaluation then leads to incorrect evaluations.

Minimal reproducible example is based on the agent bridge [example from the docs](https://github.com/UKGovernmentBEIS/inspect_ai/blob/main/examples/bridge/pydantic-ai/agent.py) - all that is different from that example is I'm providing a output_type to the agent:

```
from dataclasses import dataclass
from pydantic import Field
from pydantic_ai import Agent as PydanticAgent
from pydantic_ai import WebSearchTool

from inspect_ai.agent import Agent, AgentState, agent, agent_bridge
from inspect_ai.model import user_prompt

@dataclass
class AnswerToQueryOutput:
    answer: str = Field(description="The answer to the query")


@agent
def web_research_agent() -> Agent:
    """OpenAI Agents SDK search agent."""

    async def execute(state: AgentState) -> AgentState:
        async with agent_bridge(state) as bridge:
            agent = PydanticAgent(
                "openai-responses:inspect",
                builtin_tools=[WebSearchTool()],
                system_prompt="You help users find information by searching the web.",
                output_type=AnswerToQueryOutput,
            )

            await agent.run(user_prompt(state.messages).text)

            return bridge.state

    return execute
```

This results in a blank answer, despite the final node from pydantic-ai showing the expected final result - I've pasted the nodes below. You can see the expected final result, but inspect is not extracting it

```
Node: 
 
UserPromptNode(user_prompt="What's the difference between tennis and pickleball?", instructions_functions=[], system_prompts=('You help users find information by searching the web.',), system_prompt_functions=[], system_prompt_dynamic_functions={})

Node: 
 
ModelRequestNode(request=ModelRequest(parts=[SystemPromptPart(content='You help users find information by searching the web.', timestamp=datetime.datetime(2025, 10, 29, 20, 39, 26, 56017, tzinfo=datetime.timezone.utc)), UserPromptPart(content="What's the difference between tennis and pickleball?", timestamp=datetime.datetime(2025, 10, 29, 20, 39, 26, 56030, tzinfo=datetime.timezone.utc))]))

Node: 
 
CallToolsNode(model_response=ModelResponse(parts=[BuiltinToolCallPart(tool_name='web_search', args={'query': 'difference between tennis and pickleball', 'type': 'search'}, tool_call_id='ws_0f2509a7daaf5db10169027b7f2510819d809a8045033c8767', provider_name='openai'), BuiltinToolReturnPart(tool_name='web_search', content={'status': 'completed'}, tool_call_id='ws_0f2509a7daaf5db10169027b7f2510819d809a8045033c8767', timestamp=datetime.datetime(2025, 10, 29, 20, 39, 37, 824700, tzinfo=datetime.timezone.utc), provider_name='openai'), TextPart(content='Tennis and pickleball are both racket sports that share some similarities but differ in several key aspects:\n\n**Court Dimensions:**\n- **Tennis:** Played on a larger court measuring 78 feet in length and 27 feet in width for singles, or 36 feet for doubles.\n- **Pickleball:** Played on a smaller court measuring 44 feet in length and 20 feet in width, the same size as a doubles badminton court. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Net Height:**\n- **Tennis:** The net stands at 36 inches (3 feet) at the center.\n- **Pickleball:** The net is slightly lower, measuring 34 inches (2 feet 10 inches) at the center. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Equipment:**\n- **Tennis:** Players use strung rackets to hit a felt-covered rubber ball.\n- **Pickleball:** Players use solid composite or wooden paddles to hit a perforated plastic ball. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Serving Rules:**\n- **Tennis:** Serves are typically overhand and can be directed anywhere within the opponent\'s service box.\n- **Pickleball:** Serves must be underhand, with the paddle contacting the ball below the waist, and the ball must land in the diagonally opposite service court. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Scoring System:**\n- **Tennis:** Uses a unique scoring system with points counted as 15, 30, 40, and game, and matches are played in sets.\n- **Pickleball:** Games are typically played to 11 points, and only the serving team can score points. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Court Zones:**\n- **Tennis:** No specific zones; players can approach the net and volley from anywhere on the court.\n- **Pickleball:** Features a 7-foot non-volley zone, known as the "kitchen," on each side of the net where volleys are prohibited. ([lta.org.uk](https://www.lta.org.uk/play/ways-to-play/pickleball/tennis-vs-pickleball/?utm_source=openai))\n\n**Pace and Intensity:**\n- **Tennis:** Generally involves longer rallies and covers more ground due to the larger court size, offering a more vigorous workout.\n- **Pickleball:** The smaller court and slower ball speed result in shorter rallies and less running, making it more accessible for beginners and those seeking a less intense workout. ([pickleheads.com](https://www.pickleheads.com/guides/pickleball-vs-tennis?utm_source=openai))\n\nIn summary, while both sports involve rackets and a net, tennis is played on a larger court with a higher net, using strung rackets and a felt-covered ball, and has a more complex scoring system. Pickleball, on the other hand, is played on a smaller court with a lower net, using solid paddles and a perforated plastic ball, and features a simpler scoring system with unique rules like the non-volley zone.\n\nFor a visual comparison, you might find this video helpful:\n\n[2 Main Differences Between Pickleball and Tennis](https://www.youtube.com/watch?v=3VufiR_MkPI&utm_source=openai)\n \n<content-internal>eyJtZXNzYWdlX2lkIjogIm1zZ18wZjI1MDlhN2RhYWY1ZGIxMDE2OTAyN2I4MDdlMTg4MTlkYTFkNTU4NzBhOWFmZDE4NyJ9</content-internal>\n', id='DunfXVff9zKPuPu75MzvdN'), ToolCallPart(tool_name='final_result', args='{"answer": "Tennis and pickleball differ primarily in court size, equipment, and rules. Tennis is played on a larger court (78x27 feet for singles), with a higher net (36 inches), using strung rackets and a felt-covered ball. Pickleball uses a smaller court (44x20 feet), a lower net (34 inches), and solid paddles to hit a perforated plastic ball. Pickleball serves are underhand, and there\'s a non-volley zone called the \\"kitchen,\\" which doesn\'t exist in tennis. Scoring also differs: tennis has a unique system (15, 30, 40, game) played in sets, while pickleball games go to 11 points with only the serving team scoring. Pickleball is generally less intense and more accessible due to the smaller court and slower ball speed. Would you like more detailed info on any specific aspect?"}', tool_call_id='call_wagiUVvfLAWP4cYBBxXmh1g1')], usage=RequestUsage(input_tokens=1234, output_tokens=1030, details={'reasoning_tokens': 0}), model_name='gpt-4.1-mini', timestamp=datetime.datetime(2025, 10, 29, 20, 39, 37, tzinfo=TzInfo(0)), provider_name='openai', provider_response_id='ndwrRXsAkuUiZcwddQip2D'))

Node: 
 
End(data=FinalResult(output=AnswerToQueryOutput(answer='Tennis and pickleball differ primarily in court size, equipment, and rules. Tennis is played on a larger court (78x27 feet for singles), with a higher net (36 inches), using strung rackets and a felt-covered ball. Pickleball uses a smaller court (44x20 feet), a lower net (34 inches), and solid paddles to hit a perforated plastic ball. Pickleball serves are underhand, and there\'s a non-volley zone called the "kitchen," which doesn\'t exist in tennis. Scoring also differs: tennis has a unique system (15, 30, 40, game) played in sets, while pickleball games go to 11 points with only the serving team scoring. Pickleball is generally less intense and more accessible due to the smaller court and slower ball speed. Would you like more detailed info on any specific aspect?'), tool_name='final_result', tool_call_id='call_wagiUVvfLAWP4cYBBxXmh1g1'))
```

Please advise if using `output_type` is currently supported with inspect ai and the agent bridge. If not, is it possible to get this functionality or any workarounds you suggest?

Thanks for pointing this out! This occurs because when Pydantic has an output_type the final assistant message just has a tool call. The solution is to hoist out the answer and set the model completion with it. Example has been updated to do this here: https://github.com/UKGovernmentBEIS/inspect_ai/blob/c6492d5d12190ff8769b1af3178efce58967e901/examples/bridge/pydantic-ai/agent.py