mm.
Back to Portfolio
Agentic AIOpen SourceIndustrial

AER Industrial Compliance Agent

Autonomous AI agent for AER industrial compliance — 7-tool LangChain orchestration over real Alberta Energy Regulator directives. Replaces a 2-hour manual audit with a 30-second autonomous workflow.

View on GitHub
240×
Faster than manual audit
7
Orchestrated tools
<30s
Complete audit time
2,653
Indexed RAG chunks
01

Overview

Traditional RAG systems answer questions. This agent performs work. The shift from passive knowledge retrieval to active operational execution is what makes this genuinely useful in an industrial compliance context.

A compliance officer doesn't just need answers about AER directives — they need the audit done, the report sent, the follow-up scheduled, and the maintenance logged. That's what this agent does: it receives a plain-English instruction and autonomously orchestrates 7 tools to complete the full workflow.

02

RAG vs. Autonomous Agent

AspectTraditional RAGAutonomous Agent
RolePassive Q&AActive task execution
User input"Tell me about X""Audit X and handle it"
Tools1 — vector search7+ — search, DB, email, calendar, logs
Decision makingUser-drivenAI-driven, autonomous
Actions takenNone — just respondsEmail, schedule, log, report
03

Agent Architecture

The agent receives a goal, reasons about it using GPT-4o function calling, selects tools, processes results, and iterates until the goal is achieved. No hardcoded decision trees.

class AERComplianceAgent:
    def __init__(self, api_key: str, model: str = "gpt-4o"):
        self.llm = ChatOpenAI(
            model=model,
            temperature=0,       # Deterministic — critical for compliance
            api_key=api_key
        )
        self.agent = create_tool_calling_agent(
            self.llm,
            audit_tools,         # 7 available tools
            self.prompt          # Custom system prompt for AER context
        )
        self.agent_executor = AgentExecutor(
            agent=self.agent,
            tools=audit_tools,
            verbose=True,        # Full tool call transparency
            max_iterations=15,   # Cost cap — prevents runaway execution
            handle_parsing_errors=True
        )

7 Available Tools

search_aer_directivesget_facility_equipmentcheck_calibration_compliancesend_compliance_reportschedule_follow_uplog_maintenance_actionlist_facilities
04

End-to-End Workflow

Instruction

"Audit facility FAC-AB-001 for Directive 017 compliance and email results to safety@example.com"

01
Knowledge retrievalCalls search_aer_directives → Retrieves 365-day calibration requirement from ChromaDB
02
Data collectionCalls get_facility_equipment → Fetches 4 equipment items with calibration dates
03
Compliance analysisCalls check_calibration_compliance → Identifies 2 items overdue (400 and 380 days)
04
Report distributionCalls send_compliance_report → Emails full report with specific equipment IDs
05
Follow-up planningCalls schedule_follow_up → Creates calendar entry, returns confirmation ID
06
DocumentationCalls log_maintenance_action ×2 → Creates maintenance entry per violation

Complete compliance audit in under 30 seconds with 6 tool invocations. Zero manual intervention.

05

Results

MetricManualWith Agent
Complete audit time2+ hours< 30 seconds
Manual steps10–15 steps0 — fully autonomous
Report generationManual compilationAuto-generated and emailed
Follow-up schedulingManual calendar entryAutomatic with confirmation ID
ConsistencyVaries by analystDeterministic execution
06

Engineering Learnings

Function calling is the unlock for agents

The agent makes autonomous decisions about tool sequencing. This is fundamentally different from hard-coded logic or simple RAG retrieval, and the difference is not subtle in practice.

Tool descriptions are the interface

Clear, detailed docstrings directly determine agent performance. The LLM reads these descriptions to decide which tool to invoke — ambiguous descriptions cause wrong selection more reliably than any other failure mode.

Temperature 0 is mandatory for compliance

Regulatory domains require deterministic behaviour. Temperature 0 ensures consistent tool selection and prevents creative but incorrect responses.

Pydantic schemas prevent silent failures

When LLMs generate function inputs, validation catches errors before execution. Silent failures in compliance workflows are unacceptable.

07

Stack & Quick Start

Agent: LangChain 0.3.13 · LangChain-OpenAI 0.2.14 · GPT-4o · Pydantic 2.0
RAG: ChromaDB 0.4.22 · OpenAI Embeddings (text-embedding-3-small)
UI: Gradio 6.0 · Custom CSS · WCAG 2.1 AA
Other: Python 3.9+ · pdfplumber · python-dotenv
PythonLangChainGPT-4oChromaDBRAGPydantic 2.0Gradio 6.0
git clone https://github.com/morteza-mogharrab/aer-compliance-agent.git
cd aer-compliance-agent
python3 -m venv venv && source venv/bin/activate
pip install -r requirements_agent.txt
export OPENAI_API_KEY='your-key-here'
python3 agent_app.py   # Web interface → localhost:7860