{"slug": "building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink", "title": "Building a Two-Step Injection Molding Agent: Deterministic First-Shot Setup & Sink-Mark Tuning via REST and MCP", "summary": "A developer demonstrated a two-step closed-loop injection molding agent that splits LLM reasoning from deterministic shop-floor physics via a REST API and MCP server. The workflow uses a /v1/first-shot endpoint to compute 47 machine parameters for a 56 g ABS electronics enclosure on a 160-ton press, then a /v1/optimize endpoint that loads the archived state and applies fuzzy rule Rule.dat #65 to raise holding pressure from 0 to 27.54 MPa and holding time to 1.54 s in response to moderate sink marks.", "body_md": "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.\n\nA cleaner architecture separates **reasoning/UI** (the LLM) from **deterministic shop-floor math** (a stateful physics API/MCP tool).\n\nIn 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).\n\n`first-shot` → `optimize`) Beat Stateless Prompts\nReal injection molding tryouts follow decoupled scientific molding:\n\n`/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`.\nAlways 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)`.\n\n```\ncurl -X POST https://aicraft4injection.com/v1/first-shot \\\n  -H \"Authorization: Bearer $AICRAFT_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"business_id\": \"ABS-HOUSING-160T\",\n    \"target_shot_weight_g\": 56.0,\n    \"polymer\": {\n      \"polymer_abbreviation\": \"ABS\"\n    },\n    \"mold\": {\n      \"product_ave_thickness\": 2.2,\n      \"product_max_length\": 185.0\n    },\n    \"machine\": {\n      \"clamping_force\": 160,\n      \"injector\": {\n        \"injector_screw_diameter_mm\": 40.0\n      }\n    }\n  }'\n```\n\nFor `56 g` ABS on a `Ø40 mm` barrel (`A = π × 20² = 1256.6 mm²`):\n\n| Parameter | Meaning | Calculated Value | Engineering Basis | \n|---|---|---|---|\n| `MEL` | Metering end position | **62.72 mm** | `14.28` cushion +`41.44` fill stroke +`7.0` suck-back | \n| `ML0` | Metering position (stage 0) | **55.72 mm** | `14.28 + 41.44 mm` (93% initial first-shot fill) | \n| `VPTL` | V/P switchover position | **14.28 mm** | `max(25% × fill, 0.085 × max_stroke)` clamped`[8, 20]` mm | \n| `IL0` | Stage 0 stroke end | **49.5 mm** | Slow gate-entry ramp ( `0.50 × peak` ) | \n| `NT` /`BT1` | Nozzle / Zone 1 temp | **242.0 °C / 256.0 °C** | Amorphous ABS melt gradient | \n| `IP0` /`IP1` | Injection pressure stages 0 & 1 | **55.25 / 57.38 MPa** | Flow-length & wall-thickness pressure factors | \n| `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 | \n| `CT` | Cooling time | **10.0 s** | Derived from `2.2 mm` ABS thermal diffusivity | \n| `PP0` /`PT0` | Holding pressure / time | **0.0 MPa / 0.0 s** | T1 baseline prior to packing calibration | \n\nBecause we included `\"business_id\": \"ABS-HOUSING-160T\"`, the gateway automatically persists all 47 parameters scoped to your API key.\n\n`SHRINKAGE`)\nNow the press operator reports moderate sink marks. Your agent only needs to send the same `business_id` and the English defect enum:\n\n```\ncurl -X POST https://aicraft4injection.com/v1/optimize \\\n  -H \"Authorization: Bearer $AICRAFT_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"business_id\": \"ABS-HOUSING-160T\",\n    \"defect_info\": [\n      {\n        \"defect\": \"SHRINKAGE\",\n        \"level\": \"moderate\"\n      }\n    ]\n  }'\n```\n\nThe 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:\n\n`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\nEvery adjustment is returned inside `recommend_thinking`, so your agent can explain *why* each number changed directly to the shop-floor technician.\n\nYou don't even have to write wrapper code if your client supports remote MCP:\n\n```\n{\n  \"mcpServers\": {\n    \"aicraft-injection\": {\n      \"url\": \"https://aicraft4injection.com/mcp\",\n      \"headers\": {\n        \"Authorization\": \"Bearer YOUR_API_KEY\"\n      }\n    }\n  }\n}\n```\n\nOr run the open-source stdio wrapper (`github.com/DreamwayChan/aicraft-mcp-server`).\n\nYou 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:\n\n👉 [https://aicraft4injection.com/?utm_source=devto#trial-card](https://aicraft4injection.com/?utm_source=devto#trial-card)\n\nIf 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!", "url": "https://wpnews.pro/news/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink", "canonical_source": "https://dev.to/moss_chan_15cdefc01087a6e/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink-mark-tuning-via-21mf", "published_at": "2026-12-01 01:35:18+00:00", "updated_at": "2026-12-01 01:44:51.848972+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "agent-protocols", "developer-tools", "artificial-intelligence"], "entities": ["AICraft", "Claude", "Cursor", "Dify", "Coze", "OpenAI"], "also_reported_by": [], "takeaway": "Separating LLM reasoning from a stateful physics API that persists all 47 parameters under a business_id lets an agent recompute packing pressure and time from a single defect enum instead of guessing screw positions.", "recommendation": {"advice": "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.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink", "markdown": "https://wpnews.pro/news/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink.md", "text": "https://wpnews.pro/news/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink.txt", "jsonld": "https://wpnews.pro/news/building-a-two-step-injection-molding-agent-deterministic-first-shot-setup-sink.jsonld"}}