This repository demonstrates how to use LangGraph with MongoDB for building and managing AI agents and conversational applications using an agentic approach. It showcases the integration of language models, graph-based conversation management, and MongoDB for data persistence, enabling the creation of intelligent, autonomous agents in TypeScript and Express.js.
- Utilizes LangGraph for managing agentic conversational flows in TypeScript
- Integrates with MongoDB Atlas for storing and retrieving conversation data
- Implements a RESTful API using Express.js for chat interactions
- Uses Mistral's AI model for generating responses
- Includes a tool for employee lookup using MongoDB Atlas vector search
- Clone this repository:
git clone https://github.com/jayesh-patidar/hr-gpt.git
cd hr-gpt
- Install the required dependencies:
npm install
- Set up your environment variables:
-
Copy
.env.example
to.env
file in the root directory -
Add your API keys and MongoDB URI:
MISTRAL_API_KEY=your_mistral_api_key_here MONGODB_URI=your_mongodb_atlas_uri_here
- Run the seed script to generate and seed the database:
npm run seed
- Start the server:
npm run dev
- Use the following API endpoints:
- Start a new conversation:
curl -X POST -H "Content-Type: application/json" -d '{"message": "Your message here"}' http://localhost:3000/chat
- Continue an existing conversation:
curl -X POST -H "Content-Type: application/json" -d '{"message": "Your follow-up message"}' http://localhost:3000/chat/{threadId}
index.ts
: Entry point of the application, sets up the Express server and API routesagent.ts
: Defines the LangGraph agent, tools, and conversation flowseed-database.ts
: Script for generating and seeding synthetic employee data into MongoDB
- The seed script in
seed-database.ts
generates synthetic employee data and populates the MongoDB database. - The LangGraph agent is defined in
agent.ts
, including the conversation graph structure and tools. - MongoDB operations are integrated directly into the agent for storing and retrieving conversation data.
- The Express server in
index.ts
provides API endpoints for starting and continuing conversations. - User inputs are processed through the LangGraph agent, generating appropriate responses and updating the conversation state.
- Conversation data is persisted in MongoDB Atlas, allowing for continuity across sessions.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.