An advanced AI agent implementation using LangGraph.js and MongoDB Atlas Vector Search for intelligent HR assistance and employee data management.
- AI-powered conversational agent using LangGraph.js
- MongoDB Atlas Vector Search for semantic employee search
- Persistent conversation state using MongoDB checkpoints
- Employee data management with vector embeddings
- RESTful API endpoints for chat interactions
- TypeScript implementation for type safety
- Extensible tool system for agent capabilities
- Node.js >= 14
- MongoDB Atlas account
- OpenAI API key
- Anthropic API key
- npm or yarn package manager
- LangGraph.js - AI agent framework
- MongoDB Atlas - Database and vector search
- Express.js - API server
- TypeScript - Programming language
- Anthropic Claude - Language model
- OpenAI - Embeddings generation
- Clone the repository:
git clone <repository-url>
cd ai-agent-project- Install dependencies:
npm install- Create a
.envfile in the project root:
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
MONGODB_ATLAS_URI=your-mongodb-atlas-connection-string- Set up MongoDB Atlas Vector Search index:
- Create a vector index named "vector_index"
- Use the following index definition:
{
"fields": [
{
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}
]
}- Seed the database:
npx ts-node seed-database.ts- Start the server:
npx ts-node index.ts├── .env # Environment variables
├── index.ts # Express server setup
├── agent.ts # AI agent implementation
├── seed-database.ts # Database seeding script
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
POST /chat
Content-Type: application/json
{
"message": "Your initial message"
}POST /chat/:threadId
Content-Type: application/json
{
"message": "Your follow-up message"
}# Start a new conversation
curl -X POST \
-H "Content-Type: application/json" \
-d '{"message": "Build a team to make an iOS app, and tell me the talent gaps."}' \
http://localhost:3000/chat
# Continue conversation
curl -X POST \
-H "Content-Type: application/json" \
-d '{"message": "What are the talent gaps?"}' \
http://localhost:3000/chat/<threadId>- Create a new tool in
agent.ts:
const newTool = tool(
async ({ param1, param2 }) => {
// Tool implementation
return result;
},
{
name: "tool_name",
description: "Tool description",
schema: z.object({
param1: z.string(),
param2: z.number()
})
}
);- Add the tool to the tools array:
const tools = [employeeLookupTool, newTool];Update the prompt template in callModel function:
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
`Your updated system message here...`
],
new MessagesPlaceholder("messages")
]);- Secure API keys in environment variables
- Implement rate limiting for API endpoints
- Validate user input
- Sanitize tool outputs
- Use secure MongoDB connection string
- Implement proper error handling
OPENAI_API_KEY: OpenAI API key for embeddingsANTHROPIC_API_KEY: Anthropic API key for Claude LLMMONGODB_ATLAS_URI: MongoDB Atlas connection stringPORT: Server port (default: 3000)
employees: Stores employee data and embeddingscheckpoints: Stores conversation states
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with LangGraph.js
- MongoDB Atlas Vector Search
- Anthropic Claude API
- OpenAI API
For questions and support, please open an issue in the repository or contact the maintainers.