Multi-Agent AI

Building a Multi-Agent AI with LangGraph, Gemini Pro, and Real-Time Tools

Introduction

AI is evolving from simple question-answer systems to autonomous multi-agent architectures. Instead of a single model trying to handle everything, multi-agent AI combines specialized agents—each expert in a domain (like weather, finance, or research)—with an orchestrator that decides which agent to invoke.

In this tutorial, we’ll explore how to build a production-ready multi-agent AI using:

  • LangGraph for orchestration
  • Gemini Pro 2.5 (Google Generative AI) for fallback reasoning
  • Real-time APIs (weather, currency, stocks, Wikipedia)
  • Math.js for safe mathematical computation

Why Multi-Agent AI?

Unlike a single monolithic model, multi-agent systems have several advantages:

  • Domain Expertise: Each agent specializes (e.g., WeatherAgent, FinanceAgent).
  • Improved Accuracy: Delegates tasks to the most relevant tool or API.
  • Extensibility: Easily add new tools like News API, LangChain memory, or Telegram bot integration.
  • Cost Efficiency: Only call LLMs when other tools cannot answer.

Scope of This Project

Our multi-agent AI includes:

  • WeatherAgent: Fetches live weather data (OpenWeatherMap API).
  • MathAgent: Evaluates secure mathematical expressions using math.js.
  • FinanceAgent: Currency conversion & stock price lookup.
  • ResearchAgent: Wikipedia summaries (and extendable to News APIs).
  • Orchestrator: Routes queries intelligently using LangGraph & Gemini fallback.

The architecture is flexible and modular—you can add memory (vector DB), integrate LangChain, or deploy it as a Telegram bot or web app.

How It Works

  1. Input Query: User asks a question like:
    “Convert 125 USD to INR”
    “What’s the weather in London?”
    “Wiki Alan Turing”
  2. Router Agent: Uses LangGraph’s state machine to pick the right agent.
  3. Specialized Agents:
    • Weather API → OpenWeatherMap
    • Currency → Frankfurter API (no key)
    • Stocks → Alpha Vantage API
    • Wikipedia → REST summary API
    • Math → math.js
  4. Fallback: If no specialized agent matches, query is sent to Gemini Pro for a natural language answer.

Implementation: Step by Step

We implemented the solution in Node.js (ESM) using:

  • dotenv for API keys
  • axios for HTTP calls
  • mathjs for safe math evaluation
  • LangGraph for agent orchestration
  • @google/generative-ai for LLM responses

Key Features:

  • Regex-based query parsing for extracting city names, stock symbols, and currency pairs.
  • Safe evaluation of math expressions (no eval!).
  • Fallback to Gemini Pro for open-ended queries.
  • Error handling & sanitization for production readiness.

Sample Queries & Outputs

  • What is the weather in London? → WeatherAgent fetches from OpenWeatherMap.
  • Convert 125 USD to INR → FinanceAgent calls Frankfurter API.
  • Wiki Alan Turing → Wikipedia summary.
  • Calculate (56*23)+100 → MathAgent computes result.
  • Give me a motivational quote → Gemini fallback.

Git code is available at : https://github.com/110059/agentic-ai

Similar Posts