from dotenv import load_dotenv

from langgraph.prebuilt import create_react_agent

from examples.utils import print_agent_response
from trim.trim_chatmodel import TrimChatModel

load_dotenv()


# 1. Define a simple math tool
def calculator(expression: str) -> str:
    """Evaluates a basic math expression."""
    try:
        return str(eval(expression))
    except Exception as e:
        return f"Error: {e}"


# 2. Instantiate your language model (replace with your config if needed)
llm = TrimChatModel()

# 3. Initialize the ReAct agent
agent = create_react_agent(
    model=llm,
    tools=[calculator],  # List of tools for the agent         # Prints the reasoning steps
)

# 4. Use the agent
response = agent.invoke({"messages": "What is (12 * 3) + 5?"})
print_agent_response(response['messages'])
