Skip to content

feat: Add Frappe CRM, Helpdesk, Raven, and ERPNext agent integration tools#277

Draft
esafwan wants to merge 6 commits into
developfrom
feature/frappe-app-integration-tools
Draft

feat: Add Frappe CRM, Helpdesk, Raven, and ERPNext agent integration tools#277
esafwan wants to merge 6 commits into
developfrom
feature/frappe-app-integration-tools

Conversation

@esafwan
Copy link
Copy Markdown
Contributor

@esafwan esafwan commented May 28, 2026

Summary

Adds agent tools for Frappe apps installed on the same site (Frappe CRM, Helpdesk, Raven, ERPNext). New tools use direct Frappe DocType and report APIs—no external HTTP clients or per-integration credentials. They are registered in the integration tool registry and seeded on install/migrate via existing sync paths.

This branch builds on core communication and developer tools already merged to develop in PR #273. Those 18 tools are unchanged. This PR adds 8 consolidated Frappe/ERPNext tools, for 26 integration tools total.

Motivation

Agents need first-class access to business data and workflows inside the Frappe/ERPNext stack: CRM pipelines, helpdesk tickets, internal chat, accounting, inventory, and standard reports. External API wrappers would duplicate auth, add latency, and complicate deployment. In-process Frappe calls reuse site permissions, installed apps, and DocType APIs.

Design

Action-based dispatcher (new tools only)

Each new module exposes a single registry entry with a required action parameter. handle_action(**kwargs) routes to private _handle_* implementations. Business logic is unchanged from the initial per-operation implementation; only the public surface and registry shape were consolidated.

Benefits:

  • Fewer tool definitions for the LLM to choose among
  • Shared parameter schema per domain (e.g. all CRM lead operations on one tool)
  • Easier extension: add an action and dispatch entry without a new registry row per operation

In-process Frappe integration

  • No httpx or OAuth tokens for these tools
  • Each module checks frappe.get_installed_apps() and returns a structured JSON error if the target app is missing
  • Responses use json.dumps({"success": bool, ...}) for consistent agent parsing
  • Errors are logged via frappe.log_error with a short tool label

Reports: catalogue plus generic runner

Instead of one tool per report, ERPNext reporting is exposed as:

  • erpnext_list_reports — discover reports by module (90+ entries across 9 modules)
  • erpnext_run_report — run any script/query report via frappe.desk.query_report.run with a filters dict

Read-only; no document side effects.

Scope boundary with develop

An intermediate commit refactored Slack, Discord, Telegram, GitHub, and recipient tools into the same action pattern. That was reverted: those files match develop exactly. Consolidation applies only to tools introduced in this branch.

Tool inventory

Unchanged from develop (18 tools)

Category Tools
Communication Tools get_integration_recipient, 6× Slack, 4× Discord, 1× Telegram
Developer Tools 6× GitHub

New in this PR (8 tools)

Tool name Module Category Actions / behavior
frappe_crm crm.py Frappe CRM Tools 11 actions: leads, deals, notes, tasks, contacts
helpdesk helpdesk.py Helpdesk Tools 8 actions: tickets, comments, agents, teams, assignment
raven raven.py Raven Tools 6 actions: messages, channels, members, search
erpnext erpnext.py ERPNext Tools 14 actions: sales/purchase invoices, payments, customers, quotations, RFQs, GL ledger, journal entries
erpnext_crm erpnext_crm.py ERPNext CRM Tools 7 actions: ERPNext Lead/Opportunity lifecycle (distinct from standalone Frappe CRM)
erpnext_inventory erpnext_inventory.py ERPNext Inventory 12 actions: items, prices, BOM, stock balance/movements, warehouses, delivery notes, purchase receipts
erpnext_run_report erpnext_reports.py ERPNext Reports Run any catalogued report by name + filters
erpnext_list_reports erpnext_reports.py ERPNext Reports List reports by module or full catalogue

Frappe CRM vs ERPNext CRM: Standalone Frappe CRM uses CRM Lead / CRM Deal doctypes (frappe_crm). ERPNext built-in CRM uses Lead / Opportunity (erpnext_crm). Categories and tool names are separated so agents do not conflate the two.

Files changed

File Change
huf/ai/tools/crm.py New — Frappe CRM
huf/ai/tools/helpdesk.py New — Frappe Helpdesk
huf/ai/tools/raven.py New — Frappe Raven
huf/ai/tools/erpnext.py New — ERPNext financials/transactions
huf/ai/tools/erpnext_crm.py New — ERPNext CRM doctypes
huf/ai/tools/erpnext_inventory.py New — ERPNext inventory/BOM/stock
huf/ai/tools/erpnext_reports.py New — report catalogue + runners
huf/ai/tools/_registry.py New tool definitions, categories, ALL_INTEGRATION_TOOLS
huf/install.py Minor — ensures integration tool categories sync on install

Approx. +3,096 lines across 9 files (net of registry edits).

Agent Tool Type categories

New categories created/synced on migrate:

  • Frappe CRM Tools
  • Helpdesk Tools
  • Raven Tools
  • ERPNext Tools
  • ERPNext CRM Tools
  • ERPNext Inventory
  • ERPNext Reports

Existing Communication Tools and Developer Tools categories are unchanged.

Prerequisites

Tool group Requires
frappe_crm crm in installed apps
helpdesk helpdesk in installed apps
raven raven in installed apps
erpnext, erpnext_crm, erpnext_inventory, erpnext_*_report erpnext in installed apps

Agents should call tools only when the corresponding app is installed; missing apps return {"success": false, "error": "... not installed"}.

Out of scope

  • No changes to Slack, Discord, Telegram, GitHub, or recipient tool implementations (identical to develop)
  • Memory architecture docs were added in an intermediate commit and reverted; not included in this PR
  • No frontend/UI changes
  • No new external env vars for Frappe app tools (unlike Slack/GitHub tools on develop)

Test plan

  • Fresh migrate on a site with HUF installed; confirm 26 integration tools appear in Agent Tool sync and correct categories exist
  • Site without crm / helpdesk / raven / erpnext: each respective tool returns a clear not-installed error
  • Frappe CRM (frappe_crm): list_leads, create_lead, update_lead, list_deals, add_note, add_task
  • Helpdesk (helpdesk): create_ticket, get_ticket, add_comment, assign_ticket
  • Raven (raven): list_channels, send_message, get_messages (if Raven configured)
  • ERPNext (erpnext): list_customers, get_ledger, list_sales_invoices (read paths)
  • ERPNext CRM (erpnext_crm): list_leads, create_opportunity — verify doctypes are ERPNext Lead/Opportunity, not FCRM
  • ERPNext inventory (erpnext_inventory): list_items, stock_balance
  • Reports: erpnext_list_reports with module=Accounts; erpnext_run_report with Balance Sheet and valid company / date filters
  • Assign new tools to a test agent; run a multi-step prompt (e.g. create helpdesk ticket, add comment, resolve)
  • Confirm existing Slack/GitHub tools on the same agent still work as before (regression check vs develop behavior)

esafwan added 6 commits May 27, 2026 04:54
Adds three new internal Frappe app tool modules with full CRUD and
business-automation coverage:

- huf/ai/tools/crm.py: 10 tools for Frappe CRM — lead/deal lifecycle
  (get, create, update), notes, tasks, and contact lookup
- huf/ai/tools/helpdesk.py: 8 tools for Frappe Helpdesk — ticket
  management, comments, agent/team listing, and assignment
- huf/ai/tools/raven.py: 6 tools for Frappe Raven — send/search messages,
  list/create channels, channel membership

All tools use direct Frappe API calls (no httpx/credentials) and guard
against the app not being installed. Registry and install seeding updated.
Adds 5 new tool modules covering broad ERPNext business automation:

erpnext.py (14 tools — ERPNext Tools category):
  Sales/Purchase Invoices, Payment Entry, Quotation, Customer CRUD,
  Account Ledger (GL queries), Journal Entry creation, RFQ listing

erpnext_crm.py (7 tools — ERPNext CRM Tools category):
  ERPNext-native CRM: Lead and Opportunity lifecycle (get/create/update).
  Differentiated from standalone Frappe CRM (CRM Lead / CRM Deal)
  by doctype names, tool prefix (erpnext_crm_*), and category label.

erpnext_inventory.py (12 tools — ERPNext Inventory category):
  Item/Item Price lookup, BOM get/create, real-time Stock Balance
  (SLE dedup), Stock Movements, Stock Entries, Warehouses,
  Delivery Notes, Purchase Receipts

erpnext_reports.py (14 tools — ERPNext Reports category):
  Balance Sheet, P&L, Trial Balance, General Ledger,
  Accounts Receivable/Payable, Bank Reconciliation,
  Sales Register, Sales Order Analysis, Customer Acquisition,
  Stock Balance, Stock Ledger, Item-wise Sales, Gross Profit
  All via frappe.desk.query_report.run — read-only, no side effects.

Registry updated to 89 tools across 9 categories. Frappe CRM tools
renamed category to "Frappe CRM Tools" to distinguish from ERPNext CRM.
All files AST-validated clean.
Three new documentation files covering the full memory architecture:

- docs/SCOPED_MEMORY_KNOWLEDGE_BRIDGE_RFC.md — Updated RFC reflecting current
  state: three live backends (sqlite_fts, sqlite_vec, chroma), Phase 1 implemented
  via PR #275, phases 2–5 defined with learning profiles and learning agents

- docs/memory/zero-to-hero.md — Full onboarding doc capturing intellectual
  provenance (Agno/Hindsight/Mem0 references), how existing knowledge backends
  work, the three-layer architecture, what exists today vs what is planned,
  key files, design decisions and their reasons, glossary

- docs/memory/phase-plan.md — Per-phase delivery plan with definition of done,
  file-level targets, cross-cutting concerns (security, testing, backward compat)
Replaces one-tool-per-operation pattern with an action-dispatcher pattern.
Each tool file exposes a single handle_action(**kwargs) that routes via an
'action' kwarg. Internal logic is unchanged — only renamed to _handle_*.

Tool count: 89 → 13
  slack           (6 actions: send_message, reply_thread, list_channels, ...)
  discord         (4 actions: send_message, get_messages, list_channels, ...)
  telegram        (1 action:  send_message)
  github          (6 actions: list_repos, get_repo, create_issue, ...)
  get_recipient   (utility, unchanged)
  frappe_crm      (11 actions: leads + deals + notes + tasks + contacts)
  helpdesk        (8 actions: tickets + comments + agents + teams)
  raven           (6 actions: messages + channels + members)
  erpnext         (14 actions: invoices + payments + customers + ledger + ...)
  erpnext_crm     (7 actions: leads + opportunities)
  erpnext_inventory (12 actions: items + BOM + stock + warehouses + ...)
  erpnext_run_report   — run any ERPNext report by name + filters dict
  erpnext_list_reports — discover ~90 reports across 9 modules

erpnext_reports.py replaced with a REPORT_CATALOGUE covering 90+ reports
across Accounts, Selling, Buying, Stock, Manufacturing, CRM, Helpdesk,
Projects and HR — all accessible via two generic tools instead of 14+
individual ones.
…s only

Slack, Discord, Telegram, GitHub and recipient tools were already merged to
develop (PR #273) and should not be refactored in this branch.

Reverted to develop-identical state:
  huf/ai/tools/slack.py
  huf/ai/tools/discord.py
  huf/ai/tools/telegram.py
  huf/ai/tools/github.py
  huf/ai/tools/recipient.py

Registry now has 26 tools:
  18 from develop (unchanged) — individual slack_*/discord_*/github_* tools
   8 new (consolidated)       — frappe_crm, helpdesk, raven, erpnext,
                                 erpnext_crm, erpnext_inventory,
                                 erpnext_run_report, erpnext_list_reports
@esafwan esafwan changed the title feat: frappe app integration tools feat: Add Frappe CRM, Helpdesk, Raven, and ERPNext agent integration tools May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant