# Building a Two-Step Injection Molding Agent: Deterministic First-Shot Setup & Sink-Mark Tuning via REST and MCP

> Source: <https://dev.to/moss_chan_15cdefc01087a6e/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink-mark-tuning-via-21mf>
> Published: 2026-12-01 01:35:18+00:00

**Recommendation:** Keep deterministic physics in a stateful API keyed by business_id and let the LLM send only defect enums, so packing changes derive from stored machine state rather than model guesses.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

When developers build AI copilots for manufacturing plants (using Claude, Cursor, Dify, Coze, or OpenAI GPT Actions), the UI and workflow glue are the easy part. The hard part is **physics**: if an LLM guesses screw stroke positions or packing pressures on a 160-ton injection molding press, you get short shots, flash, or damaged tooling.

A cleaner architecture separates **reasoning/UI** (the LLM) from **deterministic shop-floor math** (a stateful physics API/MCP tool).

In this tutorial, we'll walk through a production two-step closed-loop workflow using the [AICraft Injection Process API & MCP Server](https://aicraft4injection.com/?utm_source=devto#trial-card) on a real cosmetic **ABS electronics enclosure** (`2.2 mm` wall, `56 g` shot weight, `Ø40 mm` screw, `160 T` press).

`first-shot` → `optimize`) Beat Stateless Prompts
Real injection molding tryouts follow decoupled scientific molding:

`/v1/first-shot`)` MEL`, `ML0`, `VPTL`, `IL0..IL2`), barrel temperatures (` NT`, `BT1..BT4`), and multi-stage fill speeds/pressures — intentionally leaving holding/packing at `0` so the technician verifies fill balance first.`/v1/optimize`)` business_id`.
Always pass `target_shot_weight_g` (total shot weight including runner). Without shot mass, no physical engine can derive true screw displacement from `shot_mass / (density * pi * R^2)`.

```
curl -X POST https://aicraft4injection.com/v1/first-shot \
  -H "Authorization: Bearer $AICRAFT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "business_id": "ABS-HOUSING-160T",
    "target_shot_weight_g": 56.0,
    "polymer": {
      "polymer_abbreviation": "ABS"
    },
    "mold": {
      "product_ave_thickness": 2.2,
      "product_max_length": 185.0
    },
    "machine": {
      "clamping_force": 160,
      "injector": {
        "injector_screw_diameter_mm": 40.0
      }
    }
  }'
```

For `56 g` ABS on a `Ø40 mm` barrel (`A = π × 20² = 1256.6 mm²`):

| Parameter | Meaning | Calculated Value | Engineering Basis | 
|---|---|---|---|
| `MEL` | Metering end position | **62.72 mm** | `14.28` cushion +`41.44` fill stroke +`7.0` suck-back | 
| `ML0` | Metering position (stage 0) | **55.72 mm** | `14.28 + 41.44 mm` (93% initial first-shot fill) | 
| `VPTL` | V/P switchover position | **14.28 mm** | `max(25% × fill, 0.085 × max_stroke)` clamped`[8, 20]` mm | 
| `IL0` | Stage 0 stroke end | **49.5 mm** | Slow gate-entry ramp ( `0.50 × peak` ) | 
| `NT` /`BT1` | Nozzle / Zone 1 temp | **242.0 °C / 256.0 °C** | Amorphous ABS melt gradient | 
| `IP0` /`IP1` | Injection pressure stages 0 & 1 | **55.25 / 57.38 MPa** | Flow-length & wall-thickness pressure factors | 
| `IV0` /`IV1` | Injection velocity stages 0 & 1 | **12.95 / 25.9 mm/s** | `2.20 s` target fill window vs.`3.78 s` freeze clock | 
| `CT` | Cooling time | **10.0 s** | Derived from `2.2 mm` ABS thermal diffusivity | 
| `PP0` /`PT0` | Holding pressure / time | **0.0 MPa / 0.0 s** | T1 baseline prior to packing calibration | 

Because we included `"business_id": "ABS-HOUSING-160T"`, the gateway automatically persists all 47 parameters scoped to your API key.

`SHRINKAGE`)
Now the press operator reports moderate sink marks. Your agent only needs to send the same `business_id` and the English defect enum:

```
curl -X POST https://aicraft4injection.com/v1/optimize \
  -H "Authorization: Bearer $AICRAFT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "business_id": "ABS-HOUSING-160T",
    "defect_info": [
      {
        "defect": "SHRINKAGE",
        "level": "moderate"
      }
    ]
  }'
```

The engine loads the archived 47-key state, fires fuzzy rule **`Rule.dat #65`** (` IF SHRINKAGE_mid AND PP0_low THEN PP0_add_mid`), and applies material-specific packing guards for ABS:

`PP0`` 0.0 → 27.54 MPa` (`0.48 × 57.38 MPa` peak injection pressure)`PT0`` 0.0 → 1.54 s` (`2.2 mm wall × 0.7`)` PP1 = 12.39 MPa`, `PT1 = 1.1 s` (avoids gate overpacking and residual stress)`IT`)` 5.2 s → 2.2 s` so packing engages cleanly at V/P transfer without dead delay
Every adjustment is returned inside `recommend_thinking`, so your agent can explain *why* each number changed directly to the shop-floor technician.

You don't even have to write wrapper code if your client supports remote MCP:

```
{
  "mcpServers": {
    "aicraft-injection": {
      "url": "https://aicraft4injection.com/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}
```

Or run the open-source stdio wrapper (`github.com/DreamwayChan/aicraft-mcp-server`).

You can test this exact ABS scenario in the interactive browser sandbox or generate an instant **30-call free trial API/MCP key** (no credit card required) here:

👉 [https://aicraft4injection.com/?utm_source=devto#trial-card](https://aicraft4injection.com/?utm_source=devto#trial-card)

If you're building plant-floor AI tools or MCP servers for manufacturing, I'd love to hear how you're separating LLM orchestration from deterministic engineering math in the comments!
