Architecture
Each agent follows the same pattern: purpose-built fetchers pull data from Airtable and PostgreSQL in parallel, a service layer computes the business logic, and an Express web server renders the results. AI augments the pipeline — Claude writes narratives, validates confidence, and generates recommendations.
Self-hosted, not platform-managed. Unlike hosted AI platforms (Google ADK, CrewAI), EFI's agents run on the application server. ERP data never passes through third-party orchestration — only specific prompt data is sent to model APIs. Cost: ~$0.03–0.50 per agent run.
The Four Agents
Market Research
The primary EFI application server (port 3000). Hosts the AI market report pipeline (3-pass Claude + Gemini), trade intelligence dashboards (Datamyne BOL data), calculators (Milk ROI, Fat Blending, Product Database), supplier intel email poller, and a mobile PWA. Separate customer insights server on port 3001.
Sourcing Intelligence
Demand planning with product × month gap matrix, AI-powered sourcing recommendations with capacity scenarios and PDF export, HiGHS LP cost optimizer with 7 what-if scenarios, supplier pipeline and capacity heatmap analytics, forecast audit (11 issue types), and daily digest email.
Pricing Optimization
Linear programming model (HiGHS solver) that maximizes margin across the product portfolio subject to supply, demand, inventory, and capacity constraints.
Trade Intelligence
Competitive intelligence from US maritime import records. Importer and supplier rankings,
port-level trade flows, HS code classification analysis, AI entity resolution and brand discovery,
plus calculators (Milk Pricing & ROI, Fat Blending, Product Database).
Embedded in the Market Research server at /trade-intel/*.
Monorepo Structure
AGENTS_mono/ ├── packages/ │ ├── shared/ # @efi/shared — DB clients, models, types │ ├── market-research/ # Customer insights — fetchers, AI pipeline, web │ ├── sourcing/ # Gap dashboard — demand/supply/inventory analysis │ ├── pricing/ # Pricing optimizer — LP model, scenario runner │ ├── trade-intel/ # Competitive intelligence — Datamyne BOL analysis │ ├── data-api/ # Centralized REST API — 27 endpoints, 6 route groups │ └── data-platform/ # This site — static HTML documentation ├── docs/ # Technical guides and architecture docs └── .env # Shared environment variables
Shared Infrastructure
- Airtable CRM client — lazy-init, queryTable with formula builder
- PostgreSQL ERP client — pool with SSL/DigitalOcean compat
- Anthropic Claude client — singleton, configurable model
- Data API client — typed REST client for all 28 endpoints
- Datamyne API client — singleton with 24hr cache, rate-limit protection
- Product name normalization — fuzzy match across systems
Build System
- npm workspaces + TypeScript project references
tsc -bbuilds all packages in dependency order- Each agent has its own Express server on a separate port
- Shared
.envat monorepo root viadotenv/config
Data Sources
Airtable CRM
| Table | Used By |
|---|---|
| Customers | Market Research |
| Sales Orders | Market Research, Sourcing |
| Contract Line Items | Market Research, Sourcing |
| Sales Rep Forecasts | Sourcing |
| Inventory Availability | Sourcing |
| Warehouses | Sourcing |
| Products | Market Research |
PostgreSQL ERP
| Table | Used By |
|---|---|
| supplier_purchase_orders | Market Research, Sourcing |
| products | All agents |
| ref_sales_months | Market Research, Sourcing |
| ref_otw_transit_times | Market Research |
| ref_landed_cost_estimates | Market Research |
| ref_efi_ports | Market Research, Sourcing |
External APIs
| Source | Cache | Purpose |
|---|---|---|
| Datamyne US Maritime Imports (idApp 44) | 24h | BOL records, importer/supplier totals, entity resolution |
| Datamyne US Import Census (idApp 127) | 24h | FOB pricing by country and month |
| USDA MPR DataMart (report 2991) | 30d | Dairy component prices (butterfat, protein, Class III/IV) |