The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
perf(langchain): add benchmark command (#36641)
Eugene Yurtsevf0c5a28fa05a
diff --git a/libs/langchain_v1/Makefile b/libs/langchain_v1/Makefileindex 8d6da4cb97..cb14bbaba3 100644--- a/libs/langchain_v1/Makefile+++ b/libs/langchain_v1/Makefile@@ -1,4 +1,4 @@-.PHONY: all start_services stop_services coverage coverage_agents test test_fast extended_tests test_watch test_watch_extended integration_tests check_imports check_version lint format type lint_diff format_diff lint_package lint_tests help+.PHONY: all start_services stop_services coverage coverage_agents test test_fast benchmark extended_tests test_watch test_watch_extended integration_tests check_imports check_version lint format type lint_diff format_diff lint_package lint_tests help# Default target executed when no arguments are given to make.all: help@@ -46,6 +46,9 @@ test:test_fast:LANGGRAPH_TEST_FAST=1 uv run --group test pytest -n auto $(PYTEST_EXTRA) --disable-socket --allow-unix-socket $(TEST_FILE)+benchmark:+ uv run --group test pytest tests/benchmarks/test_create_agent.py -m benchmark+extended_tests:make start_services && LANGGRAPH_TEST_FAST=0 uv run --group test pytest --disable-socket --allow-unix-socket --only-extended tests/unit_tests; \EXIT_CODE=$$?; \@@ -117,6 +120,7 @@ help:@echo 'coverage_agents - run middleware and agent tests with coverage report'@echo 'test - run unit tests with all services'@echo 'test_fast - run unit tests with in-memory services only'+ @echo 'benchmark - run the create_agent benchmark quickly'@echo 'tests - run unit tests (alias for "make test")'@echo 'test TEST_FILE=<test_file> - run all tests in file'@echo 'extended_tests - run only extended unit tests'diff --git a/libs/langchain_v1/pyproject.toml b/libs/langchain_v1/pyproject.tomlindex 98c1ccfb5d..cb6f9f4bec 100644--- a/libs/langchain_v1/pyproject.toml+++ b/libs/langchain_v1/pyproject.toml@@ -68,6 +68,7 @@ test = ["pytest-socket>=0.6.0,<1.0.0","pytest-xdist<4.0.0,>=3.6.1","pytest-mock",+ "pytest-benchmark>=5.1.0,<6.0.0","syrupy>=4.0.2,<6.0.0","toml>=0.10.2,<1.0.0","blockbuster>=1.5.26,<1.6.0",@@ -189,6 +190,7 @@ markers = ["requires: mark tests as requiring a specific library","scheduled: mark tests to run in scheduled testing","compile: mark placeholder test used to compile integration tests without running them",+ "benchmark: mark benchmark tests",]asyncio_mode = "auto"filterwarnings = [diff --git a/libs/langchain_v1/tests/benchmarks/__init__.py b/libs/langchain_v1/tests/benchmarks/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/libs/langchain_v1/tests/benchmarks/test_create_agent.py b/libs/langchain_v1/tests/benchmarks/test_create_agent.pynew file mode 100644index 0000000000..d7f536a134--- /dev/null+++ b/libs/langchain_v1/tests/benchmarks/test_create_agent.py@@ -0,0 +1,14 @@+import pytest+from langchain_core.language_models.fake_chat_models import GenericFakeChatModel+from langchain_core.messages import AIMessage+from pytest_benchmark.fixture import BenchmarkFixture++from langchain.agents import create_agent+++def test_create_agent_instantiation(benchmark: BenchmarkFixture) -> None:+ def instantiate_agent() -> None:+ create_agent(model=GenericFakeChatModel(messages=iter([AIMessage(content="ok")])))++ benchmark(instantiate_agent)diff --git a/libs/langchain_v1/uv.lock b/libs/langchain_v1/uv.lockindex 3909406d3c..eefbf608a6 100644--- a/libs/langchain_v1/uv.lock+++ b/libs/langchain_v1/uv.lock@@ -1986,6 +1986,7 @@ test = [{ name = "langchain-tests" },{ name = "pytest" },{ name = "pytest-asyncio" },+ { name = "pytest-benchmark" },{ name = "pytest-cov" },{ name = "pytest-mock" },{ name = "pytest-socket" },@@ -2040,6 +2041,7 @@ test = [{ name = "langchain-tests", editable = "../standard-tests" },{ name = "pytest", specifier = ">=8.0.0,<10.0.0" },{ name = "pytest-asyncio", specifier = ">=0.23.2,<2.0.0" },+ { name = "pytest-benchmark", specifier = ">=5.1.0,<6.0.0" },{ name = "pytest-cov", specifier = ">=4.0.0,<8.0.0" },{ name = "pytest-mock" },{ name = "pytest-socket", specifier = ">=0.6.0,<1.0.0" },