A production-grade prototype demonstrating ReAct + Safety-Critical Human-in-the-Loop (HITL) architecture for Oil & Gas operations. Built for a Data & Digital Executive to showcase on LinkedIn.
This prototype showcases five architectural capabilities that boards and operators care about in 2025:
- Agentic Reasoning - Not a chatbot; a state machine that plans, executes, and reflects
- Symbolic Wrapping - The LLM never executes directly; it selects from pre-verified read-only tools
- Safety by Design - Deterministic risk classification with human sovereignty over recommendations
- Observability First - Every decision is logged in an immutable audit trail
- Graceful Degradation - Works offline without API keys (heuristic mode), upgrades with LLM
User Query -> Perception (Intent/Entity Extraction) -> Planner (Tool Selection)
-> Executor (Read-Only Tools) -> Synthesis (Evidence Correlation)
-> Safety Critic (Risk Classification) -> [HITL Gate if Orange/Red] -> Response
| Node | Purpose | Key Feature |
|---|---|---|
perception |
Parse intent, extract entities (asset tag, metric, timeframe) | Keyword + LLM fallback |
planner |
Generate step-by-step tool calling plan | Max 3 steps, tool schemas enforced |
executor |
Call read-only tools deterministically | Never executes raw SQL/Python |
synthesis |
Correlate findings into coherent response | Offline heuristic mode + LLM mode |
safety_critic |
Classify risk: Green/Yellow/Orange/Red | Keyword + alert-based heuristics |
hitl_gate |
Pause for human approval on Orange/Red | Checkpoint ID, pause/resume via MemorySaver |
final_response |
Format with risk badge, citations, audit stamp | Immutable audit trail |
| Level | Trigger | HITL Required |
|---|---|---|
| Green | Factual retrieval only | No |
| Yellow | General guidance, warnings | No |
| Orange | Operational recommendations, sensor anomalies | Yes - Synchronous approval |
| Red | Safety-critical, emergency, "do not operate" | Yes + Secondary review |
| Tool | Function | Safety |
|---|---|---|
search_manuals |
Search O&M manuals, API standards, troubleshooting guides | Read-only document retrieval |
query_sensor |
Query time-series sensor data with anomaly detection | Read-only, synthetic data for demo |
og_copilot/
├── app.py # Streamlit UI (chat + approval card + audit log)
├── requirements.txt
├── README.md
├── app/
│ ├── __init__.py
│ ├── config.py # Safety thresholds, asset registry, LLM config
│ ├── agent/
│ │ ├── __init__.py
│ │ ├── state.py # TypedDict AgentState definition
│ │ ├── tools.py # 2 read-only tools + in-memory knowledge base
│ │ ├── nodes.py # 7 node functions for the ReAct + Safety loop
│ │ └── graph.py # LangGraph state machine compilation
│ └── data/
│ ├── __init__.py
│ └── init_knowledge_base.py # ChromaDB initialization script
Set your API key (supports OpenAI or OpenRouter):
export OPENAI_API_KEY="your-key-here"
# OR for OpenRouter
export OPEN_ROUTER_API_KEY="your-key-here"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
export LLM_MODEL="openai/gpt-4o-mini"The prototype works fully without any API key. The agent uses deterministic heuristics for:
- Intent classification (keyword-based)
- Tool plan generation (rule-based fallback)
- Risk classification (keyword + sensor alert analysis)
- Response synthesis (structured formatting of tool outputs)
cd og_copilot
pip install -r requirements.txt
python -m streamlit run app.pyThen open http://localhost:8501 in your browser.
The sidebar includes one-click demo queries:
- "Why did Compressor A trip last night?" -> Triggers document search for trip investigation procedures (Yellow risk)
- "What's the current bearing temperature for COMP-A-001?" -> Triggers sensor query with CRITICAL alert (Orange risk -> HITL approval card)
- "Draft a shift handover note for Compressor A" -> Combines document search + sensor data (Orange risk -> HITL approval card)
When the safety critic classifies a response as Orange or Red:
- Agent status changes from ACTIVE to PAUSED
- An approval card appears with evidence summary, proposed action, and risk rationale
- Chat input is disabled until operator approves or rejects
- Full audit trail captures the decision
Every event is logged:
- User queries
- HITL triggers (with checkpoint ID)
- Operator approvals/rejections
- Agent completions with risk classification
Three synthetic assets with realistic baselines:
- COMP-A-001: Main Process Compressor (72C baseline, 3.2 mm/s vibration)
- COMP-B-002: Refrigeration Compressor (65C baseline, 4.5 mm/s vibration)
- PUMP-X-101: Injection Pump (55C baseline, 2.8 mm/s vibration)
Based on API 570 and industry standards:
- Bearing temperature max: 85C (warning), 95C (critical), 100C (emergency shutdown)
- Vibration max: 7 mm/s (warning), 11 mm/s (critical)
- Baseline deviation: 15% triggers investigation
When writing your article, emphasize these architectural decisions:
- "It's not RAG, it's a state machine" - The ReAct loop shows planning, not just prompting
- "Symbolic wrapping, not prompt engineering" - LLM selects tools; deterministic code executes them
- "Safety is the architecture, not a feature" - HITL is wired into the graph, not bolted on
- "Works offline, scales with API" - Heuristic mode proves functionality without vendor lock-in
- "Every decision is auditable" - Immutable logs for regulatory compliance (OGMP 2.0, EPA)
To add more tools:
- Define a new
StructuredToolinapp/agent/tools.py - Add it to the
TOOLSregistry - Update the planner system prompt in
app/agent/nodes.py - Add safety guardrails in the critic if needed
To connect to real SCADA:
- Replace
query_sensorimplementation with actual Historian/PI System queries - Keep the same interface; the agent doesn't need changes
| Layer | Technology |
|---|---|
| Orchestration | LangGraph (StateGraph + MemorySaver) |
| LLM | GPT-4o Mini via OpenRouter (optional, lazy init) |
| Embeddings | sentence-transformers/all-MiniLM-L6-v2 (fallback: keyword scoring) |
| Vector Store | In-memory (ChromaDB-ready for scale) |
| UI | Streamlit with custom CSS |
| Data | Synthetic time-series with deterministic anomaly injection |
Built for demonstration purposes. The architecture is designed to scale to production with ChromaDB + SCADA historian integration + enterprise auth.