Industrial copilots fail when every query goes through one generic prompt. A robust design uses specialized modes and agents coordinated by a central router.
Four-Layer Copilot Pattern
- Intent Router: classify query into direct response, retrieval, workflow, or deep investigation.
- Tool Registry: unified catalog of built-in tools, external connectors, and workflow tools.
- Planner: generate an execution plan with dependency-aware parallel groups.
- Executor: dispatch tools, stream traces, aggregate evidence, summarize actions.
Routing Skeleton
async function route(query, context) {
if (context.forceMode) return { mode: context.forceMode };
const cls = await classifyQuery(query, context); // LLM or rules+LLM
// modes: direct_llm | rag_qa | workflow | agent | deep_agent
return cls;
}
Dynamic Tool Registry
class ToolRegistry {
constructor() {
this.tools = new Map();
this.categories = new Map();
}
register(tool) {
this.tools.set(tool.name, tool);
if (!this.categories.has(tool.category)) this.categories.set(tool.category, []);
this.categories.get(tool.category).push(tool.name);
}
getToolRegistryForLLM() {
return [...this.categories.entries()].map(([cat, names]) => ({
category: cat,
tools: names.map(n => this.tools.get(n))
}));
}
}
Planner Output Contract
{
"goal": "Investigate process drift and propose corrective actions",
"steps": [
{"id": 1, "tool": "query_digital_twin", "parallel_group": 1},
{"id": 2, "tool": "query_process_runs", "parallel_group": 1},
{"id": 3, "tool": "query_maintenance_history", "parallel_group": 1},
{"id": 4, "tool": "search_documents", "parallel_group": 1},
{"id": 5, "tool": "summarize", "parallel_group": 2}
]
}
Parallel Executor Pattern
async function executePlan(plan, context, runTool) {
const grouped = groupBy(plan.steps, s => s.parallel_group || 1);
const results = [];
for (const groupId of Object.keys(grouped).sort((a,b) => Number(a)-Number(b))) {
const groupResults = await Promise.all(
grouped[groupId].map(async step => ({
stepId: step.id,
tool: step.tool,
result: await runTool(step.tool, step.parameters || {}, context)
}))
);
results.push(...groupResults);
}
return results;
}
Traceability and UI Feedback
- Emit
step_start,step_complete, andtool_resultevents. - Store raw tool outputs for tables/charts.
- Persist final reasoning to a decision trace store for future precedent search.
Design Rules That Keep It Reliable
- Prefer deterministic handlers for high-risk operations.
- Use LLM planning, but keep guarded fallback plans.
- Constrain database access to allowlisted tables and schemas.
- Always synthesize with explicit evidence sections and actionable next steps.
If you implement these four layers, your copilot becomes more than chat: it becomes a multi-agent execution system that can investigate, explain, and improve operations with auditable outputs.
