AI-powered conversational agent using BESSER Agentic framework for creating and modifying UML diagrams using natural language for the editor.besser-pearl.org
The Modeling Agent is an intelligent backend service that interprets natural language requests and generates UML diagram elements in real-time. It uses LLM (Large Language Models) to understand user intent and produce structured diagram specifications in the BESSER model format.
- What the Bot Can Do
- Supported Diagram Types
- Architecture
- API & Data Formats
- Installation & Setup
- Usage Examples
- Testing
- Known Issues & Limitations
- β Create individual classes with attributes and methods
- β Generate complete class diagrams with multiple classes and relationships
- β Support relationships: Association, Composition, Aggregation, Inheritance, Realization
- β Specify visibility modifiers (+, -, #, ~)
- β Define attribute types and method signatures
- β Set multiplicity on relationships
- β Modify existing classes
- β Create object instances from class definitions
- β Reference class diagrams to use exact class/attribute IDs
- β Populate objects with realistic example values
- β Create links between object instances
- β Validate objects against their class definitions
- β Create states (simple, initial, final, choice)
- β Define transitions with triggers, guards, and effects
- β Generate complete state machines with multiple states
- β Support composite states and history states
- β Create agent nodes with goals and actions
- β Define message passing between agents
- β Generate multi-agent systems
- β Specify agent communication protocols
- β Query official UML specification documents
- β Get definitions of UML concepts and notation
- β Retrieve best practices and formal definitions
- β RAG-powered retrieval from UML specification PDFs
- π― Single Element Creation: "add a class User"
- π¨ Complete System Generation: "create a library management system"
- π Model Modification: "add a method to the User class"
- π¬ Natural Language Understanding: Works with conversational requests
- π Context-Aware Generation: Uses current diagram state to make intelligent decisions
- π Reference Diagram Support: ObjectDiagram can reference ClassDiagram definitions
- π§ LLM-Powered: Uses GPT for intelligent interpretation of user requests
- β‘ Real-Time WebSocket Communication: Instant updates to frontend
- π‘οΈ Fallback Mechanisms: Generates basic elements if AI fails
| Diagram Type | Single Element | Complete System | Modify | Status |
|---|---|---|---|---|
| Class Diagram | β | β | β | Fully Supported |
| Object Diagram | β | β | β | Fully Supported |
| State Machine | β | β | β | Fully Supported |
| Agent Diagram | β | β | β | Fully Supported |
| UML Specification | N/A | N/A | N/A | Fully Supported |
βββββββββββββββββββ
β Frontend β (TypeScript React Widget)
β (BESSER Web) β
ββββββββββ¬βββββββββ
β WebSocket (JSON)
βΌ
βββββββββββββββββββ
β Modeling Agent β (Python Backend)
β (BESSER AI) β
βββββββββββββββββββ€
β β’ Intent Router β
β β’ Diagram β
β Handlers β
β β’ LLM Service β
β β’ RAG Service β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β GPT/LLM β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β UML Specs β
β (Vector DB) β
βββββββββββββββββββ
-
Intent Router (
modeling_agent.py):- Detects user intent (create, modify, query)
- Routes requests to appropriate handlers
- Manages conversation state
-
Diagram Handlers (
diagram_handlers/):ClassDiagramHandler: Handles class diagram generationObjectDiagramHandler: Handles object diagram generation (with reference support)StateMachineHandler: Handles state machine generationAgentDiagramHandler: Handles agent diagram generation
-
LLM Service:
- Wraps GPT API calls
- Handles prompt engineering
- Parses and validates JSON responses
-
RAG Service:
- Retrieval-Augmented Generation for UML specifications
- Vector-based document retrieval from UML spec PDFs
- Context-aware answers to UML specification questions
- Leverages Chroma vector store for efficient document search
-
WebSocket Service:
- Real-time communication with frontend
- Sends structured BESSER model updates
{
"message": "[DIAGRAM_TYPE:ClassDiagram] create a User class",
"diagramType": "ClassDiagram",
"currentModel": {
"version": "3.0.0",
"type": "ClassDiagram",
"elements": {},
"relationships": {}
},
"referenceDiagramData": {
"version": "3.0.0",
"type": "ClassDiagram",
"elements": {...}
}
}{
"action": "inject_element",
"diagramType": "ClassDiagram",
"element": {
"name": "User",
"attributes": [
{"name": "id", "type": "String", "visibility": "+"},
{"name": "name", "type": "String", "visibility": "+"}
],
"methods": [
{"name": "login", "returnType": "void", "visibility": "+"}
]
},
"message": "β
Successfully created class User with 2 attributes and 1 method!"
}{
"action": "inject_complete_system",
"diagramType": "ClassDiagram",
"systemSpec": {
"systemName": "LibraryManagement",
"classes": [...],
"relationships": [...]
},
"message": "β¨ Created LibraryManagement diagram!"
}{
"action": "inject_element",
"diagramType": "ObjectDiagram",
"element": {
"objectName": "harryPotter",
"className": "Book",
"classId": "class_j14u331vy_mh3ca9ma",
"attributes": [
{
"name": "title",
"attributeId": "attr_gsral672h_mh3ca9ma",
"value": "Harry Potter and the Sorcerer's Stone"
},
{
"name": "isbn",
"attributeId": "attr_zmzmcz7ud_mh3ca9ma",
"value": "978-0439708180"
}
]
}
}- Python 3.11+
- OpenAI API key
# Clone the repository
cd ModelingAgent
# Install dependencies
pip install -r requirements.txt
# Set up configuration
cp config.ini.example config.ini
# Edit config.ini with your OpenAI API key[DEFAULT]
API_KEY = your_openai_api_key_here
MODEL = gpt-4
TEMPERATURE = 0.7
PORT = 8765python modeling_agent.pyThe agent will start a WebSocket server on ws://localhost:8765
User: "create a User class with id, name, and email attributes"
Agent: β
Created User class with 3 attributes
User: "add a login method to User"
Agent: β
Added login() method to User class
User: "create a library management system"
Agent: β¨ Created complete library system with Book, Author, Member, and Loan classes
User: "create a book object named harryPotter"
Agent: β
Created harryPotter object (instance of Book) with 4 attributes
User: "add another book called lordOfTheRings"
Agent: β
Created lordOfTheRings object with realistic values
User: "create a login state machine"
Agent: β¨ Created login state machine with Idle, Authenticating, and LoggedIn states
User: "add a timeout transition"
Agent: β
Added timeout transition from Authenticating to Idle
User: "create a multi-agent auction system"
Agent: β¨ Created auction system with Auctioneer and Bidder agents
# Run all tests
pytest
# Run specific test file
pytest tests/test_class_diagram_handler.py
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=diagram_handlerstests/
βββ __init__.py
βββ conftest.py # Shared fixtures
βββ test_class_diagram_handler.py # Class diagram tests
βββ test_payload_and_routing.py # Integration tests
βββ test_workflow_scenarios.py # End-to-end tests
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is part of the BESSER framework. See LICENSE for details.