Skip to content

6. Make a scoped change with an agent

Your model now has named parts, explicit dimensions and checks. Give an agent a small change whose result you can review in both code and the running app.

Continue with the checked enclosure from chapter 5. Keep the app open with --project enclosure:PROJECT as in chapter 2.

If you are starting here, expand this chapter's complete starting point and save it as enclosure.py. It has the same model and checks as chapter 5.

Complete starting point for the agent task: enclosure.py
"""Chapter 6: the checked starting point for a scoped agent edit.

Task: change HEIGHT to 24, keep the rim at Z=0 and preserve the lid and mount.
Validate the assembly and export both parts after the change.
"""
import cadquery as cq

WIDTH = 80
DEPTH = 50
HEIGHT = 20
WALL = 2.4
LID_THICKNESS = 3
SCREW_LENGTH = 8
MOUNT_POINTS = ((-34, -19), (-34, 19), (34, -19), (34, 19))


def box_body():
    # The rim is Z=0; the box extends down from it.
    outside = cq.Workplane("XY").rect(WIDTH, DEPTH).extrude(-HEIGHT)
    cavity = (cq.Workplane("XY").rect(WIDTH - 2 * WALL, DEPTH - 2 * WALL)
              .extrude(-(HEIGHT - WALL)))
    shell = outside.cut(cavity)
    # Four pads join the walls; each will receive a blind insert pocket.
    pads = (cq.Workplane("XY").pushPoints(MOUNT_POINTS)
            .circle(4.5).extrude(-8))
    return shell.union(pads)


def lid_body():
    return cq.Workplane("XY").rect(WIDTH, DEPTH).extrude(LID_THICKNESS)


from cadkit import FastenerSpec
import cadkit as ck


def insert_envelope(spec):
    """A dimensioned placeholder, not a supplier-specific insert model."""
    model = (cq.Workplane("XY").circle(2.35).circle(1.5)
             .extrude(spec.length_mm).val())
    model.thread_diameter = 3
    model.thread_pitch = 0.5
    return model


MOUNT = ck.InsertMount(
    pattern=ck.PointPattern(MOUNT_POINTS),
    screw=FastenerSpec("socket_head_cap_screw", "M3-0.5", length_mm=SCREW_LENGTH),
    insert=FastenerSpec(
        "heat_set_insert", "M3-0.5", length_mm=5.7, standard="tutorial-envelope",
        factory=insert_envelope, representation="envelope",
        description="Tutorial insert envelope; select and calibrate a real insert before printing.",
    ),
    clearance_diameter=3.4,
    pocket=ck.InsertPocket(diameter=4, depth=6.7, insert_outer_diameter=4.7),
    minimum_engagement=3,
)

BOX = ck.Part(
    "box", box_body, manufacture=ck.FDM("PETG"),
    features={"lid-mount": MOUNT.insert_side()},
)
LID = ck.Part(
    "lid", lid_body, manufacture=ck.FDM("PETG"),
    features={"lid-mount": MOUNT.clearance_side(thickness=LID_THICKNESS)},
)

DESIGN = ck.Assembly("enclosure")
box = DESIGN.add("box", BOX, color=(0.32, 0.58, 0.72))
lid = DESIGN.add("lid", LID, color=(0.86, 0.70, 0.40), explode=(0, 0, 20))
DESIGN.fix(box)
closure = DESIGN.connect(
    "lid-mount", MOUNT,
    through=lid.feature("lid-mount"), into=box.feature("lid-mount"),
)

# Require the installed lid to touch the rim, without a material overlap.
DESIGN.interface(
    "lid-on-rim", left=box, right=lid,
    kind="contact", max_gap_mm=0.01,
)
# Check a straight, 3 mm diameter driver against these two parts.
DESIGN.driver_access(
    "lid-driver", connection=closure,
    diameter=3, length=30, obstacles=(box, lid),
)

PROJECT = DESIGN.as_project()

Give the agent the instructions and live view

From your model directory, install the CadKit skill:

npx skills add aurkakoak/cadkit --skill cadkit

Choose your agent host in the installer. Node/npm is needed for this skill installation command; the packaged desktop's MCP server does not need a separate Node installation.

In CadKit Desktop, click the plug icon and copy the MCP configuration for this session into your agent client's MCP settings. The copied configuration contains the app executable, project directory and project reference. Use the same project that is open in the app.

The skill teaches the agent how to work; MCP lets it inspect your actual running session. The agent's coding environment supplies file editing and terminal commands. CadKit MCP itself does not edit arbitrary files or run shell commands.

Start a fresh agent conversation in the model directory, or reload the client's skills and MCP configuration. Select the box in the app, then use this prompt:

Use the CadKit skill and the open CadKit app. Read enclosure.py and inspect my selected box. Increase the box height from 20 mm to 24 mm by changing HEIGHT. Keep the rim at Z = 0, preserve the lid and its four mounting sites, and do not change the screw or insert specifications. After the rebuild, inspect both parts and run validate-assembly. Export both parts to build/taller-enclosure. Tell me what changed, any confirmed failures, and what remains unverified. Do not slice or print anything.

Review the result

The code change should be HEIGHT = 24. The box's floor should move from Z = −20 to Z = −24 while the rim, lid and hardware stay in place. The outer box dimensions should now be 80 × 50 × 24 mm. Its pads still descend 8 mm from the rim, and its floor stays 2.4 mm thick.

The taller box with its lid hidden

The desktop bounds include a small numerical margin (24.01 mm in this view); the authored height is 24 mm.

Ask the agent to show the interior with the lid hidden and capture a screenshot. Its geometry-dependent MCP calls should first read get_state and use the current revision and object IDs. If a file edit rebuilds the model, the agent must read the new state before measuring it again.

Verify the same result yourself:

uv run cadkit --project enclosure:PROJECT inspect box
uv run cadkit --project enclosure:PROJECT inspect lid
uv run cadkit --project enclosure:PROJECT validate-assembly --output build/taller-checks.json
uv run cadkit --project enclosure:PROJECT build all --output-dir build/taller-enclosure

The lid should still measure 80 × 50 × 3 mm. The BOM should still contain four screws and four inserts. The mechanical report should have no confirmed failures and should retain the earlier unverified findings.

You have used the same project through geometry creation, assembly, inspection, export, mechanical checks and agent work. Keep the dimensions, names and checks in source control so that later changes can be reviewed in the same way.

Choose your next task

These how-to guides start from an existing project:

Complete example · ← Check a change · Tutorial overview