Skip to content

Tavily-FDE/autopr--fork-langgraph-multi-tool-agent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LangGraph Multi-Tool AI Agent

A small but complete AI agent built with LangGraph, Flask, OpenAI, SerpAPI, and a safe calculator tool.

The app routes each user message to the right capability: normal chat, web search, translation, or calculation. It includes both a command-line interface and a modern chat-style web UI with Server-Sent Events for a faster response experience.

Why This Project Matters

This project demonstrates practical AI engineering skills:

  • building an agent workflow with LangGraph
  • routing user intent with an LLM
  • connecting external tools such as search and calculator functions
  • keeping tool code separate from graph orchestration
  • building a usable Flask frontend for the agent
  • handling environment variables safely
  • passing recent chat history back into the model

Features

  • AI intent classification
  • normal chat support
  • real Google search results through SerpAPI
  • safe math calculator using Python ast
  • English translation route
  • Flask chat interface
  • Server-Sent Events for responsive message updates
  • browser-session chat history
  • command-line mode for quick testing
  • clean folder structure for learning and teaching

Architecture

User message
   |
   v
Flask UI or CLI
   |
   v
LangGraph state
   |
   v
intent_detection node
   |
   v
conditional routing
   |
   +-- chat --------> chat_node --------> response
   +-- search ------> search_node ------> SerpAPI + LLM summary
   +-- calculator --> calculator_node --> safe math result
   +-- translator --> translator_node --> English translation
   +-- fallback ----> fallback_node ----> general LLM answer

Project Structure

.
|-- agent.py                  # CLI entry point
|-- app.py                    # Flask web app
|-- langgraph_agent/
|   |-- graph.py              # LangGraph nodes and edges
|   |-- intent.py             # LLM intent classifier
|   |-- llm.py                # OpenAI setup
|   |-- nodes.py              # Agent node functions
|   `-- state.py              # Shared graph state
|-- tools/
|   |-- calculator.py         # Safe calculator tool
|   `-- search_tool.py        # SerpAPI search tool
|-- templates/
|   `-- index.html            # Tailwind chat UI
|-- static/
|   `-- styles.css            # Small custom CSS
|-- .env.example              # Environment template
`-- requirements.txt

Tech Stack

  • Python
  • LangGraph
  • LangChain OpenAI
  • OpenAI API
  • SerpAPI
  • Flask
  • Tailwind CSS
  • Server-Sent Events

Setup

Create and activate a virtual environment:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

Install dependencies:

pip install -r requirements.txt

Create your environment file:

Copy-Item .env.example .env

Fill in .env:

OPENAI_API_KEY=your_openai_key
OPENAI_MODEL=gpt-4.1-mini
SERPAPI_API_KEY=your_serpapi_key
FLASK_SECRET_KEY=change-this-for-production

Run The Web App

python app.py

Open:

http://127.0.0.1:5000

Run From The CLI

python agent.py "25 * 12"
python agent.py "Who won the World Cup in 2022?"
python agent.py "Bonjour comment allez-vous"
python agent.py "Tell me a simple joke about Python"

Interactive mode:

python agent.py

Example Use Cases

  • Ask a normal question:
Explain LangGraph in simple words.
  • Search the web:
What are the latest OpenAI models?
  • Calculate:
sqrt(144) + 6
  • Translate:
Bonjour comment allez-vous

Notes

Intent detection always uses the OpenAI model, so OPENAI_API_KEY is required to route every query.

Search uses SerpAPI, so search questions also require SERPAPI_API_KEY.

The web app stores recent chat history in memory for the current running server. For production, this could be replaced with Redis, SQLite, Postgres, or another persistent store.

Security

Do not commit your .env file. This project includes .gitignore rules to keep local keys private.

If an API key is ever shared publicly, rotate it immediately from the provider dashboard.

Good Repository Names

Recommended:

langgraph-multi-tool-agent

Other strong options:

langgraph-ai-agent
ai-agent-tool-router
flask-langgraph-agent
multi-tool-ai-assistant
serpapi-langgraph-agent

Portfolio Summary

This project shows how to build a real AI agent that can classify user intent, call external tools, use web search, remember recent conversation, and provide a polished chat interface.

About

A LangGraph-powered multi-tool AI agent with LLM intent routing, SerpAPI web search, safe calculator execution, chat memory, and a Flask/Tailwind chat interface.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 49.8%
  • HTML 48.1%
  • CSS 2.1%