Skip to content

agent-arch-labs/AutoCADMAS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AutoCAD MAS

Multi-Agent System for Autonomous CAD Drawing Generation

Python 3.12 173 tests passed License: MIT LangGraph DXF/DWG


Overview

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.

Why Multi-Agent?

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
Architecture Workflow

Key Features

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

Architecture

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

Agent Roles

  • 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

Workflow State Machine

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

Quick Start

Prerequisites

  • Python 3.11+
  • Conda (recommended) or venv

Installation

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.txt

Running the API Server

PYTHONPATH=src python -m uvicorn src.api.gateway:app --host 0.0.0.0 --port 8000 --reload

Or via Make:

make run

Using the API

# 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"
  }'

Python SDK

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']}")

NLP Parsing

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

Test Results

Overview

173 tests passed โ€” 0 failed โ€” 100% pass rate

Test Summary Tests by Module

Test Suite Breakdown

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

Advanced Test Cases

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)

Ablation Study Security

Ablation Study

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.


Security

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.


Project Structure

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

Development

Deployment Guide: See DEPLOY.md for Docker, Docker Compose, Kubernetes, and CI/CD setup instructions.

Running Tests

# All tests
make test

# Unit tests only
make test-unit

# Integration tests
make test-integration

# With coverage report
make test-cov

Linting & Type Checking

make lint        # ruff
make typecheck   # mypy

Generating Visualizations

PYTHONPATH=src python scripts/visualize_tests.py

Docker

make docker-build
make docker-up

License

MIT License. See pyproject.toml for details.


Citation

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},
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors