Manta Developers
GitHub
Menu

Live changes

Let the agent change what your app shows, watch the result, and check it with a picture.

What it is

Some apps show something people give feedback on: a chart, an animation, a layout, a draft. With app tools, the agent can act on that feedback in the page itself. It reads what can be changed, changes it, takes a picture of the result and checks it, while the person watches.

The pattern needs three kinds of tool:

Tool What it does
Read Returns what the agent may change, with the current values and a sentence on each
Change Makes one change through the same code as your controls, so the page updates at once
Look Returns a picture of the result, which the agent sees in its next step

The agent gets no new permissions. It changes only what the tools let it change, and only while the chat is open.

Example

An app shows an animation in a frame, with settings the person can tweak. The frame answers getSettings and setSetting messages, and snapshot with a PNG of its current frame. Three tools lend that to the agent:

import { useMemo } from "react";
import { EmbeddedChat, type AppTools } from "@manta-eu/react/components/embedded-chat";

function useStageTools(stage: StageFrame): AppTools {
  return useMemo(
    () => ({
      readSettings: {
        description:
          "List the animation's settings: each one's path, current value, allowed range and what it does. Read them before changing one.",
        parameters: { type: "object", properties: {} },
        execute: () => stage.request("getSettings"),
      },
      changeSetting: {
        description:
          "Change one setting of the animation. The person sees the change at once. Use a path and a value readSettings listed.",
        parameters: {
          type: "object",
          properties: { path: { type: "string" }, value: {} },
          required: ["path", "value"],
        },
        execute: ({ path, value }: { path: string; value: unknown }) => {
          if (!stage.hasSetting(path)) throw new Error(`There is no setting ${path}.`);
          return stage.request("setSetting", { path, value });
        },
      },
      lookAtStage: {
        description:
          "Take a picture of the animation as it is now. Call it after a change, to check the change looks right.",
        parameters: { type: "object", properties: {} },
        execute: async () => ({ picture: await stage.request<Blob>("snapshot") }),
      },
    }),
    [stage],
  );
}

export function StageCopilot({ stage }: { stage: StageFrame }) {
  return (
    <EmbeddedChat
      user={{ id: "…", email: "you@example.com", name: "You" }}
      isOperator={false}
      appTools={useStageTools(stage)}
    />
  );
}

“Slow the spin down” now reads the settings, changes the speed and looks at the stage. The person sees each step in the chat and the change in the frame.

Keep the rules in the tools

The agent reads each tool’s description to decide when and how to call it. Put your app’s rules there: which tool comes first, what a change may touch, and that it should look again after a change. Check every input in execute as you would a form’s, and throw an error the agent can act on.

Pictures

  • The picture is uploaded to the datastore and shown to the agent; see Returning files for who can upload and the limits.
  • A frame on another origin, such as a sandboxed iframe, has to take its own picture: the page cannot read its pixels. Ask it with postMessage, as in the example. A WebGL canvas needs preserveDrawingBuffer, or the picture taken right after a frame is drawn.
  • Take the picture at the size the person sees, so text and positions match what they pointed at.

Keeping a change

The tools change what the page shows. Keeping it is up to your app: save the settings the way your own controls do, or hand them to your build when a change needs one. A change the agent made is then kept, undone and reviewed like any other.