autogen_instantiation.py
"""
AutoGen Instantiation Performance Evaluation
============================================
Demonstrates agent instantiation benchmarking with AutoGen.
"""
from typing import Literal
from agno.eval.performance import PerformanceEval
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
# ---------------------------------------------------------------------------
# Create Benchmark Tool
# ---------------------------------------------------------------------------
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")
tools = [get_weather]
# ---------------------------------------------------------------------------
# Create Benchmark Function
# ---------------------------------------------------------------------------
def instantiate_agent():
return AssistantAgent(
name="assistant",
model_client=OpenAIChatCompletionClient(
model="gpt-4o",
model_info={
"vision": False,
"function_calling": True,
"json_output": False,
"family": "gpt-4o",
"structured_output": True,
},
),
tools=tools,
)
# ---------------------------------------------------------------------------
# Create Evaluation
# ---------------------------------------------------------------------------
autogen_instantiation = PerformanceEval(func=instantiate_agent, num_iterations=1000)
# ---------------------------------------------------------------------------
# Run Evaluation
# ---------------------------------------------------------------------------
if __name__ == "__main__":
autogen_instantiation.run(print_results=True, print_summary=True)
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno "autogen-ext[openai]" autogen-agentchat memory-profiler
3
Export your API keys
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
Run the example
Save the code above as
autogen_instantiation.py, then run:python autogen_instantiation.py