Skip to main content
Glama
Abinash009

iso26262-agent

by Abinash009
README.md
# iso26262-agent

**AI-powered ISO 26262 Functional Safety Agent for Automotive**

An MCP (Model Context Protocol) server that provides AI-assisted functional safety engineering tools for automotive ECU development. Generates HARA, FMEA, safety requirements, and compliance checks using RAG + LLM β€” grounded in ISO 26262 standards.

Built for engineers working on safety-critical systems: inverters, motor controllers, TCUs, ADAS, autonomous drive platforms, and battery management systems.

---

## 🎯 What It Does

| Tool | Input | Output |
|------|-------|--------|
| **HARA Generator** | System/function description | Hazard events + ASIL classification (A/B/C/D) |
| **FMEA Generator** | Component description | Full FMEA table (Failure Mode, S, O, D, RPN, Actions) |
| **Safety Requirements** | Function + ASIL level | ISO 26262-compliant FSR/TSR/SWSR requirements |
| **Compliance Checker** | Your existing requirements | Gap analysis vs ISO 26262 with clause references |

---

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              MCP Client (IDE/CLI)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚ MCP Protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           iso26262-agent (MCP Server)        β”‚
β”‚                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  HARA   β”‚ β”‚  FMEA   β”‚ β”‚ Requirements β”‚  β”‚
β”‚  β”‚Generatorβ”‚ β”‚Generatorβ”‚ β”‚  Generator   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β”‚            β”‚             β”‚           β”‚
β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚         RAG Pipeline                    β”‚ β”‚
β”‚  β”‚  Query β†’ Embed β†’ Search β†’ Context      β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                   β”‚                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚         LLM (Gemini API)               β”‚ β”‚
β”‚  β”‚  Context + Prompt β†’ Structured Output  β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          Knowledge Base (194 chunks)         β”‚
β”‚                                              β”‚
β”‚  β€’ ISO 26262 Parts 1-12 concepts            β”‚
β”‚  β€’ ASIL determination tables (S/E/C β†’ ASIL) β”‚
β”‚  β€’ Automotive failure mode patterns          β”‚
β”‚  β€’ Safety requirement templates              β”‚
β”‚  β€’ HARA methodology & examples              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ› οΈ Tech Stack

- **Python 3.11+**
- **MCP Protocol** β€” Model Context Protocol server (standardized AI tool interface)
- **Gemini API** β€” LLM for reasoning and generation
- **RAG Pipeline** β€” Semantic embeddings + vector search (with TF-IDF fallback)
- **Pydantic** β€” Structured data models and validation
- **Rich** β€” Formatted CLI output

---

## πŸš€ Quick Start

### 1. Clone & Install

```bash
git clone https://github.com/Abinash009/iso26262-agent.git
cd iso26262-agent
pip install -r requirements.txt
```

### 2. Set API Key

```bash
export GOOGLE_API_KEY=your_gemini_api_key_here
```

Or create a `.env` file:
```
GOOGLE_API_KEY=your_key_here
```

### 3. Run Demo

```bash
python3 demo.py
```

This runs all 3 tools with example automotive inputs and shows formatted output.

### 4. Run as MCP Server

```bash
python3 src/server.py
```

---

## πŸ“‹ Usage Examples

### HARA Generator

```
Input: "Torque control function in traction inverter for electric truck"

Output:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
β”‚ Hazard                                                       β”‚ ASIL β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€
β”‚ Unintended forward over-torque while vehicle is stationary   β”‚ D    β”‚
β”‚ Unintended excessive negative torque (regen braking)         β”‚ C    β”‚
β”‚ Sudden total loss of drive torque during overtaking           β”‚ B    β”‚
β”‚ Unintended reverse torque while forward gear engaged         β”‚ D    β”‚
β”‚ Unintended forward motion when reverse gear engaged          β”‚ A    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜
```

### FMEA Generator

```
Input: "DC-DC converter 800V to 12V for auxiliary systems"

Output:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Failure Mode                          β”‚ S β”‚ O β”‚ D β”‚ RPN β”‚ Recommended Action       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ HV to LV Isolation Breakdown          β”‚10 β”‚ 2 β”‚ 4 β”‚ 80  β”‚ Reinforced galvanic iso  β”‚
β”‚ Loss of Output (Zero Voltage)         β”‚ 9 β”‚ 4 β”‚ 3 β”‚ 108 β”‚ Dual 12V output paths    β”‚
β”‚ Uncontrolled Output Overvoltage       β”‚ 8 β”‚ 3 β”‚ 2 β”‚ 48  β”‚ Redundant OV protection  β”‚
β”‚ Shoot-Through (High/Low Side)         β”‚ 8 β”‚ 3 β”‚ 2 β”‚ 48  β”‚ HW-enforced dead-time    β”‚
β”‚ Excessive Junction Temperature        β”‚ 6 β”‚ 4 β”‚ 2 β”‚ 48  β”‚ Dual NTC sensors         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Safety Requirements Generator

```
Input: function="Emergency braking torque delivery", ASIL=D

Output:
[FSR-001] [FSR] The system shall prevent unintended emergency braking torque delivery
[FSR-002] [FSR] The system shall deliver requested torque within specified time
[FSR-003] [FSR] The system shall maintain symmetrical braking torque delivery
[TSR-001] [TSR] Dual-channel cross-validation of torque demand signals
[TSR-002] [TSR] Dual independent power supply for hydraulic actuation
[TSR-003] [TSR] Redundant pressure sensors for left/right monitoring
```

---

## πŸ“ Project Structure

```
iso26262-agent/
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ demo.py                      # Quick demo script (run this!)
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py              # Package initialization
β”‚   β”œβ”€β”€ server.py                # MCP protocol server + CLI
β”‚   β”œβ”€β”€ tools.py                 # 4 safety tools + SafetyAgent class
β”‚   β”œβ”€β”€ rag.py                   # RAG pipeline (embeddings + search)
β”‚   └── models.py                # Pydantic data models
β”œβ”€β”€ knowledge_base/
β”‚   β”œβ”€β”€ asil_determination.md    # ASIL classification tables
β”‚   β”œβ”€β”€ failure_modes_automotive.md  # ECU failure mode patterns
β”‚   β”œβ”€β”€ hara_methodology.md      # HARA process & examples
β”‚   β”œβ”€β”€ iso26262_overview.md     # ISO 26262 Parts 1-12 summary
β”‚   └── safety_requirements_patterns.md  # Requirement templates
β”œβ”€β”€ tests/
β”‚   └── test_tools.py            # Unit tests
└── docs/
```

---

## πŸ”‘ Key Design Decisions

| Decision | Rationale |
|----------|-----------|
| MCP Protocol | Standardized AI tool interface β€” works with any MCP client |
| RAG over fine-tuning | Updatable knowledge base, no retraining needed, source traceability |
| TF-IDF fallback | Works without API key for demos and testing |
| Pydantic models | Type-safe, validated, serializable structured output |
| Automotive-specific KB | Not generic FMEA β€” tailored to ECU failure patterns |
| Separated concerns | RAG, Tools, Models, Server β€” each independently testable |

---

## 🎯 Supported Automotive Domains

- **Power Electronics** β€” Inverters, DC-DC converters, motor controllers
- **Connectivity** β€” TCU, V2X, telematics
- **ADAS / Autonomous Drive** β€” Camera, radar, sensor fusion, path planning
- **Battery Management** β€” BMS, cell balancing, thermal management
- **Braking / Steering** β€” Brake-by-wire, EPS, stability control
- **Body Electronics** β€” Lighting, door control, climate

---

## ⚠️ Disclaimer

This tool **assists** engineers in safety analysis β€” it does **not replace** human judgement for safety-critical decisions. All outputs should be reviewed by qualified functional safety engineers before use in production.

---

## πŸ‘€ Author

**Abinash Kumar** β€” AI & Automotive Connectivity Engineer

- LinkedIn: [abinash-kumar-26261657](https://www.linkedin.com/in/abinash-kumar-26261657/)
- GitHub: [Abinash009](https://github.com/Abinash009)

### Related Projects
- [sync-spec-agent](https://github.com/Abinash009/sync-spec-agent) β€” RAG + MCP agent for telecom standards
- [tcu-test-agent](https://github.com/Abinash009/tcu-test-agent) β€” Automotive ECU test automation (Robot Framework)

---

## πŸ“„ License

MIT License