> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PydanticAI Instantiation Performance Evaluation

> Benchmark 1000 PydanticAI agent constructions, including an inline @agent.tool_plain weather tool, via Agno's PerformanceEval.

Demonstrates agent instantiation benchmarking with PydanticAI.

```python pydantic_ai_instantiation.py theme={null}
"""
PydanticAI Instantiation Performance Evaluation
===============================================

Demonstrates agent instantiation benchmarking with PydanticAI.
"""

from typing import Literal

from agno.eval.performance import PerformanceEval
from pydantic_ai import Agent


# ---------------------------------------------------------------------------
# Create Benchmark Function
# ---------------------------------------------------------------------------
def instantiate_agent():
    agent = Agent(
        "openai:gpt-5.6-luna", system_prompt="Be concise, reply with one sentence."
    )

    # Tool definition remains scoped to agent construction by design.
    @agent.tool_plain
    def get_weather(city: Literal["nyc", "sf"]):
        """Use this to get weather information."""
        if city == "nyc":
            return "It might be cloudy in nyc"
        elif city == "sf":
            return "It's always sunny in sf"
        else:
            raise AssertionError("Unknown city")

    return agent


# ---------------------------------------------------------------------------
# Create Evaluation
# ---------------------------------------------------------------------------
pydantic_instantiation = PerformanceEval(func=instantiate_agent, num_iterations=1000)

# ---------------------------------------------------------------------------
# Run Evaluation
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    pydantic_instantiation.run(print_results=True, print_summary=True)
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno memory-profiler pydantic-ai
```

**2. Export your API keys**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `pydantic_ai_instantiation.py`, then run:

```bash theme={null}
python pydantic_ai_instantiation.py
```

Full source: [cookbook/09\_evals/performance/comparison/pydantic\_ai\_instantiation.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/09_evals/performance/comparison/pydantic_ai_instantiation.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.