Update app.py
Browse files5 unmodified lines6789101158 unmodified lines7071727374757677787980818283848586875 unmodified linesfrom langchain_core.tools import Toolfrom langchain_groq import ChatGroqfrom langgraph.prebuilt import create_react_agentload_dotenv()58 unmodified lines_agent_executor = Noneasync def get_agent_executor():"""Initializes and returns the agent executor, ensuring it's a singleton."""global _agent_executorif _agent_executor is None:if not os.getenv("GROQ_API_KEY"):raise ValueError("GROQ_API_KEY secret not set.")client = MCPClient(command=sys.executable, args=["server.py"])tools = await client.get_tools()model = ChatGroq(model="openai/gpt-oss-20b")_agent_executor = create_react_agent(model, tools)return _agent_executor# --- Gradio Chat Logic ---async def respond_to_chat(message: str, history: list):agent = await get_agent_executor()5 unmodified lines67891011121358 unmodified lines7273747576777879808182838485868788899091929394955 unmodified linesfrom langchain_core.tools import Toolfrom langchain_groq import ChatGroqfrom langgraph.prebuilt import create_react_agentfrom langchain.agents import create_tool_calling_agentfrom langchain.tools import convert_to_openai_toolload_dotenv()58 unmodified lines_agent_executor = Noneasync def get_agent_executor():global _agent_executorif _agent_executor is None:if not os.getenv("GROQ_API_KEY"):raise ValueError("GROQ_API_KEY secret not set.")client = MCPClient(command=sys.executable, args=["server.py"])tools_raw = await client.get_tools()tools = [convert_to_openai_tool(t) for t in tools_raw] # 🟢 Key Fixmodel = ChatGroq(model="openai/gpt-oss-20b")_agent_executor = create_tool_calling_agent(model, tools) # 🟢 Key Fixreturn _agent_executor# --- Gradio Chat Logic ---async def respond_to_chat(message: str, history: list):agent = await get_agent_executor()
app.py+11-3