LangGraph Instantiation Performance Evaluation

Measure LangGraph create_react_agent instantiation over 1,000 iterations per metric with PerformanceEval, using ChatOpenAI gpt-5.6-luna and a weather tool.

Demonstrates agent instantiation benchmarking with LangGraph.

This evaluation performs 2,010 callable invocations: 10 warm-ups, 1,000 runtime measurements, and 1,000 memory measurements. It measures construction, not model inference.

This preserved example measures the legacy create_react_agent factory. For new applications, follow LangChain’s migration to create_agent. Measurements from different factories describe different workloads.

PerformanceEval runs the callable separately for each enabled metric: warm-ups first, then runtime measurements, then memory measurements. num_iterations applies to each metric, and the default is 10 additional warm-up calls. Model retries, tools, delegation, and memory extraction can add provider requests beyond the callable count.

Memory measurements use Python’s tracemalloc; they do not measure process RSS, GPU memory, database-server memory, or remote model memory. Record dependency versions, database state, and model settings when comparing results.

langgraph_instantiation.py
"""
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-5.6-luna"), 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

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno langchain-core langchain-openai langgraph

Export your API keys

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as langgraph_instantiation.py, then run:

python langgraph_instantiation.py

Full source: cookbook/09_evals/performance/comparison/langgraph_instantiation.py