# Build With an Agent

The loop an agent follows to make a scene. Write, validate, verify, render, look, fix.

Motion SDK is designed so an agent can make a scene without a person checking each step. The scene is data, mistakes come back as fixes, and the agent can render a frame and look at it.

### Give It Context

Install the [skills](/docs/agents/skills) or point the agent at [/llms-full.txt](/docs/agents/llms-txt). Both teach the scene format, the presets and the fix loop. The JSON Schema in `schema/scene.schema.json` lets it check field names.

### Write the Scene

The agent writes the scene as TypeScript with [`@motion-sdk/scene`](/docs/concepts/typescript) and runs `tsc --noEmit`, so typos, wrong presets and wrong value shapes come back as compile errors with suggestions. It can also write the JSON directly, or stream it as [patches](/docs/reference/patch). Start with the camera, lighting and the main shapes. Use presets first. They're short and they look good.

### Validate

```bash title="Terminal"
motion-sdk validate scene.json --final --json
```

From TypeScript, `validate(scene, { final: true })` in `@motion-sdk/core/validate` returns the same report without the CLI. Each issue has a `path` and a `suggested_fix`, often a patch the agent can apply as is. Loop until there are no errors. See [Error Codes](/docs/reference/errors).

### Verify the Motion

```bash title="Terminal"
motion-sdk verify scene.json checks.json --json
```

The agent writes the brief down as checks, such as `expect("ball").movesRight({ during: [0, 1] })` or `expect("title").appearsBefore("subtitle")`. Verify samples the timeline without a GPU and returns each failure with expected versus actual and a fix hint. Loop until `ok` is `true`. See [Verify Motion](/docs/agents/verify).

### Render a Frame and Look

```bash title="Terminal"
motion-sdk render scene.json -t 2 -o check.png
```

The agent opens the image and compares it with the brief or a reference. Renders are [deterministic](/docs/concepts/determinism), so a change it didn't make never shows up.

### Fix and Repeat

Change one thing at a time, then render the same frame again. When stills look right, render the export.

## Streaming in the Browser

An agent can also build a scene live in front of the user. Each patch applies on the next frame, and a bad patch is rejected without breaking what's on screen.

```ts title="live.ts"
const player = await createPlayer(canvas, {}, {
  authoring: true,
  onError: (message) => agent.send(`Patch rejected: ${message}`),
})
for await (const line of agent.patches()) player.patch(line)
```

Pass `authoring: true` when the agent may stream prefabs or models later. See [Streaming](/docs/concepts/streaming).

## Prompting Tips

- Ask for a typed scene module (`defineScene` from `@motion-sdk/scene`) or a scene file, not renderer code.
- Name the export preset in the prompt, such as "a 6 second seamless x_1x1 loop".
- Ask the agent to render stills at key moments and check them before exporting.
- For a reference clip, ask for a shot list first. See [Recreate a Reference Video](/docs/guides/recreate-a-reference-video).
