Skip to content

← Back to news

How Mgent Debugged Five Broken SysML Models on Its Own

How Mgent Debugged Five Broken SysML Models on Its Own

Mgent demo series, Day 2

We gave Mgent, the AI agent in Mg, one sentence of instruction and a folder of five SysML v2 models full of validation errors. About 60 seconds later, all five models passed validation. About two minutes in, it had also built and run a Jupyter notebook that anyone can re-run to verify the result.

No one typed anything after the first sentence.

This article walks through what Mgent actually did during those two minutes, because the interesting part is not that the errors got fixed. It is how they got fixed: Mgent made mistakes, noticed them, formed hypotheses, tested them, threw out the wrong ones, and isolated the real cause with minimal test cases. That is the difference between an AI agent and an AI chat.

The request

This was the entire prompt:

can you fix the validation errors in the sysml models in folder SampleModel? Create a notebook to open the models and validate after fixing the issues. Add the notebook in the same folder.

The starting point

SampleModel/ contains a small vehicle model split across five packages. Each file had at least one problem, and several of them are mistakes that real teams make every day, especially when moving from SysML v1 to SysML v2:

FileProblems
Vehicle.sysmlMissing semicolon; file named Vehicle.sysml but declares package VehicleModel
Cabin.sysmlBare import (SysML v2 requires private or public); missing semicolon
Chassis.sysmlMissing semicolon; a part named frame
Electrical.sysmlblock Lamp, a SysML v1 keyword
Powertrain.sysmlblock Transmission and value gearCount, both SysML v1 keywords

Some of these produce confusing cascades. A single syntax error can make the validator also report that standard types like Real and Integer cannot be resolved, which sends a human debugging in the wrong direction.

What Mgent did

1. Diagnose before touching anything (0–7 s)

Mgent listed the folder, read Mg’s quickstart guidance, read all five models, and ran the validator on each one. Only then did it consult the SysML v2 syntax reference and write up its analysis.

2. First round of fixes (11 s)

It applied six targeted edits in one pass: added the missing semicolons, changed import to private import, and replaced block with part def and value with attribute.

3. Re-validate, and find that it is not done (12–15 s)

Mgent did not assume its fixes worked. It ran the validator again on every file, and errors remained. Rather than stopping and reporting success, it started investigating why.

4. Doubt its own work (15–35 s)

The validator still complained about the bare import in Cabin.sysml, an error Mgent believed it had fixed. So it re-read the file from disk and found that the edit had not taken effect. It switched to rewriting the file in full, and Cabin.sysml then validated cleanly.

While reading the models again, it also noticed a rule violation the validator had not pointed at directly: Mg requires a file’s top-level package to match its file name, and Vehicle.sysml declared package VehicleModel. It renamed the package to Vehicle.

5. Form hypotheses, and reject the wrong ones (35–46 s)

Chassis.sysml was the hard case. Every line looked valid, yet the validator kept reporting a syntax error on this line:

part frame : Frame;

Mgent worked through it the way an engineer would:

  • Hypothesis: the validator is reading a stale, cached model. Possible, so it kept looking for evidence.
  • Hypothesis: hidden characters or line endings. It dumped the raw bytes of the file, found Windows CRLF line endings, rewrote the file with LF endings, and re-validated. Same error. Hypothesis rejected.
  • Hypothesis: something about the file itself. It validated the same content as plain text, bypassing the file entirely. Same error. So the problem was in the SysML, not in the file or the cache.

6. Isolate the cause with minimal test cases (46–52 s)

This is the most instructive part of the run. Mgent stripped the problem down to the smallest models that would tell it something.

This passes:

package T {
    part def Chassis {
        part thing : Frame;
    }
    part def Frame {}
}

This fails:

package T {
    part def Chassis {
        part frame : Frame;
    }
    part def Frame {}
}

The only difference is the name. Conclusion: frame is a reserved keyword in SysML v2 (it is used for framed concerns), so it cannot be used as a feature name. To confirm, Mgent tested one more variant:

part frameStructure : Frame;

It passed. Mgent applied the rename to Chassis.sysml.

7. Confirm everything (54–60 s)

Mgent validated each file again. All five came back with zero issues, including Vehicle.sysml, which imports the other four packages.

8. Build the verification notebook (64 s – 2 min)

The second half of the request was a notebook that opens the models and validates them. Mgent created ValidateSampleModel.ipynb with the MgPy kernel, and it hit a few more obstacles along the way:

  • Running all cells at once timed out on the first attempt, so it ran the cells one at a time.
  • A cell identifier format was rejected, so it switched to cell indexes.
  • A query meant to list the model’s packages returned nothing, so it rewrote the query to enumerate each package explicitly.

Finally, it ran the whole notebook top to bottom in one pass to make sure it works as a unit.

The result

The notebook loads all five models together so cross-package references resolve, validates each one, and queries the loaded model. Its final output:

Cabin: ['Cabin', 'Seat', 'SteeringWheel']
Chassis: ['Chassis', 'Frame', 'Wheel']
Electrical: ['Electrical', 'Battery', 'Lamp']
Powertrain: ['Powertrain', 'Engine', 'Transmission']
Vehicle: ['Vehicle', 'vehicle']

Final validation errors per file: {'Cabin.sysml': 0, 'Chassis.sysml': 0, 'Electrical.sysml': 0, 'Powertrain.sysml': 0, 'Vehicle.sysml': 0}
RESULT: ALL FILES VALID

The changes, in summary:

FileFix
Vehicle.sysmlAdded missing semicolon; package VehicleModel → package Vehicle
Cabin.sysmlimport → private import; added missing semicolon
Chassis.sysmlAdded missing semicolon; part frame → part frameStructure
Electrical.sysmlblock Lamp → part def Lamp
Powertrain.sysmlblock → part def; value → attribute

The notebook matters as much as the fixes. It is a reproducible record that the model validates, which anyone on the team can re-run. The AI proposes. The validator decides.

Why an AI chat would not do this

With an AI chat, every step above is a round trip through a human. You paste the error, get a suggested fix, apply it, re-run the validator, and paste the new error back. When the fix does not work, the chat cannot see that. You have to notice it, and you have to supply the evidence for every hypothesis. Finding that frame is a reserved word could easily take a dozen exchanges, and that is assuming the chat suggests the right experiments.

In control terms, AI chat is open-loop: it produces an output and stops, and a human closes the loop. Mgent is closed-loop: the validator is its sensor. It acts, measures the result, and corrects until the measurement says the model is valid. Systems engineers already know why closed-loop control is more robust. The same reasoning applies here.

What still needs a human

Mgent did not just fix syntax. Renaming frame to frameStructure is a naming decision, and renaming package VehicleModel to package Vehicle changes a package name that other models may reference. These are reasonable choices, but they are design choices, and an engineer should review the diff before it is merged. Mgent makes the changes and the evidence visible. The engineer stays in charge of what goes into the model.

Try it

Mgent is available now in Mg. Subscribe at mg.mgnite.com.

This article is part of a short series showing what AI agents actually mean for MBSE. Next, we will look at other ways Mgent can take repetitive model work off your plate.