Issues with AI Agent in Node.js (Multiple Tools + Free LLMs like Mistral & Gemini)

Hi everyone,

I’ve been building my own AI Agent in Node.js based on the MongoDB AI Agent example, but using free LLMs instead of OpenAI.
Here’s the setup and what I’ve run into:


Setup

  • LLM: Mistral 7B via OpenRouter (later also tried Gemini API)
  • Tools implemented:
    1. Currency conversion (FX API)
    2. LEI verification (GLEIF API)
    3. Bitcoin price lookup (CoinGecko API)

What I observed

  1. With a single tool → works fine (both Mistral & Gemini).
  2. With two tools (currency + LEI) → initially, the second tool didn’t trigger and the model hallucinated results.
  • Oddly, when I swapped the order (LEI first, currency second), it started working better… but sometimes the second tool still wouldn’t get called.
  1. With three tools → it fails consistently, doesn’t trigger tools properly, and gives hallucinated answers instead.
  2. Tried switching to Gemini LLM to see if it’s model-specific → but even with one tool, Gemini doesn’t call the tool.

My questions for the community:

  • Has anyone faced similar tool invocation issues in Node.js AI Agents when using multiple tools?
  • Could this be due to the way tools are registered or the limitations of free LLM providers like OpenRouter/Gemini?
  • Does anyone have a working Node.js AI Agent example with multiple tools using a free LLM instead of OpenAI?

Why I’m asking:
I’m trying to make a stable multi-tool AI Agent without depending on OpenAI, but I’m hitting weird behavior when more than one tool is registered. Any pointers, code snippets, or best practices would be super helpful!

Thanks in advance!