Building an n8n multi-agent inventory workflow starts with a hard problem: different categories of questions require fundamentally different capabilities, and trying to handle them with one AI prompt produces a system that handles none of them reliably.
"How many units of this SKU do we have?" requires an exact database query. "Has this SKU been selling faster recently?" requires statistical reasoning over historical records. "Is demand for this category likely to increase next month?" requires data that is not in your database at all.
Attempting to answer all three with a single LLM prompt creates a system that fails on each. The model will try to answer trend questions using only the inventory data in its context. It will hallucinate table names or column references it was not given. It will generate confident-sounding analysis based on incomplete information.
For Stock Mate, PixelPlot's AI-powered inventory system, we structured the solution around an Intent Classifier that routes each query to a specialized agent. The orchestration runs in n8n, with Groq handling the LLM calls and Supabase as the database.
When an LLM is given a single, broad prompt covering multiple capabilities, its failure modes are difficult to predict and harder to debug. A SQL generation failure looks the same as a trend analysis failure. A hallucinated column name and an incomplete market analysis produce equally wrong outputs, but they require different fixes.
Decomposing the system into agents with narrow responsibilities changes this. A SQL Agent can fail in identifiable ways. If it generates a query referencing a column that does not exist, that is debuggable. If the External Trend Agent receives no Google Trends data from SerpAPI, it can return a qualified "insufficient data" response rather than inventing an analysis.
The architecture PixelPlot deployed for Stock Mate uses three agents:
The Intent Classifier sits before all three agents and determines which one should handle the request. For Stock Mate, this is implemented as a Function node in n8n combined with a lightweight Groq call for ambiguous queries.
// Simplified n8n Function node for intent classification
const query = $input.item.json.query || '';
const lower = query.toLowerCase();
const externalSignals = ['forecast', 'market', 'trend', 'demand', 'popular', 'seasonal'];
const internalSignals = ['velocity', 'history', 'past sales', 'last week', 'rate of'];
let intent = 'SQL_QUERY'; // Default to exact data retrieval
if (externalSignals.some(kw => lower.includes(kw))) {
intent = 'EXTERNAL_TREND';
} else if (internalSignals.some(kw => lower.includes(kw))) {
intent = 'INNER_TREND';
}
return [{ json: { original_query: query, intent } }];Keyword matching alone fails on queries like "Will we run out of this item?" which signals an inner trend question without using explicit keywords. The n8n workflow escalates ambiguous queries to a Groq call with a structured JSON output schema and a system prompt defining the three intent categories.
The SQL Agent receives only the database schema definition in its system prompt, not live data. It generates a SQL SELECT statement, which is validated in a Function node before execution against Supabase.
The database credential n8n uses for this agent is read-only. This is a non-negotiable constraint, not a performance optimization. An LLM generating SQL is not a trusted input. Restricting it to read-only access at the database level means that even if the model generates a destructive statement, the database rejects it.
The Inner Trend Agent feeds into a conditional node in n8n. If calculated sales velocity exceeds available stock by a defined threshold, an n8n Gmail node generates a structured reorder request to the relevant vendor, as described in the Stock Mate case study.
This conditional logic is implemented as a deterministic Function node with explicit numeric thresholds, not as an LLM decision. Letting a language model decide whether to trigger an email that places a real purchase order introduces unnecessary and unauditable risk.
SerpAPI returns Google Trends data as structured results, but the relevance of those results depends heavily on how the query is phrased. A slightly different search term returns a different dataset. The External Trend Agent's system prompt instructs the Groq model to include a confidence field in its JSON output, set to "low" when the trend data is thin or ambiguous.
The n8n workflow handles low-confidence responses by routing to a different output path, one that explicitly tells the user the trend data was insufficient rather than presenting a confident but weakly supported analysis.
n8n provides a visual execution trace, credential management, built-in retry logic for failed API calls, and a webhook interface without writing HTTP server code. For a workflow that spans three different external services (Groq, Supabase, and SerpAPI), the visual canvas makes it practical to trace exactly where a failure occurred without reading raw application logs.
The tradeoff is that n8n's default execution mode is synchronous. For high-concurrency deployments with many simultaneous users, queue mode with a Redis broker and dedicated worker instances is required. For the internal tooling use case Stock Mate was built for, default mode handles the load adequately.
For more on how PixelPlot approaches AI automation and workflow engineering, the services page covers the full scope.
n8n handles credential management, API retry logic, webhook routing, and execution monitoring out of the box. For multi-service workflows where observability and maintainability matter, the visual canvas reduces operational complexity.
Two layers: the system prompt restricts output to SELECT statements, and the database credentials used by n8n are read-only at the database level. The database will reject any write operations regardless of what the LLM generates.
The External Trend Agent's LLM receives an empty result set and is instructed to return confidence: "low" in its structured output. The n8n workflow routes low-confidence responses to a fallback message rather than presenting them as analysis.
In n8n's default mode, workflow executions are synchronous. For concurrent usage beyond a small team, enabling queue mode with a Redis broker and multiple worker processes is the correct configuration.