Docs/Architecture/AI Copilot

Architecture

AI Copilot

How the tenant-safe assistant uses agentic retrieval, tenant-scoped context, and swappable LLM backends.

What it is

EasyFlow's copilot is a tenant-scoped retrieval assistant for supply chain operations. It is designed to answer questions about shipments, inventory, approvals, suppliers, and workflow exceptions using only the current tenant's operational context.

✦The copilot is designed around a provider abstraction. EasyFlow can run in a fully local agentic mode through Ollama, or use hosted backends such as OpenAI or Gemini while keeping the same tenant-scoped response contract.

Agentic architecture

Agentic AI in EasyFlow means the assistant does more than autocomplete a generic answer. It gathers tenant context, inspects operational records, and produces an answer grounded in current business data.

ModeHow it worksBest fit
Local agentic modeLangChain agent + tenant MCP tools + Ollama modelSelf-hosted demos, on-prem deployments, strict data residency
Hosted grounded modeOpenAI or Gemini provider + tenant-scoped document contextTeams that want managed models without rewriting the app
Heuristic fallbackDeterministic local logic over the same tenant datasetSafe demo fallback when no model backend is available

Tenant-safe retrieval

  • The assistant receives the current tenant slug from the workspace route or request payload.
  • Tenant data is loaded only for that tenant workspace.
  • Operational records are transformed into tenant-scoped knowledge documents.
  • A tenant-scoped MCP server is created in-process for that request only.
  • LangChain loads only that MCP server's tools, so the model can query only the current tenant context.
  • If a signed-in user is tenant-scoped in the registry, the route refuses cross-tenant access.

Current data sources

Until live ERP-side data is fully wired everywhere, the copilot uses the same tenant-specific operational structures already powering the app UI.

SourceUsed for
Inventory dataLow-stock, reorder, SKU, and restock questions
Procurement dataPurchase order status and approval questions
Logistics dataShipment delay, ETA, and carrier questions
Supplier dataLead-time, fill-rate, and supplier risk questions
Automation / integration dataWorkflow trigger and integration status questions
Tenant KPIsOverview, exception, and operational health questions

LLM backends

EasyFlow now supports multiple backend styles through the same provider interface. The local Ollama path is the most agentic because it can reason through tenant MCP tools directly. Hosted OpenAI and Gemini paths use the same tenant-scoped knowledge documents and return the same structured assistant payload.

text
User question
   ↓
Tenant-aware API route
   ↓
Tenant-scoped knowledge documents
   ↓
Provider registry
   ↓
Ollama: LangChain + MCP tools
OpenAI / Gemini: grounded context prompt
   ↓
Grounded answer + citations

The default local path uses ChatOllama through LangChain. The hosted-provider path is designed so teams can point EasyFlow at OpenAI or Gemini later without changing the API contract or UI.

bash
# Example local setup
ollama serve
ollama pull llama3.1:8b

Environment variables

env
AI_PROVIDER=heuristic
LOCAL_LLM_ENABLED=false
LOCAL_LLM_BASE_URL=http://127.0.0.1:11434
LOCAL_LLM_MODEL=llama3.1:8b
LOCAL_EMBEDDING_MODEL=nomic-embed-text
OPENAI_API_KEY=
OPENAI_MODEL=gpt-4.1-mini
OPENAI_BASE_URL=https://api.openai.com/v1/responses
GEMINI_API_KEY=
GEMINI_MODEL=gemini-2.5-flash

Set AI_PROVIDER to ollama, openai, gemini, or heuristic. If no provider is configured, EasyFlow falls back to deterministic tenant-grounded logic instead of failing closed.

Current limitations

  • The current retrieval layer is lexical and tenant-scoped, not vector-search based yet.
  • The MCP tool layer currently exposes local tenant knowledge documents rather than live ERP-backed indexed stores everywhere.
  • The hosted-provider paths are grounded in tenant documents today, but the deeper agentic tool loop currently exists only in the local Ollama + MCP mode.
  • Production-quality prompt and model tuning still depend on the deployment environment you choose.