Overview

Enterprise supply chain operations generate both structured data (orders, inventory, shipments) and unstructured knowledge (contracts, reports, policies). Teams need to query across both data types naturally.

Architecture

The system uses a state graph with four specialized nodes:

Router Agent

Classifies incoming queries into categories: structured data questions, document questions, hybrid questions, or general queries. Uses few-shot prompting with examples from each category.

SQL Agent

Translates natural language to SQL using schema-aware prompting. Includes query validation, execution against SQLite, and result formatting. Handles joins across multiple supply chain tables (suppliers, products, orders, shipments).

RAG Agent

Performs hybrid retrieval using ChromaDB vector search combined with keyword filtering. Documents are chunked with overlap and embedded at ingestion time. Retrieves relevant chunks and generates grounded answers with source citations.

Summarizer Agent

Aggregates outputs when a query requires information from both structured and unstructured sources. Produces a coherent response that synthesizes SQL results with document excerpts.

Technical Details

class AgentState(TypedDict):
    query: str
    route: str
    sql_result: Optional[str]
    rag_result: Optional[str]
    final_answer: str
    sources: List[str]

The state graph ensures clean data flow between agents. Each agent reads from and writes to specific state keys, preventing unintended interactions.

Results

  • Query routing accuracy: 92%
  • SQL generation accuracy: 85% on test queries
  • End-to-end response time: 2.1s average
  • Supports 50+ concurrent users via FastAPI async handlers