# Agentic HR Chatbot (Google Chat)

> An internal HR assistant in Google Chat for leave requests, policy questions, employee lookups, daily announcements, and document management.

Status: Internal tool · Tags: LangGraph, LangChain, TypeScript, Google Chat, PII redaction

## Overview

I built an HR assistant that works directly inside Google Chat, giving colleagues a way to handle common HR requests without switching between different tools.

It can answer questions about company policies, file and cancel leave requests, look up employee information, check leave schedules, send daily announcements, and manage shared document links.

The tool is currently used by a small group of colleagues within the organization.

It supports two operating modes: cloud-based inference using Groq, Gemini, and local Ollama as a fallback, or a fully local setup using Ollama. Both modes use the same agent workflow, tools, guardrails, and data handling. Only the model provider changes.

The chatbot also shares its data model with the internal HR portal, keeping employee records, projects, and leave information consistent between the two.

## The problem

HR requests and employee information were already available through an internal HR web application, but accessing them meant navigating to the portal and handling each request there. I wanted to make these services more accessible by bringing common HR workflows directly into Google Chat, where colleagues already communicate every day.

Since these workflows involve sensitive employee information, integrating an AI assistant also meant addressing how that data is handled. The goal was to provide a convenient chat-based interface to existing HR services without exposing sensitive employee records to third-party AI providers.

## Implementation

### Agent and tools

Built a ReAct agent using LangGraph with 15 tools validated through Zod.

The tools cover:
- Filing and cancelling leave requests
- Viewing leave history and employee availability
- Checking who's on leave for a specific date or month
- Looking up employee information and project assignments
- Retrieving headcount and leave statistics
- Checking holidays and HR policies
- Viewing scheduled job status
- Finding and saving shared document links

### PII redaction

One of the main parts of the implementation was handling sensitive employee information before it reaches an AI provider.

Employee data retrieved from the database — including names, email addresses, phone numbers, departments, job titles, employment statuses, and leave dates — is replaced with tokens such as `«NAME_1»` and `«EMAIL_1»`.

The original values are restored on the server after the model responds.

A token registry is maintained per conversation, allowing the same employee or value to retain its token across follow-up messages. This keeps conversations consistent without exposing the underlying information to the model.

User-provided text is not automatically redacted, so the protection specifically applies to database-derived information.

### Identity and access

The authenticated user's identity is resolved from their email address on the server and injected into the tools when they are initialized.

The model does not get to choose or provide a `userId`. This prevents it from acting on behalf of another employee by generating or modifying identity parameters.

### Guardrails and validation

Security checks happen before requests reach the model.

- Prompt-injection attempts are handled through deterministic checks before provider calls.
- Tool arguments are validated using Zod.
- A recursion limit prevents the agent from getting stuck in repeated tool calls.

### Model providers and failover

The chatbot supports multiple model providers.

In cloud mode, requests follow this order:
1. Groq
2. Google Gemini
3. Local Ollama

In local mode, requests go directly to Ollama.

Providers without configured API keys are skipped. If all available providers fail, the API returns a `503` response with the failure reason rather than silently failing.

### Scheduled HR announcements

Daily cron jobs run at 8:00 AM in the company's timezone.

They handle:
- Daily HR announcements
- Holiday reminders
- Employee birthdays
- Work anniversaries

The `/status` endpoint keeps a record of individual job executions, making it easier to check whether a particular task ran successfully.

Announcement content is generated using the same provider chain. The expected output is a validated JSON object, with individual fields falling back to predefined templates when generation fails. This way, a provider outage does not prevent an announcement from being sent.

### Leave management

Employees can submit or cancel leave requests directly through Google Chat.

Requests are saved through Prisma, followed by an approval card sent to Google Chat and an email notification to HR.

### Document registry

Added a document registry for locating and saving shared resources, including Google Docs, Sheets, Slides, Drive, and Notion links.

New links go through a preview-and-confirm step before being saved. Document ownership is assigned using the authenticated user's email rather than information supplied by the model.

### Tracing and debugging

Integrated optional LangSmith tracing to inspect agent execution, tool calls, and model interactions.

Tracing receives the same redacted payloads used by the model providers. Input and output collection can also be disabled entirely when needed.

## Tech stack

- **Backend:** TypeScript, Express
- **Database:** MySQL, Prisma
- **Agent framework:** LangChain.js, LangGraph.js
- **AI providers:** Groq, Google Gemini, Ollama
- **Integration:** Google Chat
- **Scheduling:** Cron
- **Observability:** LangSmith

## Outcome

The chatbot is currently being used internally by a small group of colleagues. It has not been rolled out company-wide.

The project established a working approach for using LLMs with sensitive HR data without sending database-derived personal information to external providers.

I also added smoke tests covering all agent tools, RAG, security refusals, PII redaction, token consistency across multiple conversation turns, and read-only cron status.

## What I learned

Working with sensitive data changes how an AI agent needs to be designed. Redaction cannot simply be added as a final step before sending a prompt. It affects how data flows between the database, tools, agent, and model and how responses are handled afterward.

I also found that having multiple providers is only part of making an agent reliable. Validation, predictable failure handling, and fallback behavior are just as important. A system should still behave sensibly when a model is unavailable or returns something unexpected.

Finally, tracing is important when working with agentic systems. Being able to inspect what the agent does, which tools it calls, and how it reaches a result makes debugging much easier, especially when the workflows involve employee records.

---

Source: https://jayetan.github.io/work/agentic-hr-chatbot/
