# The loop an agent works in

An agent that writes a video cannot watch it play. It works in a loop of small steps, each one a call of a [tool](/docs/framework/agents/tools.md) that answers in JSON or with a picture:

1. **Edit** the video's files with `bash`. Framescript writes the change only when the video still runs.
2. **Check** it: `check` answers with the diagnostics. Fix them before anything else. Check is the one gate: a video it finds an error in is not written by an agent's tools, and no one exports it, from the studio, the tool `exports` or `render`; the studio shows every finding after every change, whatever made it.
3. **Look**: `frame` returns a frame as a picture. Read the picture.
4. **Trace** what you see back to its line: `inspect` with `action: "pick"` for a pixel, `inspect` for a whole frame, and with `action: "schedule"` for the whole video.
5. **Change** the thing: a control with `controls` and `action: "set"`, or the literal on the line the trace named.
6. **Answer** the comment that asked for it, with `comments` and `action: "reply"`.

Then check and look again. How to plan a video, build it in parts and judge what you see is on [Making a video that holds up](/docs/framework/agents/making.md). The tools are described in [Checking a video](/docs/framework/agents/checking.md), [Reading a video](/docs/framework/agents/reading.md), [Looking at a frame](/docs/framework/agents/frames.md) and [Controls and comments](/docs/framework/agents/controls-and-comments.md). This page walks through one pass on a small video. A call is shown as the parameters the tool named above it is given, and every answer below is from a real run, shortened where it says so.

## Before the first edit

The person's wishes come first. Each video has a `brief.md` at its root, which the person writes in the studio's [Brief](/docs/app/brief-and-history.md#the-brief): what they want of the video and the decisions they approved. Read it before changing the video and keep what it settles. Framescript's own pages, these, are in the app at `/framescript/docs`, and an example for every concept at `/framescript/videos/examples`: start from the one closest to the task.

While an agent works, the person sees it: its name stands at the top right of the window, and what it opens or moves to shows there as it happens. The tool `app` shows them what it means, a frame, a step or a comment's thread, and takes a screenshot of the window as they see it.

## The video

A video has this file as `/videos/hello/index.ts`, written with `bash`. A title rises into place letter by letter, as every title does by default, then moves up.

```ts
import {
  add,
  by,
  camera,
  clip,
  input,
  timeline,
  tween,
  video,
  wait,
} from "framescript"
import { rise } from "framescript/motion"
import { text } from "framescript/text"
import * as THREE from "three"

export default video(
  {
    width: 1280,
    height: 720,
    fps: 30,
    inputs: {
      ink: input.color("#ededed", { label: "Ink" }),
      rise: input.slider(0.4, { min: 0, max: 1, step: 0.05, label: "Rise" }),
    },
  },
  timeline(function* ({ stage, inputs }) {
    ;(stage.scene as THREE.Scene).background = new THREE.Color("#0e0e0e")
    const lens = yield* add(new THREE.PerspectiveCamera(32, 16 / 9, 0.1, 100), {
      position: [0, 0, 14],
    })
    yield* camera(lens)
    yield* clip("intro", function* () {
      const title = yield* add(
        text("Hello", { fontSize: 1.2, color: inputs.ink, anchorX: "center" }),
        { position: [0, -0.3, 0] }
      )
      title.name = "title"
      yield* rise(title)
      yield* tween(title.position, { y: by(inputs.rise) }, 0.8)
      yield* wait(0.6)
    })
  })
)
```

## Check

The first draft of this file had no camera, and it moved the title by a fixed `by(0.4)` while still declaring `rise`. Framescript wrote it, since it ran, and `check` said what was wrong:

```json
{ "video": "/videos/hello" }
```

```json
{
  "ok": true,
  "video": "hello",
  "status": "ready",
  "duration": 2.412,
  "frames": 73,
  "diagnostics": [
    {
      "severity": "warning",
      "rule": "input-unread",
      "message": "The input \"rise\" is declared and never read, so turning it changes nothing. Read it in the timeline, or remove it.",
      "site": "hello/index.ts:12:13",
      "span": null,
      "time": 2.412,
      "frame": 72
    },
    {
      "severity": "warning",
      "rule": "no-camera",
      "message": "The video never calls camera(). A default camera is used; add one and make it active with camera(cam).",
      "site": null,
      "span": null,
      "time": 0,
      "frame": 0
    }
  ]
}
```

The line number is the draft's. A diagnostic's `message` says what is wrong and what to do, and its `site` is the `file:line:column` to do it at. Warnings leave `ok` true; an error makes `ok` false and marks the answer as an error. Treat both as work to do: the file above is the draft with both warnings fixed, and it checks clean, with `"diagnostics": []`. The [taste](/docs/framework/taste.md) warnings are strict on purpose and the same: meet the rule, as the library's defaults such as `rise` do, or lift it for one object with `allow` and a reason a person reads. A taste finding names its objects with their lines, its clip and the crop that shows them, and `check` with `shots: true` returns a picture of each, so you see what it points at ([what a finding carries](/docs/framework/taste.md#what-a-finding-carries)).

## Look

Draw frame 30 with `frame`:

```json
{ "video": "/videos/hello", "frame": 30, "out": "out/hello-30.png" }
```

```json
{
  "video": "hello",
  "frame": 30,
  "time": 1,
  "path": "/videos/hello/out/hello-30.png",
  "width": 1280,
  "height": 720,
  "bytes": 26919
}
```

The picture comes back with the answer: read it. Here it shows the word "Hello" in light grey on a dark ground, centred, a little below the middle.

A frame shows where things are, not how they move. To judge an entrance or a camera move, draw the stretch as a contact sheet, each tile labelled with its time and frame: `frame` with `from: 0` and `to: 1.5` ([a stretch as a contact sheet](/docs/framework/agents/frames.md#motion-a-stretch-as-a-contact-sheet-and-a-loop)).

## A comment arrives

A reviewer leaves a comment on the title in the studio. List what is open with `comments`:

```json
{ "video": "/videos/hello", "status": "open" }
```

```json
{
  "comments": [
    {
      "id": "c5eeff7",
      "video": "hello",
      "time": 1.9,
      "point": {
        "x": 0.43,
        "y": 0.58
      },
      "object": {
        "name": "title",
        "site": "hello/index.ts:33:28",
        "at": {
          "x": 0.155,
          "y": 0.511
        }
      },
      "status": "open",
      "author": "Mara",
      "body": "The title ends too low. Bring it up to the middle of the frame.",
      "at": "2026-11-22T17:09:03.229Z",
      "replies": []
    }
  ]
}
```

The thread gives the moment (1.9 s), the point, and the object under it: `title`, added at `hello/index.ts:33`. Look at exactly what the reviewer saw with `frame`, and keep the picture for comparison:

```json
{ "video": "/videos/hello", "comment": "c5eeff7", "crop": "comment", "out": "out/before.png" }
```

```json
{
  "video": "hello",
  "frame": 57,
  "time": 1.9,
  "comment": "c5eeff7",
  "crop": [0.18, 0.32999999999999996, 0.5, 0.5],
  "path": "/videos/hello/out/before.png",
  "width": 640,
  "height": 360,
  "bytes": 11446
}
```

## Trace

The comment already names the object. To learn what decides where it ends, pick a pixel of it at that frame. The point is a share of the frame; `pick` takes pixels, so 0.43 of 1280 is 550 and 0.58 of 720 is 418. Call `inspect`:

```json
{ "video": "/videos/hello", "action": "pick", "frame": 57, "x": 550, "y": 418 }
```

```json
{
  "frame": 57,
  "time": 1.9,
  "x": 550,
  "y": 418,
  "object": {
    "id": "o1",
    "name": "title",
    "type": "Mesh",
    "span": "s4",
    "site": "hello/index.ts:33:28"
  },
  "pointers": [
    {
      "frame": 57,
      "time": 1.9,
      "object": {
        "id": "o1",
        "name": "title",
        "type": "Mesh",
        "span": "s4",
        "site": "hello/index.ts:33:28"
      },
      "path": "position.y",
      "value": 0.10000000000000003,
      "segment": {
        "id": "g6",
        "span": "s14",
        "site": "hello/index.ts:39:14",
        "from": -0.3,
        "to": 0.10000000000000003,
        "start": 1.012,
        "end": 1.812,
        "easing": {
          "name": "easeOut",
          "params": []
        },
        "state": "ended"
      },
      "chain": [
        {
          "id": "s3",
          "kind": "clip",
          "name": "intro",
          "site": "hello/index.ts:32:12"
        }
      ],
      "editable": {
        "to": {
          "class": "computed",
          "range": "hello/index.ts:39:41-39:56",
          "text": "by(inputs.rise)"
        },
        "duration": {
          "class": "literal",
          "range": "hello/index.ts:39:60-39:63",
          "text": "0.8"
        }
      }
    }
  ]
}
```

The pointers for the rise, the line's cut and each letter's move, are cut. This one says: at frame 57 the title's `position.y` is 0.1, put there by the tween on line 39, which ended at 1.812 s inside the clip `intro`. Its end value is `by(inputs.rise)`: a control decides it.

## Change

List the controls with `controls` to see the one to turn, its limits and its line:

```json
{ "video": "/videos/hello" }
```

```json
{
  "video": "hello",
  "controls": [
    {
      "name": "rise",
      "section": null,
      "kind": "slider",
      "label": "Rise",
      "min": 0,
      "max": 1,
      "step": 0.05,
      "default": 0.4,
      "value": 0.4,
      "site": "hello/index.ts:23:13",
      "declared": true,
      "line": "hello/index.ts:23"
    }
  ]
}
```

The control `ink` is cut. Try a value before writing it, as the `inputs` of `frame`. The source stays as it is, and no checkpoint is made.

```json
{ "video": "/videos/hello", "comment": "c5eeff7", "crop": "comment", "inputs": { "rise": 0.9 } }
```

The picture shows the title in the middle. Write the value with `controls`:

```json
{ "video": "/videos/hello", "action": "set", "name": "rise", "value": "0.9" }
```

```json
{
  "ok": true,
  "video": "hello",
  "control": "rise",
  "from": 0.4,
  "to": 0.9,
  "line": "hello/index.ts:23",
  "text": "0.9"
}
```

Line 23 now reads `rise: input.slider(0.9, { min: 0, max: 1, step: 0.05, label: "Rise" }),`. A value outside the limits is refused and nothing is written:

```json
{
  "ok": false,
  "video": "hello",
  "error": "The control \"rise\" must lie from 0 to 1; it is 1.5."
}
```

Then run the loop's first steps again: `check` (clean), and the same `frame` call with `out: "out/after.png"`, to compare with `before.png`.

## Answer

Say what you changed, where, and where to look. Set the thread to `review`, so the reviewer sees it waits for them; resolving it is theirs. Call `comments`:

```json
{
  "video": "/videos/hello",
  "action": "reply",
  "id": "c5eeff7",
  "status": "review",
  "body": "Raised the Rise control from 0.4 to 0.9 (hello/index.ts:23). Frame 57 shows the title in the middle."
}
```

The answer is the thread with the reply in it and `"status": "review"`. The window shows it at once, and `app` with `action: "thread"` opens the thread there for the person.

## Going back

Every change Framescript writes is a checkpoint of the video's [history](/docs/app/brief-and-history.md#history), so a step that went wrong is undone by putting the one before it back. In the video's folder, bash's `history` lists the checkpoints, `checkpoint <message>` makes one by name, such as an approved cut, and `restore <id>` puts one back through the same checks.

## What to prefer

- **A control for anything a person may want to turn.** When someone asks for a dial, declare one input with `input` and a `label`, and read it where it applies. Then they can turn it in the studio, and you can set it with `controls`. See [Inputs and controls](/docs/framework/media/inputs.md).
- **Literals and named constants for the rest.** A pointer's `editable` gives each value a class. A `literal` (`0.8`) and a `linked` value (a constant such as `TIME`) can be changed by the studio; a `computed` one (`BASE * 2`, `(v) => v + 2`) cannot. Write `by(2)`, not a function, and an options object with plain numbers, so that a person can still drag what you wrote. See [Editing by dragging](/docs/app/full-view.md#editing-by-dragging).
- **Change the line the pointer names.** For a `literal`, edit the text at its `range`. For a `linked` value the `range` is the constant's definition, and changing it changes every use.
- **Names on objects.** `title.name = "title"` makes every pointer, pick and comment say which object it means.
- **`check` after every edit**, before looking, also after an edit your own client's tools wrote outside Framescript's: those pass no gate until check runs. A timeline that throws ends at the error, so the frames after it do not exist.
- **Small pictures first.** `scale` 0.5 for the layout, `crop` at full size for a detail, `crop: "comment"` for what a reviewer pointed at.
- **Short pointers in what you write.** "frame 57, `title` `position.y`, `hello/index.ts:39`" is enough for a person to find it.

## See also

- [Connecting an agent](/docs/framework/agents.md) and [The tools an agent has](/docs/framework/agents/tools.md)
- [Checking a video](/docs/framework/agents/checking.md)
- [Reading a video](/docs/framework/agents/reading.md) and [Looking at a frame](/docs/framework/agents/frames.md)
- [Hearing a video](/docs/framework/agents/hearing.md)
- [Controls and comments](/docs/framework/agents/controls-and-comments.md)
- [Inputs and controls](/docs/framework/media/inputs.md)
- [Comments and review](/docs/app/comments.md)
- [Editing by dragging](/docs/app/full-view.md#editing-by-dragging) and [What an edit writes](/docs/framework/studio/editing-source.md)
