An intelligent AI-powered chat assistant for ERPNext that uses LangChain and OpenAI GPT-4 to help users query and interact with their ERP data using natural language.
- π£οΈ Natural Language Queries - Ask questions in plain English
- π€ Voice Recognition - Speak your queries instead of typing! (NEW!)
- π§ 7 Specialized Tools - Query customers, items, sales orders, purchase orders, stock, and more
- π§ Context-Aware - Remembers conversation history for multi-turn dialogues
- π Permission-Based - Respects ERPNext user permissions
- π¬ Real-Time Chat UI - Integrated directly into ERPNext navbar
- π Session Management - Create, save, and manage chat sessions
- π― Agentic AI - Automatically selects and executes the right tools
- ERPNext 15.x or later
- Python 3.10+
- OpenAI API key (Get one here)
-
Get the app:
cd /path/to/your/bench bench get-app https://github.com/barathprathosh/erpnext_ai_chat.git -
Install on your site:
bench --site your-site install-app erpnext_ai_chat
-
Install dependencies:
bench pip install langchain langchain-openai langchain-community chromadb openai tiktoken
-
Configure API Key:
- Go to: Setup β AI Chat Settings
- Enter your OpenAI API key
- Click Save
-
Restart bench:
bench restart
-
Start chatting!
- Click the "AI Assistant" button in the navbar
- Type or click π€ to use voice input
- Ask: "Show me pending sales orders"
Click the microphone button and speak, or type your queries:
"Show me pending sales orders"
"Get sales orders for customer ABC Corp"
"Find completed orders from last week"
"Search for customer Tech Solutions"
"Get details for customer CUST-00001"
"Find all customers in California"
"Check stock balance for ITEM-001"
"What's the available quantity in Main Warehouse?"
"Show me items with low stock"
"Show pending purchase orders"
"Get POs from supplier XYZ"
"Find recent purchase orders"
User Query β Chat UI β API β AI Agent β LangChain β Tools β ERPNext Data
β
OpenAI GPT-4
β
Natural Language Response
- AI Agent - Orchestrates conversation flow using LangChain
- 7 Specialized Tools - Query different ERPNext doctypes
- Memory Manager - Maintains conversation context
- REST API - 6 endpoints for chat operations
- Chat UI - Modern interface integrated into ERPNext
- Quick Start Guide - Get started in 5 minutes
- Setup Guide - Detailed installation and configuration
- Voice Feature Guide - Using voice recognition (NEW!)
- Project Structure - Technical architecture and code organization
| Tool | Description | Example |
|---|---|---|
search_customers |
Find customers by name | "Search for customer ABC" |
get_customer_details |
Get detailed customer info | "Show details for CUST-001" |
search_items |
Find products/items | "Search for laptop items" |
get_sales_orders |
Fetch sales orders | "Show pending sales orders" |
get_purchase_orders |
Fetch purchase orders | "Show purchase orders from supplier X" |
get_stock_balance |
Check inventory levels | "Check stock for ITEM-001" |
search_doctype |
Generic doctype search | "Find all draft quotations" |
# Send a message
POST /api/method/erpnext_ai_chat.api.chat.send_message
{
"message": "Show me pending sales orders",
"session_id": "optional-session-id"
}
# Get chat history
GET /api/method/erpnext_ai_chat.api.chat.get_chat_history?session_id=AICS-0001
# Get all sessions
GET /api/method/erpnext_ai_chat.api.chat.get_sessions
# Create new session
POST /api/method/erpnext_ai_chat.api.chat.create_new_session
# Clear history
POST /api/method/erpnext_ai_chat.api.chat.clear_chat_history
# Delete session
POST /api/method/erpnext_ai_chat.api.chat.delete_sessionUses OpenAI's API with affordable pricing:
| Model | Cost per Query | Recommended For |
|---|---|---|
| gpt-4o-mini (default) | ~$0.0001 | Daily use (very cheap!) |
| gpt-4o | ~$0.01 | Complex queries |
Example: 100 queries/day with gpt-4o-mini = ~$3/month
- β Respects ERPNext permissions
- β API key stored encrypted
- β All queries logged
- β No direct database access
- β User-based session isolation
- Customer Service - Quickly find customer information
- Sales Operations - Monitor orders and pipelines
- Inventory Management - Check stock levels instantly
- Procurement - Track purchase orders
- General Queries - Ask anything about your ERP data
# In erpnext_ai_chat/ai_agent/tools.py
from langchain.tools import tool
import frappe
@tool
def get_invoices(status: str = None, limit: int = 10) -> str:
"""Get sales invoices with optional status filter"""
invoices = frappe.get_all(
"Sales Invoice",
filters={"status": status} if status else {},
fields=["name", "customer", "grand_total"],
limit=limit
)
result = f"Found {len(invoices)} invoice(s):\n"
for inv in invoices:
result += f"- {inv.name}: {inv.customer} (${inv.grand_total})\n"
return result
# Add to get_erpnext_tools() function
def get_erpnext_tools(user=None):
return [
# ... existing tools ...
get_invoices # Your new tool
]Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details
- Built with LangChain
- Powered by OpenAI GPT-4
- For Frappe ERPNext
- π Documentation
- π Issue Tracker
- π¬ Discussions
If you find this project useful, please consider giving it a star on GitHub!
Made with β€οΈ for the ERPNext community