import os from langchain_nvidia_ai_endpoints import ChatNVIDIA from langgraph.prebuilt import create_react_agent import logging from LoggerSingleton import ChatLogger from models import RateLimitLLMHandler def add(a: float, b: float): """Add two numbers.""" return a + b def multiply(a: float, b: float): """Multiply two numbers.""" return a * b def divide(a: float, b: float): """Divide two numbers.""" return a / b logger: logging.Logger = ChatLogger.get_logger("0") handler = RateLimitLLMHandler(limit=40, chat_logger=logger) nvidia_api_key = os.environ["NVIDIA_API_KEY"] llm = ChatNVIDIA( model="meta/llama-3.3-70b-instruct", api_key=nvidia_api_key, temperature=0.2, top_p=0.7, max_tokens=1024, callbacks=[handler] ) math_agent = create_react_agent( model=llm, tools=[add, multiply, divide], prompt=( "You are a math agent.\n\n" "INSTRUCTIONS:\n" "- Assist ONLY with math-related tasks\n" "- After you're done with your tasks, respond to the supervisor directly\n" "- Respond ONLY with the results of your work, do NOT include ANY other text." ), name="math_agent", )