File size: 1,113 Bytes
0335261 bfb26a0 0335261 bfb26a0 0335261 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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
|