from langchain.agents import AgentExecutor, create_react_agent from langchain_openai import ChatOpenAI from utils.prompt import prompt_default from utils.tools import tools_default def create_agent_executor( llm=None, tools=None, prompt=None, verbose=True, max_execution_time=60, max_iterations=10, early_stopping_method="generate", ): if llm is None: llm = ChatOpenAI( model="gpt-4o", # Vision-capable model temperature=0, timeout=60, # 60 second timeout for LLM calls request_timeout=120, # 2 minute timeout for requests max_retries=2, # Retry failed requests ) if tools is None: tools = tools_default if prompt is None: prompt = prompt_default agent = create_react_agent(llm, tools, prompt) agent_executor = AgentExecutor( agent=agent, tools=tools, verbose=verbose, max_execution_time=max_execution_time, max_iterations=max_iterations, early_stopping_method=early_stopping_method, ) return agent_executor