The HR Policy Generation Agent is an intelligent platform that leverages AI to streamline the creation, updating, and management of HR policies for organizations. Built with Next.js and powered by Lyzr AI agents, it provides an intuitive interface for generating compliant, country-specific HR policies through conversational AI.
- AI-Powered Policy Generation - Create comprehensive HR policies through natural conversation with specialized AI agents
- Multi-Country Compliance - Generate policies compliant with regulations across multiple jurisdictions (US, Canada, UK, Germany, France, India, Australia)
- Intelligent Policy Updates - Update existing policies with AI-assisted compliance checking and version control
- PDF Upload & Analysis - Upload existing policy documents for analysis, parsing, and conversion to editable format
- Policy Database - Centralized repository for storing, viewing, and managing all organizational policies
- Real-time Research - Integrated Perplexity AI agent for up-to-date legal and compliance research
- Rich Text Editing - Professional editor with formatting, highlighting, and markdown support
- Version Control - Track policy changes with versioning and status management (Draft, In Review, Approved, Published, Archived)
- Dark Mode Support - Comfortable viewing experience with theme toggling
The application is built using a modern stack with AI agents at its core:
┌─────────────────────────────────────────────────────────────┐
│ Next.js Frontend │
│ (React 19, TypeScript, Tailwind CSS, shadcn/ui) │
└───────────────────┬─────────────────────────────────────────┘
│
┌───────────────────┴─────────────────────────────────────────┐
│ API Routes Layer │
│ (/api/chat, /api/policies, /api/upload-pdf, etc.) │
└───────────────────┬─────────────────────────────────────────┘
│
┌───────────┴───────────┐
│ │
┌───────┴────────┐ ┌────────┴─────────┐
│ Lyzr AI │ │ MongoDB │
│ Agents │ │ (Prisma) │
│ │ │ │
│ • Chat Agent │ │ • Users │
│ • Perplexity │ │ • Policies │
│ • Compliance │ │ • Sessions │
│ • Law Updates │ └───────────────────┘
└────────────────┘
- Node.js 18+
- npm, yarn, pnpm, or bun
- MongoDB database
- Lyzr AI API key (Get one here)
- Clone the repository
git clone https://github.com/amitlyzr/policy-generation-app.git
cd policy-generation-app- Install dependencies
npm install
# or
yarn install
# or
pnpm install- Set up environment variables
Create a .env.local file in the root directory:
# Database
DATABASE_URL="your_mongodb_connection_string"
# Lyzr AI Configuration
LYZR_API_KEY="your_lyzr_api_key"
# Agent IDs (obtain from Lyzr dashboard)
NEXT_PUBLIC_CHAT_AGENT_ID="your_chat_agent_id"
NEXT_PUBLIC_PERPLEXITY_AGENT_ID="your_perplexity_agent_id"
NEXT_PUBLIC_COMPLIANCE_AGENT_ID="your_compliance_agent_id"
NEXT_PUBLIC_LAW_AGENT_ID="your_law_agent_id"Note
You can find a template in .env.example. Copy it and fill in your values.
- Set up the database
npx prisma generate
npx prisma db push- Run the development server
npm run dev
# or
yarn dev
# or
pnpm devOpen http://localhost:3000 to see the application.
- Navigate to Create New Policy from the sidebar
- Start a conversation with the AI agent about the policy you need
- Specify the policy type (e.g., Remote Work, PTO, Code of Conduct)
- Select applicable countries for compliance
- Review and refine the generated policy through conversation
- Save the policy to your database
- Go to Upload Policy section
- Drag and drop or select a PDF file
- Add a policy name and select applicable countries
- The system will parse and convert the PDF to editable markdown format
- Review and save to your policy database
- Navigate to Compliance Test section
- Select a policy from your database
- Describe the changes needed or compliance requirements
- The AI will analyze and suggest updates
- Review changes and save new version
- Access Policy Database to view all policies
- Filter by status, country, or search by name
- View, edit, or archive policies as needed
- Track version history and status changes
- Next.js 15.5 - React framework with App Router
- React 19 - UI library
- TypeScript - Type safety
- Tailwind CSS 4 - Utility-first CSS
- shadcn/ui - Component library
- Radix UI - Unstyled accessible components
- Lyzr AI SDK - Multi-agent orchestration
- Tiptap - Rich text editor
- pdf2md - PDF parsing
- Marked - Markdown processing
- Streamdown - Streaming markdown renderer
- Prisma - Database ORM
- MongoDB - Document database
- Next.js API Routes - Backend API
- Zustand - Lightweight state management
- Lyzr Auth - Authentication provider
- js-cookie - Cookie management
policy-generation-agent/
├── prisma/
│ └── schema.prisma # Database schema
├── public/ # Static assets
├── src/
│ ├── app/
│ │ ├── api/ # API routes
│ │ │ ├── chat/ # Chat agent endpoint
│ │ │ ├── policies/ # Policy CRUD operations
│ │ │ ├── upload-pdf/ # PDF processing
│ │ │ └── research-policy/ # Research agent endpoint
│ │ ├── create-policy/ # Policy creation page
│ │ ├── update-policy/ # Policy update page
│ │ ├── upload-policy/ # Policy upload page
│ │ ├── policy-db/ # Policy database page
│ │ ├── layout.tsx # Root layout
│ │ └── page.tsx # Dashboard
│ ├── components/
│ │ ├── custom/ # Custom components
│ │ │ ├── policy-conversation.tsx
│ │ │ ├── policy-database.tsx
│ │ │ ├── policy-uploader.tsx
│ │ │ └── ...
│ │ ├── providers/ # Context providers
│ │ └── ui/ # Reusable UI components
│ ├── lib/
│ │ ├── lyzr.ts # Lyzr AI integration
│ │ ├── prisma.ts # Prisma client
│ │ ├── file-utils.ts # File processing utilities
│ │ └── utils.ts # General utilities
│ └── stores/
│ └── policy-store.ts # Zustand state management
├── .env.example # Environment variables template
├── package.json
└── README.md
POST /api/chat
{
"message": "Create a remote work policy",
"sessionId": "session_xyz",
"agentId": "chat_agent_id",
"userId": "user_123"
}// Get all policies for a user
GET /api/policies?userId=user_123
// Create new policy
POST /api/policies
{
"name": "Remote Work Policy",
"content": "...",
"countries": ["United States", "Canada"],
"userId": "user_123"
}
// Update policy
PUT /api/policies?policyId=policy_123
// Delete policy
DELETE /api/policies?policyId=policy_123POST /api/upload-pdf
Content-Type: multipart/form-data
{
"file": <PDF file>,
"userId": "user_123"
}The application uses multiple specialized AI agents:
- Chat Agent - Main conversational interface for policy generation
- Perplexity Agent - Real-time research for legal and compliance information
- Compliance Agent - Validates policies against regulatory requirements
- Law Agent - Provides updates on legal changes and requirements
Configure these agents in the Lyzr dashboard and add their IDs to your environment variables.
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
userId String @unique
orgId String
policies Policy[]
}
model Policy {
id String @id @default(auto()) @map("_id") @db.ObjectId
policyId String @unique
name String
content String
countries String[]
status PolicyStatus @default(DRAFT)
version Int @default(1)
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id])
}
enum PolicyStatus {
DRAFT
IN_REVIEW
APPROVED
PUBLISHED
ARCHIVED
}npm testnpm run build
npm startnpm run lintThe easiest way to deploy is using Vercel:
- Push your code to GitHub
- Import project to Vercel
- Add environment variables
- Deploy
The application can be deployed to any platform that supports Next.js:
- AWS Amplify
- Netlify
- Railway
- DigitalOcean App Platform
Ensure environment variables are properly configured in your deployment platform.
Database Connection Errors
- Verify your
DATABASE_URLis correctly formatted - Ensure MongoDB is accessible from your deployment environment
- Run
npx prisma generateafter schema changes
AI Agent Errors
- Verify your
LYZR_API_KEYis valid - Check that all agent IDs are correctly configured
- Ensure you have sufficient credits in your Lyzr account
PDF Upload Issues
- Check file size (max 10MB by default)
- Verify PDF is not password-protected
- Ensure proper file permissions
- 📧 Email: support@lyzr.ai
- 📅 Book a Demo
- 💬 GitHub Discussions
- 🐛 Report Issues
- Built with Lyzr AI
- UI components from shadcn/ui
- Icons from Tabler Icons
Empowering organizations with AI-driven HR policy management
