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.
The Payroll Agent follows your intended workflow:
- Document Upload โ User uploads payroll documents (PDF, images)
- VLM Processing โ Converts documents to VLM-friendly format
- Text + Position Extraction โ VLM extracts text with spatial awareness
- ReAct Agent Processing โ Groq LLM processes VLM results
- Interactive Editing โ User can chat to modify payroll data
- Export Results โ Final JSON/CSV output
- 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
- 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
- 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
- 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
-
Clone the repository:
git clone <repository-url> cd react-agent
-
Install dependencies:
pip install -e . -
Set up environment variables:
cp .env.example .env
-
Configure API keys in your
.envfile:# Required for VLM processing OPENAI_API_KEY=your-openai-api-key # Required for text reasoning GROQ_API_KEY=your-groq-api-key
- Sign up at OpenAI
- Create an API key
- Add to
.env:OPENAI_API_KEY=your-key
- Sign up at Groq Console
- Create an API key
- Add to
.env:GROQ_API_KEY=your-key
streamlit run streamlit_app.py- Upload Document: Drag and drop payroll documents
- VLM Processing: Automatic text and position extraction
- Interactive Editing: Chat to modify payroll data
- Export Results: Download JSON or CSV
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)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: {...}"
"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]"
"Add employee [name] with $[rate]/hour""Remove employee [name]""Add overtime hours for [name]"
"Calculate net pay for all employees""Calculate gross pay for [name]""Update all deductions to [amount]"
"Export final data""Finalize""Get JSON"
Run the test suite:
python test_debug.pyThis tests:
- VLM processing workflow
- Interactive editing functionality
- State management
- Export capabilities
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
- User uploads payroll document via Streamlit
- File saved to temp directory
- Document metadata extracted
- 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
- Groq Llama processes VLM results
- Structures data into employee payroll objects
- Handles user requests for modifications
- Continues conversation until user exports
- Natural language parsing of modification requests
- Real-time updates to payroll data
- State persistence across conversation
- Validation and error handling
- JSON format with complete payroll data
- CSV export for spreadsheet compatibility
- Timestamp and metadata inclusion
# Default models (configurable)
text_model = "llama-3.1-8b-instant" # Groq for reasoning
vision_model = "gpt-4o-mini" # OpenAI for VLMmax_file_size = 10 * 1024 * 1024 # 10MB
max_pages = 10 # PDF page limit
supported_formats = ['.pdf', '.png', '.jpg', '.jpeg']- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the test suite:
python test_debug.py - Review logs in the terminal
- Ensure API keys are correctly configured
- Verify document formats are supported
- Start the Streamlit app:
streamlit run streamlit_app.py - Upload a payroll document
- Watch the VLM processing
- Chat to edit payroll data
- Export your results
The system is ready for production use with your increased OpenAI quota!
