Tutorial 7 von 12
Mit API / MCP automatisieren
Experte 15 Min.
Steuere die Twinworks-Engine aus Skripten und KI-Agenten: Simuliere ein Modell, ermittle eine Rangfolge der Engpässe, variiere und optimiere Puffer, taste eine Linie aus und prüfe Warteschlangenformeln – mit echten JSON-Anfragen und -Antworten.
Die Simulations-Engine im Arbeitsbereich ist derselbe TypeScript-Code, der sechs Tools auf der usefulweb-API und dem MCP-Server antreibt. Ein siebtes, der Materialtransport-Planer, wird in Gemeinsam genutzte Fahrzeuge, Transportpläne und Modellprüfungen behandelt. Die Ergebnisse sind deterministisch: Dasselbe Modell mit demselben Seed liefert immer dieselben Zahlen, in der App wie auf dem Server.
| Tool-ID (REST) | MCP-Name | Funktion |
|---|---|---|
twinworks-simulate | twinworks_simulate | Modell + Laufzeit + Seed + Replikationen → Kennzahlen mit Konfidenzintervallen, Statistiken je Station, Engpass, Kosten |
twinworks-bottleneck-analysis | twinworks_bottleneck_analysis | Gereihte Engpässe (Aktivperioden-Methode) + Was-wäre-wenn-Gewinne + Empfehlungen |
twinworks-buffer-sweep | twinworks_buffer_sweep | Variiert eine Puffergröße (oder einen anderen Parameter) → Durchsatzkurve und Kniepunkt |
twinworks-buffer-allocation | twinworks_buffer_allocation | Verteilt eine feste Anzahl von Pufferplätzen für maximalen Durchsatz (Greedy-Verfahren, gemeinsame Zufallszahlen) |
twinworks-line-balance | twinworks_line_balance | Arbeitsschritte + Vorrangbeziehungen + Taktzeit → Stationszuordnung, Effizienz, Glättungsindex |
twinworks-queue-formulas | twinworks_queue_formulas | M/M/1, M/M/c, M/D/1, M/G/1, Kingman – optional per Simulation überprüft |
Im Arbeitsbereich zeigt dir Hilfe → Mit API / MCP automatisieren fertige Anfragen für dein aktuelles Modell, die du direkt kopieren kannst.

1. Eine Vorlage simulieren
Jedes Modell-Tool akzeptiert entweder eine template-ID oder ein model, also das JSON aus Datei → Exportieren → Modell-JSON (aktives Szenario), als String übergeben.
curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-simulate/calculate \
-H 'content-type: application/json' \
-d '{"template":"three-station-line","horizonHours":8,"replications":5,"seed":42}'
Antwort (gekürzt):
{
"summary": "3-station line: 64.1 ± 3.4 good parts/h (95 % CI, 5 replications), mean lead time 304 s, WIP 5.53; bottleneck: Mill.",
"result": {
"replications": 5,
"seeds": [42, 3029642774, 2605890936, 2032093786, 1137000544],
"throughputPerHour": { "mean": 64.1333, "lo": 60.7384, "hi": 67.5282, "halfWidth": 3.3949, "n": 5 },
"little": { "L": 6.8785, "lambdaPerHour": 66.6667, "W": 369.285, "lambdaW": 6.8386, "relError": 0.00581, "ok": true },
"stations": [
{ "id": "M2", "name": "Mill", "utilization": 0.9126,
"states": { "busy": 0.9126, "setup": 0, "waitop": 0, "blocked": 0, "idle": 0.0874, "down": 0, "maint": 0, "off": 0 },
"availability": 1, "performance": 0.903, "quality": 1, "oee": 0.903 }
],
"bottleneck": { "primary": "M2", "ranking": [ { "id": "M2", "name": "Mill", "sole": 0.8252, "shifting": 0.0606, "total": 0.8858 } ] },
"openInAppUrl": "https://twinworks.usefulweb.site/app#project=…"
}
}
seeds listet den Seed jeder Replikation auf, sodass sich jeder Lauf exakt reproduzieren lässt. little vergleicht den gemessenen Umlaufbestand (WIP) mit Durchsatz × Durchlaufzeit der ersten Replikation (Littles Gesetz) und ist damit eine schnelle Plausibilitätsprüfung des Modells. openInAppUrl öffnet das Modell im Arbeitsbereich.
2. Dein eigenes Modell, von Hand nachgerechnet
Eine deterministische Linie mit zwei Maschinen: unbegrenzter Nachschub, M1 = 30 s, ein Puffer mit 3 Plätzen, M2 = 40 s. Speichere sie als two-machines.json:
{
"name": "Two machines",
"settings": { "horizon": 7200, "warmup": 600 },
"nodes": [
{ "id": "S", "type": "source", "arrival": "saturated" },
{ "id": "M1", "type": "machine", "cycle": { "type": "constant", "value": 30 } },
{ "id": "B", "type": "buffer", "capacity": 3 },
{ "id": "M2", "type": "machine", "cycle": { "type": "constant", "value": 40 } },
{ "id": "OUT", "type": "sink" }
],
"links": [ { "from": "S", "to": "M1" }, { "from": "M1", "to": "B" }, { "from": "B", "to": "M2" }, { "from": "M2", "to": "OUT" } ]
}
Das Feld model ist Text (das JSON als String), deshalb wird die Datei mit jq eingebettet:
jq -n --rawfile m two-machines.json '{model: $m, replications: 1}' |
curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-simulate/calculate \
-H 'content-type: application/json' --data @-
Ergebnis: "summary": "Two machines: 90 good parts/h (single run), mean lead time 240 s, WIP 6; bottleneck: Machine M2." (Zwei Maschinen: 90 Gutteile/h im Einzellauf, mittlere Durchlaufzeit 240 s, Umlaufbestand 6, Engpass: Maschine M2.)
Das entspricht genau der Theorie für eine deterministische Linie: Durchsatz = 1 / Zykluszeit des Engpasses = 3600 / 40 = 90 Teile/h. M1 ist zu 30/40 = 75 % belegt und die übrigen 25 % blockiert, M2 ist zu 100 % belegt. Littles Gesetz gilt exakt: L = λ·W = (90 / 3600 s) × 240 s = 6 Teile im System.
Verteilungstypen: constant {value}, uniform {min,max}, triangular {min,mode,max}, normal {mean,sd} (bei 0 abgeschnitten), exponential {mean}, lognormal {mean,sd}. Das vollständige Format findest du in /project.schema.json.
3. Engpässe ermitteln und Verbesserungen testen
curl -s -X POST https://twinworks.usefulweb.site/api/v1/tools/twinworks-bottleneck-analysis/calculate \
-H 'content-type: application/json' \
-d '{"template":"bottleneck-buffer-sizing","replications":3}'
{
"summary": "\"OP30 Hone\" is the main bottleneck (58.3% of the time; best tested fix: Add a parallel server at \"OP30 Hone\" (1 → 2), +7.85 parts/h).",
"result": {
"primary": "M3",
"ranking": [
{ "rank": 1, "id": "M3", "name": "OP30 Hone", "sole": 0.4043, "shifting": 0.1788, "total": 0.5831, "utilization": 0.8477 },
{ "rank": 2, "id": "M2", "name": "OP20 Bore", "sole": 0.2613, "shifting": 0.1628, "total": 0.4241, "utilization": 0.7929 }
],
"recommendations": [ "\"OP30 Hone\" is the bottleneck 58.3% of the time (40.4% sole, 17.9% shifting): …" ]
}
}
4. Einen Puffer variieren
{ "template": "bottleneck-buffer-sizing", "target": "B2", "parameter": "capacity", "from": 1, "to": 8, "step": 1, "replications": 4 }
Sende das per POST an /api/v1/tools/twinworks-buffer-sweep/calculate:
{
"summary": "Throughput ranges from 99.6 to 105.8 parts/h over buffer capacity 1…8 at B2; knee point at 3.",
"result": {
"points": [
{ "value": 1, "throughput": { "mean": 99.5682, "lo": 95.1451, "hi": 103.9913 }, "wip": { "mean": 7.9107 }, "bottleneck": "M3" },
{ "value": 2, "throughput": { "mean": 102.4318, "lo": 97.7379, "hi": 107.1257 }, "wip": { "mean": 8.6199 }, "bottleneck": "M3" },
{ "value": 3, "throughput": { "mean": 103.7273, "lo": 99.2019, "hi": 108.2527 }, "wip": { "mean": 9.285 }, "bottleneck": "M3" }
]
}
}
Alle Messpunkte verwenden dieselben Replikations-Seeds. Dadurch ist die Kurve glatt und die Unterschiede zwischen den Punkten sind aussagekräftig.
5. Die Pufferverteilung optimieren
{ "template": "bottleneck-buffer-sizing", "total": 8, "replications": 3, "horizonHours": 6 }
Sende das per POST an /api/v1/tools/twinworks-buffer-allocation/calculate:
{
"summary": "8 buffer places: B1=1, B2=4, B3=2, B4=1 gives 97.13 parts/h (current allocation 95.2, significant gain); 6 well-placed places already reach the current throughput.",
"result": {
"best": { "capacities": { "B1": 1, "B2": 4, "B3": 2, "B4": 1 } },
"gain": { "mean": 1.9333, "lo": 1.6465, "hi": 2.2202 },
"placesForCurrentThroughput": 6,
"evaluations": 18
}
}
result.model ist das Modell mit den optimierten Kapazitäten und kann direkt an twinworks-simulate übergeben werden. Lässt du total weg, wird die aktuelle Anzahl an Plätzen neu verteilt. Mit buffers (z. B. "B2,B3") beschränkst du die Optimierung auf bestimmte Puffer.

6. Eine Linie austakten
{
"tasks": [
{ "id": "A", "time": 60, "predecessors": "" }, { "id": "B", "time": 40, "predecessors": "A" },
{ "id": "C", "time": 55, "predecessors": "B" }, { "id": "D", "time": 50, "predecessors": "A" },
{ "id": "E", "time": 30, "predecessors": "D" }, { "id": "F", "time": 45, "predecessors": "D" },
{ "id": "G", "time": 20, "predecessors": "F" }, { "id": "H", "time": 35, "predecessors": "C,E,G" }
],
"availableMinutes": 450, "demand": 270, "method": "best"
}
→ "4 stations for a takt time of 100 s (theoretical minimum 4), efficiency 83.8%, smoothness index 47.7 s." (4 Stationen bei 100 s Taktzeit, theoretisches Minimum 4, Effizienz 83,8 %, Glättungsindex 47,7 s) mit den Stationen [A,B], [D,F], [C,E], [G,H]. Das Ergebnis enthält außerdem ein simulationsfertiges model der ausgetakteten Linie.
7. Eine Warteschlangenformel prüfen
{ "queue": "mm1", "arrivalsPerHour": 60, "serviceTime": 48, "verify": true, "replications": 10 }
→ "M/M/1: utilization 80%, mean wait 192 s, mean queue 3.2; simulation confirms the result." (M/M/1: Auslastung 80 %, mittlere Wartezeit 192 s, mittlere Warteschlangenlänge 3,2; die Simulation bestätigt das Ergebnis.) Der Block verification enthält die simulierte mittlere Wartezeit von 193.4 s mit dem 95-%-Intervall [177.2, 209.6], das die exakten 192 s einschließt.
8. Aus einem KI-Agenten nutzen (MCP)
Füge den MCP-Endpunkt https://twinworks.usefulweb.site/mcp in deinem MCP-Client hinzu (Claude Desktop, Cursor, …). Die Tool-Namen verwenden Unterstriche:
{
"jsonrpc": "2.0", "id": 2, "method": "tools/call",
"params": {
"name": "twinworks_bottleneck_analysis",
"arguments": { "template": "bottleneck-buffer-sizing", "replications": 3 }
}
}
Die Antwort enthält die Zusammenfassung als Text und das vollständige JSON in structuredContent. Ein guter Prompt: „Hier ist meine Linie als Twinworks-JSON. Finde den Engpass, variiere dann den Puffer davor von 1 bis 8 und sag mir die kleinste Größe, die 95 % des Gewinns erreicht.“
Grenzen
Eine Replikation darf höchstens 6 Millionen Ereignisse umfassen. Die API akzeptiert bis zu 30 Replikationen für twinworks-simulate und bis zu 20 je Messpunkt für die Analyse- und Variationstools, bei Laufzeiten bis zu 2.400 Stunden. Für größere Studien nutzt du den Arbeitsbereich (er läuft in einem Web Worker) oder teilst die Arbeit auf mehrere Aufrufe auf.
Bereit zum Ausprobieren?