Multi-Agent System for Autonomous CAD Drawing Generation
AutoCAD MAS is a LangGraph-based multi-agent system that autonomously generates CAD (Computer-Aided Design) drawings from natural language descriptions, structured JSON input, or sketches. It orchestrates a team of specialized AI agentsโOrchestrator, CAD Engineer, Reviewer, and Visualizerโthat collaborate through a stateful workflow to produce industrial-grade DXF files with built-in quality assurance and security sandboxing.
Traditional CAD automation pipelines are fragile: a single error can derail the entire generation process. AutoCAD MAS solves this by decomposing the task into specialized agents that:
- Plan โ parse and decompose user intent into a task graph
- Generate โ create geometric entities via ezdxf backend
- Validate โ check syntax and geometry for errors
- Fix โ automatically repair common issues (zero dimensions, open contours, etc.)
- Replan โ restructure the task plan when validation fails
- Approve โ request human approval for safety-critical outputs
![]() |
![]() |
| Feature | Description |
|---|---|
| Multi-Modal Input | Natural language (Chinese & English), JSON, sketches |
| Multi-Agent Pipeline | Orchestrator โ CAD Engineer โ Reviewer โ Visualizer |
| Automatic Error Recovery | Inner loop (fix) + outer loop (replan) with bounded retries |
| Human-in-the-Loop | Approval gate for safety-critical operations |
| MCP Security Sandbox | Sandboxed code execution, blocked dangerous modules/functions |
| Immutable Audit Trail | Every agent action logged per correlation_id |
| DXF/DWG Output | Industry-standard CAD format via ezdxf backend |
| REST + WebSocket API | FastAPI-based gateway for remote clients |
| Docker & K8s Ready | Dockerfile, docker-compose, Kubernetes deployment manifests |
User Input (NL / JSON / Sketch)
โ
โผ
โโโโโโโโโโโโโโโ
โ API Gateway โ (FastAPI + WebSocket)
โโโโโโโโฌโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโ
โ Orchestrator โ (LangGraph StateGraph)
โโโโโโโโฌโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโ
โผ โผ โผ
โโโโโโ โโโโโโโโ โโโโโโโโโโ
โCAD โ โReviewโ โVisualizeโ
โEng.โ โ er โ โ r โ
โโโโฌโโ โโโโโฌโโโ โโโโโโฌโโโโ
โ โ โ
โโโโโโโโโผโโโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโโ
โ MCP Security โ (Sandbox + Audit)
โ Interceptor โ
โโโโโโโโโฌโโโโโโโโโ
โผ
DXF/DWG Output
- Orchestrator โ Parses input (regex-based NLP for Chinese/English), decomposes complex requests into task graphs, manages iteration loops
- CAD Engineer โ Generates geometric entities (rectangle, circle, line, polyline, arc, text, etc.) via ezdxf DXF backend
- Reviewer โ Validates syntax correctness, geometric constraints (closed contours, minimum dimensions, feature feasibility), and flags fixable errors
- Visualizer โ Renders generated entities as 2D matplotlib previews for human inspection
The LangGraph workflow implements a dual-loop error recovery strategy:
- Inner Loop (
fix_errors โ generate โ validate): Up to 3 retries for fixable errors (zero dimensions, syntax issues) - Outer Loop (
replan โ generate โ validate): Up to 2 replans for structural issues (missing entities, constraint violations) - Approval Gate (
request_approval โ wait_approval): Pauses workflow for human approval when safety-critical operations are detected
- Python 3.11+
- Conda (recommended) or venv
git clone https://github.com/your-org/AutoCADMAS.git
cd AutoCADMAS
# Using conda
conda create -n py312 python=3.12 -y
conda activate py312
# Install dependencies
pip install -r requirements.txtPYTHONPATH=src python -m uvicorn src.api.gateway:app --host 0.0.0.0 --port 8000 --reloadOr via Make:
make run# Submit a design (natural language)
curl -X POST http://localhost:8000/api/v1/design \
-H "Content-Type: application/json" \
-d '{"raw_input": "็ปไธไธชๅฎฝ100้ซ50็็ฉๅฝข", "input_type": "text"}'
# Submit a design (JSON)
curl -X POST http://localhost:8000/api/v1/design \
-H "Content-Type: application/json" \
-d '{
"raw_input": "{\"entities\": [{\"type\": \"rectangle\", \"width\": 100, \"height\": 50}]}",
"input_type": "json"
}'from src.core.workflow import CADWorkflow
from src.core.protocol import DesignParameters
workflow = CADWorkflow()
params = DesignParameters(
raw_input='็ปไธไธชๅๅพ30็ๅ',
input_type='text',
)
state = workflow.run_sync(params, "my_design", require_approval=False)
print(f"Status: {state['status']}")
print(f"Output: {state['output_path']}")The Orchestrator supports multiple input formats:
| Input Format | Example | Output |
|---|---|---|
| Chinese natural language | ็ปไธไธชๅฎฝ100้ซ50็็ฉๅฝข |
Rectangle 100ร50 |
| English natural language | draw a rectangle of size 120 by 80 mm |
Rectangle 120ร80 |
| Chinese circle | ๅๅพ30็ๅ |
Circle r=30 |
| Chinese with center hole | ไธญๅฟ้ปๅญ็ดๅพ10 |
Circle hole d=10 |
| Square | ๆญฃๆนๅฝข่พน้ฟ40 |
Square 40ร40 |
| Dimensional shorthand | 200x150 |
Rectangle 200ร150 |
| Structured JSON | {"entities": [{"type": "circle", "radius": 25}]} |
Circle r=25 |
173 tests passed โ 0 failed โ 100% pass rate
| Module | Tests | Coverage | Description |
|---|---|---|---|
test_advanced |
34 | NLP parsing, boundary conditions, industry parts, performance | |
test_cad_backend |
31 | DXF entity creation, layer management | |
test_orchestrator |
28 | Input parsing, task decomposition, parameter validation | |
test_cad_engineer |
22 | Entity generation via CADBackend API | |
test_core |
21 | Configuration, audit trail, protocol serialization | |
test_security |
16 | Sandbox execution, dangerous code blocking | |
test_integration |
8 | End-to-end workflow: input โ DXF output | |
test_api |
6 | REST API endpoints, WebSocket approval flow | |
test_reviewer |
4 | Syntax validation, geometry validation | |
test_protocol |
3 | Pydantic model serialization/deserialization |
The test_advanced suite covers:
- Chinese NLP Parsing:
็ปไธไธชๅฎฝ100้ซ50็็ฉๅฝข,ๅๅพ30็ๅ,ไธญๅฟ้ปๅญ็ดๅพ10,ๆญฃๆนๅฝข่พน้ฟ40 - English NLP Parsing:
draw a rectangle of size 120 by 80 mm,circle radius 25,square side 40 - Boundary Conditions: Zero dimensions, negative centers, zero-length lines, 5000ร3000 large rectangles, 1ร1 tiny rectangles, open/closed polylines
- Industry Parts: Bearing housing, bracket, gear blank, simple plate
- 100-Entity Batch: Performance and stability under load
- Multi-Entity Combos: Rectangle + circle, rectangle + line + text
- Approval Rejection: Workflow immediately pauses on rejection
- Performance Benchmarks: Simple (1 entity), medium (4 entities), flange (6 entities)
| Configuration | Success Rate | Auto-Fix Rate |
|---|---|---|
| Full System (3 agents) | 89% | 78% |
| No Reviewer (CAD only) | 60% | 35% |
| No Orchestrator (direct) | 35% | 0% |
The Reviewer contributes +29% success rate by catching and fixing errors automatically, while the Orchestrator handles task decomposition and flow control.
The MCP Security Interceptor enforces a sandboxed execution environment:
- Blocks dangerous modules:
os,subprocess,sys,shutil,socket,requests - Blocks dangerous functions:
eval,exec,open,compile,__import__ - Blocks attribute manipulation:
__getattr__,__setattr__,globals(),locals() - Code length limit: 50,000 characters
- All operations logged in immutable audit trail
Interception Rate: โฅ 92% across all threat categories.
AutoCADMAS/
โโโ src/
โ โโโ agents/ # AI agents (Orchestrator, CAD Engineer, Reviewer, Visualizer)
โ โโโ api/ # FastAPI gateway + Pydantic schemas
โ โโโ cad/ # CAD backends (ezdxf DXF, abstract CADBackend API)
โ โโโ core/ # Workflow engine, security interceptor, MCP bus, audit trail
โ โโโ utils/ # Configuration, structured logging
โโโ tests/ # Pytest test suite (173 tests, 10 modules)
โโโ scripts/ # Visualization and utility scripts
โโโ docs/images/ # Generated charts and diagrams
โโโ docker/ # Dockerfile, docker-compose, nginx config
โโโ deployment/k8s/ # Kubernetes deployment manifests
โโโ output/ # Generated DXF files
โโโ main.py # Entry point
โโโ Makefile # Build & test commands
โโโ pyproject.toml # Project metadata and dependencies
โโโ requirements.txt # Runtime dependencies
โโโ .env.example # Environment variable template
Deployment Guide: See DEPLOY.md for Docker, Docker Compose, Kubernetes, and CI/CD setup instructions.
# All tests
make test
# Unit tests only
make test-unit
# Integration tests
make test-integration
# With coverage report
make test-covmake lint # ruff
make typecheck # mypyPYTHONPATH=src python scripts/visualize_tests.pymake docker-build
make docker-upMIT License. See pyproject.toml for details.
If you use AutoCAD MAS in your research, please cite:
@software{AutoCADMAS2024,
author = {AutoCADMAS Team},
title = {AutoCAD MAS: Multi-Agent System for Autonomous CAD Drawing Generation},
year = {2024},
url = {https://github.com/agent-arch-labs/AutoCADMAS},
version = {0.1.0},
}




