Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

18 Commits

Folders and files

Repository files navigation

๐Ÿ“Š Payroll Document Parsing Agent

CI Integration Tests

An intelligent payroll document parsing agent that combines Vision Language Models (VLM) with ReAct reasoning patterns to extract, analyze, and interactively edit payroll information from documents.

Graph view in LangGraph studio UI

๐ŸŽฏ What it does

The Payroll Agent follows your intended workflow:

  1. Document Upload โ†’ User uploads payroll documents (PDF, images)
  2. VLM Processing โ†’ Converts documents to VLM-friendly format
  3. Text + Position Extraction โ†’ VLM extracts text with spatial awareness
  4. ReAct Agent Processing โ†’ Groq LLM processes VLM results
  5. Interactive Editing โ†’ User can chat to modify payroll data
  6. Export Results โ†’ Final JSON/CSV output

๐Ÿš€ Key Features

๐Ÿ“„ Document Processing

  • Multi-format support: PDF, PNG, JPEG, and more
  • VLM-powered extraction: Uses OpenAI GPT-4o-mini for vision analysis
  • Spatial awareness: Extracts text with position context
  • Automatic conversion: PDF โ†’ PNG for optimal VLM processing

๐Ÿ’ฌ Interactive Chat-Based Editing

  • Natural language modifications: "Update Alice's pay rate to $25/hour"
  • Real-time updates: Changes reflected immediately
  • Continuous conversation: Keep chatting until satisfied
  • Smart parsing: Handles complex payroll requests

๐Ÿง  Dual Model Architecture

  • Vision Model: OpenAI GPT-4o-mini for document analysis
  • Text Model: Groq Llama-3.1-8b-instant for reasoning and edits
  • Fallback strategy: Text-based processing if VLM fails

๐Ÿ“Š Data Management

  • Structured extraction: Employee ID, name, pay rate, hours, deductions, etc.
  • Automatic calculations: Net pay = gross pay - deductions
  • Export options: JSON and CSV formats
  • State persistence: All changes maintained in conversation

๐Ÿ› ๏ธ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd react-agent
  2. Install dependencies:

    pip install -e .
  3. Set up environment variables:

    cp .env.example .env
  4. Configure API keys in your .env file:

    # Required for VLM processing
    OPENAI_API_KEY=your-openai-api-key
    
    # Required for text reasoning
    GROQ_API_KEY=your-groq-api-key

๐Ÿ“‹ API Key Setup

OpenAI (Vision Processing)

  1. Sign up at OpenAI
  2. Create an API key
  3. Add to .env: OPENAI_API_KEY=your-key

Groq (Text Processing)

  1. Sign up at Groq Console
  2. Create an API key
  3. Add to .env: GROQ_API_KEY=your-key

๐ŸŽฎ Usage

Option 1: Streamlit Interface (Recommended)

streamlit run streamlit_app.py
  1. Upload Document: Drag and drop payroll documents
  2. VLM Processing: Automatic text and position extraction
  3. Interactive Editing: Chat to modify payroll data
  4. Export Results: Download JSON or CSV

Option 2: Direct API Usage

from src.react_agent.state import State
from src.react_agent.graph import graph
from langchain_core.messages import HumanMessage

# Create state with uploaded document
state = State(
    document_uploaded=True,
    file_path="payroll_document.pdf",
    messages=[HumanMessage(content="Process this payroll document")]
)

# Run the agent
result = await graph.ainvoke(state)

๐Ÿ’ฌ Interactive Editing Examples

After VLM processing, you can chat to modify payroll data:

๐Ÿค– "Here's your extracted payroll data..."

๐Ÿ‘ค "Update Alice's pay rate to $25/hour"
๐Ÿค– "โœ… Updated Alice's pay rate to $25.00/hour"

๐Ÿ‘ค "Add employee David with $30/hour rate, worked 40 hours"
๐Ÿค– "โœ… Added employee David with $30.00/hour rate, 40 hours worked"

๐Ÿ‘ค "Change Clara's deductions to $150"
๐Ÿค– "โœ… Changed Clara's deductions to $150.00"

๐Ÿ‘ค "Calculate net pay for all employees"
๐Ÿค– "โœ… Calculated net pay for all employees"

๐Ÿ‘ค "Export final data"
๐Ÿค– "โœ… Here's your final JSON: {...}"

๐Ÿ”ง Supported Commands

Employee Modifications

  • "Update [name]'s pay rate to $[amount]"
  • "Set [name]'s employee ID to [id]"
  • "Change [name]'s deductions to $[amount]"
  • "Fix [name]'s hours to [hours]"

Employee Management

  • "Add employee [name] with $[rate]/hour"
  • "Remove employee [name]"
  • "Add overtime hours for [name]"

Calculations

  • "Calculate net pay for all employees"
  • "Calculate gross pay for [name]"
  • "Update all deductions to [amount]"

Export

  • "Export final data"
  • "Finalize"
  • "Get JSON"

๐Ÿงช Testing

Run the test suite:

python test_debug.py

This tests:

  • VLM processing workflow
  • Interactive editing functionality
  • State management
  • Export capabilities

๐Ÿ“ Project Structure

react-agent/
โ”œโ”€โ”€ src/react_agent/
โ”‚   โ”œโ”€โ”€ configuration.py    # Model and processing configuration
โ”‚   โ”œโ”€โ”€ state.py           # State management with Pydantic models
โ”‚   โ”œโ”€โ”€ graph.py           # LangGraph workflow definition
โ”‚   โ”œโ”€โ”€ tools.py           # VLM processing and document handling
โ”‚   โ”œโ”€โ”€ prompts.py         # System prompts for payroll processing
โ”‚   โ””โ”€โ”€ utils.py           # Utility functions
โ”œโ”€โ”€ streamlit_app.py       # Web interface
โ”œโ”€โ”€ test_debug.py          # Test suite
โ””โ”€โ”€ README.md              # This file

๐ŸŽฏ Workflow Details

1. Document Upload

  • User uploads payroll document via Streamlit
  • File saved to temp directory
  • Document metadata extracted

2. VLM Processing Node

  • Document converted to VLM-friendly PNG format
  • OpenAI GPT-4o-mini analyzes document images
  • Extracts text with spatial position awareness
  • Fallback to text-based processing if VLM fails

3. ReAct Agent Node

  • Groq Llama processes VLM results
  • Structures data into employee payroll objects
  • Handles user requests for modifications
  • Continues conversation until user exports

4. Interactive Editing

  • Natural language parsing of modification requests
  • Real-time updates to payroll data
  • State persistence across conversation
  • Validation and error handling

5. Export & Finalization

  • JSON format with complete payroll data
  • CSV export for spreadsheet compatibility
  • Timestamp and metadata inclusion

๐Ÿ”ง Configuration

Model Configuration

# Default models (configurable)
text_model = "llama-3.1-8b-instant"      # Groq for reasoning
vision_model = "gpt-4o-mini"             # OpenAI for VLM

Processing Limits

max_file_size = 10 * 1024 * 1024  # 10MB
max_pages = 10                     # PDF page limit
supported_formats = ['.pdf', '.png', '.jpg', '.jpeg']

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

For issues and questions:

  1. Check the test suite: python test_debug.py
  2. Review logs in the terminal
  3. Ensure API keys are correctly configured
  4. Verify document formats are supported

๐ŸŽ‰ Next Steps

  1. Start the Streamlit app: streamlit run streamlit_app.py
  2. Upload a payroll document
  3. Watch the VLM processing
  4. Chat to edit payroll data
  5. Export your results

The system is ready for production use with your increased OpenAI quota!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages