File size: 1,180 Bytes
72bab8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
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",
)