```javascript
import Groq from "groq-sdk";

const groq = new Groq();

// Define models
const ROUTING_MODEL = "openai/gpt-oss-20b";
const TOOL_USE_MODEL = "openai/gpt-oss-20b";
const GENERAL_MODEL = "openai/gpt-oss-20b";

function calculate(expression) {
  try {
    // Note: Using this method to evaluate expressions in JavaScript can be dangerous.
    // In a production environment, you should use a safer alternative.
    const result = new Function(`return ${expression}`)();
    return JSON.stringify({ result });
  } catch (error) {
    return JSON.stringify({ error: `Invalid expression: ${error}` });
  }
}

async function routeQuery(query) {
  const routingPrompt = `
    Given the following user query, determine if any tools are needed to answer it.
    If a calculation tool is needed, respond with 'TOOL: CALCULATE'.
    If no tools are needed, respond with 'NO TOOL'.

    User query: ${query}

    Response:
    `;

  const response = await groq.chat.completions.create({
    model: ROUTING_MODEL,
    messages: [
      {
        role: "system",
        content:
          "You are a routing assistant. Determine if tools are needed based on the user query.",
      },
      { role: "user", content: routingPrompt },
    ],
    max_completion_tokens: 20,
  });

  const routingDecision = response.choices[0].message?.content?.trim();

  if (routingDecision?.includes("TOOL: CALCULATE")) {
    return "calculate tool needed";
  }

  return "no tool needed";
}

async function runWithTool(query) {
  const messages = [
    {
      role: "system",
      content:
        "You are a calculator assistant. Use the calculate function to perform mathematical operations and provide the results.",
    },
    {
      role: "user",
      content: query,
    },
  ];
  const tools = [
    {
      type: "function",
      function: {
        name: "calculate",
        description: "Evaluate a mathematical expression",
        parameters: {
          type: "object",
          properties: {
            expression: {
              type: "string",
              description: "The mathematical expression to evaluate",
            },
          },
          required: ["expression"],
        },
      },
    },
  ];
  const response = await groq.chat.completions.create({
    model: TOOL_USE_MODEL,
    messages: messages,
    tools: tools,
    tool_choice: "auto",
    max_completion_tokens: 4096,
  });
  const responseMessage = response.choices[0].message;
  const toolCalls = responseMessage.tool_calls;
  if (toolCalls) {
    messages.push(responseMessage);
    for (const toolCall of toolCalls) {
      const functionArgs = JSON.parse(toolCall.function.arguments);
      const functionResponse = calculate(functionArgs.expression);
      messages.push({
        tool_calls_id: toolCall.id,
        role: "tool",
        content: functionResponse,
      });
    }
    const secondResponse = await groq.chat.completions.create({
      model: TOOL_USE_MODEL,
      messages: messages,
    });
    return secondResponse.choices[0].message?.content ?? "";
  }
  return responseMessage.content ?? "";
}

async function runGeneral(query) {
  const response = await groq.chat.completions.create({
    model: GENERAL_MODEL,
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: query },
    ],
  });
  return response.choices[0]?.message?.content ?? "";
}

export async function processQuery(query) {
  const route = await routeQuery(query);
  let response = null;
  if (route === "calculate tool needed") {
    response = await runWithTool(query);
  } else {
    response = await runGeneral(query);
  }

  return {
    query: query,
    route: route,
    response: response,
  };
}

// Example usage
async function main() {
  const queries = [
    "What is the capital of the Netherlands?",
    "Calculate 25 * 4 + 10",
  ];

  for (const query of queries) {
    try {
      const result = await processQuery(query);
      console.log(`Query: ${result.query}`);
      console.log(`Route: ${result.route}`);
      console.log(`Response: ${result.response}\n`);
    } catch (error) {
      console.error(`Error processing query "${query}":`, error);
    }
  }
}

main();
```

---

## Initialize the Groq client