Copy
Ask AI
"""
LangGraph Instantiation Performance Evaluation
==============================================
Demonstrates agent instantiation benchmarking with LangGraph.
"""
from typing import Literal
from agno.eval.performance import PerformanceEval
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
# ---------------------------------------------------------------------------
# Create Benchmark Tool
# ---------------------------------------------------------------------------
@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 create_react_agent(model=ChatOpenAI(model="gpt-4o"), tools=tools)
# ---------------------------------------------------------------------------
# Create Evaluation
# ---------------------------------------------------------------------------
langgraph_instantiation = PerformanceEval(func=instantiate_agent, num_iterations=1000)
# ---------------------------------------------------------------------------
# Run Evaluation
# ---------------------------------------------------------------------------
if __name__ == "__main__":
langgraph_instantiation.run(print_results=True, print_summary=True)
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/09_evals/performance/comparison
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python langgraph_instantiation.py