Created
March 17, 2025 19:40
-
-
Save orarbel/5cfcac749cd60282ad7da2f43530ac16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import pytest | |
from langchain.agents import initialize_agent, AgentType | |
from langchain.agents.agent import AgentExecutor | |
from langchain.tools import Tool | |
from langchain_community.llms import OpenAI | |
from langchain.prompts import PromptTemplate | |
from langgraph.prebuilt import create_react_agent | |
# Agno imports | |
from agno.agent.agent import Agent | |
from agno.models.openai.chat import OpenAIChat | |
from llms import get_gpt4_o | |
def dummy_tool(): | |
"""A dummy tool for testing""" | |
return "dummy result" | |
def test_agent_initialization_and_execution_times(): | |
# Setup common components | |
llm = get_gpt_4o() | |
tools = [ | |
Tool( | |
name="DummyTool", | |
func=dummy_tool, | |
description="A dummy tool for testing" | |
) | |
] | |
test_question = "What is 2 + 2? Use the dummy tool if needed." | |
# Test LangChain create_react_agent | |
start_time = time.perf_counter() | |
agent = create_react_agent(model=llm, tools=tools) | |
create_react_time = time.perf_counter() - start_time | |
# Test LangChain execution | |
start_time = time.perf_counter() | |
inputs = { | |
"messages": [("user", test_question)] | |
} | |
langchain_response = agent.invoke(inputs) | |
langchain_execution_time = time.perf_counter() - start_time | |
# Test Agno initialization | |
start_time = time.perf_counter() | |
agno_agent = Agent( | |
model=OpenAIChat(id="gpt-4o", temperature=0.6), | |
tools=[dummy_tool], | |
markdown=True | |
) | |
agno_time = time.perf_counter() - start_time | |
# Test Agno execution | |
start_time = time.perf_counter() | |
agno_response = agno_agent.run(test_question) | |
agno_execution_time = time.perf_counter() - start_time | |
print(f"\nInitialization times:") | |
print(f"LangChain create_react_agent: {create_react_time:.4f} seconds") | |
print(f"Agno Agent: {agno_time:.4f} seconds") | |
print(f"\nExecution times:") | |
print(f"LangChain execution: {langchain_execution_time:.4f} seconds") | |
print(f"Agno execution: {agno_execution_time:.4f} seconds") | |
# Compare speeds | |
fastest_init_time = min(create_react_time, agno_time) | |
fastest_exec_time = min(langchain_execution_time, agno_execution_time) | |
if fastest_init_time == create_react_time: | |
fastest_init = "create_react_agent" | |
else: | |
fastest_init = "Agno" | |
if fastest_exec_time == langchain_execution_time: | |
fastest_exec = "LangChain" | |
else: | |
fastest_exec = "Agno" | |
print(f"\nSpeed comparisons:") | |
print(f"Initialization - create_react_agent vs Agno: {create_react_time/agno_time:.2f}x") | |
print(f"Execution - LangChain vs Agno: {langchain_execution_time/agno_execution_time:.2f}x") | |
print(f"\n{fastest_init} has the fastest initialization") | |
print(f"{fastest_exec} has the fastest execution") | |
return { | |
'init_times': (create_react_time, agno_time), | |
'exec_times': (langchain_execution_time, agno_execution_time), | |
'responses': (langchain_response, agno_response) | |
} | |
if __name__ == "__main__": | |
test_agent_initialization_and_execution_times() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment