Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.heylua.ai/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Internal HR assistant integrating with BambooHR API for employee management and Lua Data API for company policies and documents. What it does:
  • Look up employee information
  • Request time off
  • Search HR policies
  • Onboard new employees
  • Answer benefits questions
APIs used: BambooHR API (external) + Lua Data API (policies)

Complete Implementation

src/index.ts

import { LuaAgent, LuaSkill, LuaJob } from "lua-cli";
import {
  SearchPoliciesTool,
  GetEmployeeInfoTool,
  RequestTimeOffTool
} from "./tools/HRTools";

// HR skill
const hrSkill = new LuaSkill({
  name: "hr-operations",
  description: "Internal HR operations and employee services",
  context: `
    This skill helps employees with HR-related requests.
    
    - search_policies: Search company policies and procedures
    - get_employee_info: Look up employee information
    - request_time_off: Submit time off requests
    
    Always be helpful and professional.
    Ensure confidentiality of employee information.
  `,
  tools: [
    new SearchPoliciesTool(),
    new GetEmployeeInfoTool(),
    new RequestTimeOffTool()
  ]
});

// Daily attendance report job
const attendanceReportJob = new LuaJob({
  name: 'daily-attendance-report',
  description: 'Send daily attendance summary',
  schedule: {
    type: 'cron',
    pattern: '0 17 * * 1-5'  // Every weekday at 5 PM
  },
  execute: async (job) => {
    const user = await job.user();
    await user.send([{
      type: 'text',
      text: '📊 Daily attendance report is ready. All employees accounted for.'
    }]);
  }
});

// Configure agent (v3.0.0)
export const agent = new LuaAgent({
  name: "hr-operations-assistant",
  
  persona: `You are a professional and helpful HR assistant.
  
Your role:
- Help employees find HR policies and procedures
- Look up employee information
- Process time off requests
- Answer benefits and payroll questions
- Guide through HR processes

Communication style:
- Professional and friendly
- Confidential and trustworthy
- Clear and helpful
- Empathetic and supportive

Best practices:
- Maintain confidentiality of employee information
- Provide accurate policy information
- Direct employees to appropriate resources
- Confirm details before processing requests
- Follow company HR policies strictly

When to escalate:
- Sensitive employee relations issues
- Compensation discussions
- Disciplinary matters
- Legal or compliance questions`,

  
  skills: [hrSkill],
  jobs: [attendanceReportJob]
});
v3.0.0 Features: This demo uses LuaAgent with scheduled jobs for daily attendance reports.

src/tools/HRTools.ts

import { LuaTool, Data, env } from "lua-cli";
import { z } from "zod";

// 1. Search HR Policies (Lua Vector Search)
export class SearchPoliciesTool implements LuaTool {
  name = "search_policies";
  description = "Search company HR policies and procedures";
  
  inputSchema = z.object({
    query: z.string().describe("Policy question or keyword")
  });

  async execute(input: z.infer<typeof this.inputSchema>) {
    const results = await Data.search('hr_policies', input.query, 5, 0.7);
    
    return {
      policies: results.map(entry => ({
        title: entry.title,
        summary: entry.content.substring(0, 200) + '...',
        category: entry.category,
        lastUpdated: entry.updatedAt,
        relevance: `${Math.round(entry.score * 100)}%`
      })),
      count: results.length
    };
  }
}

// 2. Get Employee Info (BambooHR External API)
export class GetEmployeeInfoTool implements LuaTool {
  name = "get_employee_info";
  description = "Look up employee information";
  
  inputSchema = z.object({
    employeeId: z.string()
  });

  async execute(input: z.infer<typeof this.inputSchema>) {
    const bambooApiKey = env('BAMBOOHR_API_KEY');
    const bambooSubdomain = env('BAMBOOHR_SUBDOMAIN');
    
    const response = await fetch(
      `https://api.bamboohr.com/api/gateway.php/${bambooSubdomain}/v1/employees/${input.employeeId}`,
      {
        headers: {
          'Authorization': `Basic ${Buffer.from(bambooApiKey + ':x').toString('base64')}`,
          'Accept': 'application/json'
        }
      }
    );
    
    if (!response.ok) {
      throw new Error('Employee not found');
    }
    
    const employee = await response.json();
    
    return {
      employeeId: employee.id,
      name: `${employee.firstName} ${employee.lastName}`,
      department: employee.department,
      jobTitle: employee.jobTitle,
      hireDate: employee.hireDate,
      manager: employee.supervisor,
      workEmail: employee.workEmail
    };
  }
}

// 3. Request Time Off (BambooHR External API)
export class RequestTimeOffTool implements LuaTool {
  name = "request_time_off";
  description = "Submit a time off request";
  
  inputSchema = z.object({
    employeeId: z.string(),
    startDate: z.string(),
    endDate: z.string(),
    timeOffType: z.enum(['vacation', 'sick', 'personal']),
    notes: z.string().optional()
  });

  async execute(input: z.infer<typeof this.inputSchema>) {
    const bambooApiKey = env('BAMBOOHR_API_KEY');
    const bambooSubdomain = env('BAMBOOHR_SUBDOMAIN');
    
    const response = await fetch(
      `https://api.bamboohr.com/api/gateway.php/${bambooSubdomain}/v1/employees/${input.employeeId}/time_off/request`,
      {
        method: 'POST',
        headers: {
          'Authorization': `Basic ${Buffer.from(bambooApiKey + ':x').toString('base64')}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          start: input.startDate,
          end: input.endDate,
          timeOffTypeId: input.timeOffType,
          notes: input.notes
        })
      }
    );
    
    const data = await response.json();
    
    return {
      success: true,
      requestId: data.id,
      status: 'pending_approval',
      message: "Time off request submitted. You'll be notified when approved."
    };
  }
}

Environment Setup

# .env
BAMBOOHR_API_KEY=your_bamboohr_api_key
BAMBOOHR_SUBDOMAIN=your_company

Key Features

External HRIS

BambooHR integration

Vector Search

Policy semantic search