from langchain import hub from langchain.agents import AgentExecutor, create_react_agent, load_tools from langchain.tools import tool from langchain_openai import ChatOpenAI from dotenv import load_dotenv from tools import lookup_ip, lookup_name from langsmith import Client """ This is the main runner of the custom agent. Agent tools are defined seperatly and imported from tools.py So far, wholly adapted from https://github.com/wu4f/cs410g-src/blob/main/04_Agents/07_tools_custom_agent.py """ load_dotenv() #os.environ["LANGCHAIN_TRACING_V2"] = "true" #os.environ["LANGCHAIN_PROJECT"] = f"LangSmith Introduction" #os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com" #client = Client() llm = ChatOpenAI(model_name="gpt-4-turbo", temperature=0) tools = load_tools(["serpapi", "terminal"], allow_dangerous_tools=True) tools.extend([lookup_name, lookup_ip]) base_prompt = hub.pull("langchain-ai/react-agent-template") prompt = base_prompt.partial(instructions="Answer the user's request utilizing at most 8 tool calls") agent = create_react_agent(llm,tools,prompt) agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) print("Welcome to my application. I am configured with these tools:") for tool in agent_executor.tools: print(f' Tool: {tool.name} = {tool.description}') while True: line = input("llm>> ") try: if line: result = agent_executor.invoke({"input":line}) print(result) else: break except Exception as e: print(e)