# Agent drives the app

> The tool calls an AI agent makes: read the running app, click and type in it, check its console and edit its files.

Live: https://clientvm.joeldsouza.me/demos/agent-drives-preview/ (Chromium) · Source: https://github.com/Reflex-Gravity/client-vm/blob/main/site/src/demos/agent-drives-preview.ts

This is what an AI app builder does between a model’s turns. Each chip is one tool call from @clientvm/agent-api, made here in the browser exactly as it would be for a model’s tool_use block, and the terminal shows the call and the result the model would get back.

The preview is the agent’s own: preview_snapshot reads it as a text outline with element refs, preview_click and preview_type drive it, and preview_console returns what the page logged. edit_file changes the project, and the next load shows the change.

## How it's built

```ts
import { createAgentTools } from '@clientvm/agent-api';

const tools = createAgentTools({ instance: app, previewContainer });
// send tools.definitions to the model; for each tool_use block it returns:
const result = await tools.call('preview_click', { port: 5050, text: 'Add item' });
```

## Try

- read the page: tool call `preview_snapshot` {"port":5050}
- click “Add item”: tool call `preview_click` {"port":5050,"text":"Add item"}
- fill the form: tool call `preview_type` {"port":5050,"selector":"#name","value":"Ada","submit":true}
- read the console: tool call `preview_console` {"port":5050}
- edit index.html: tool call `edit_file` {"path":"/home/user/app/index.html","old_string":"<h1>Todo</h1>","new_string":"<h1>Edited by the agent</h1>"}
- reload and read: tool call `preview_snapshot` {"port":5050,"path":"/"}

## Built with

@clientvm/agent-api, Node.js 24, driveable preview

## Docs

- [Agent API](https://clientvm.joeldsouza.me/docs/agent-api/)
- [Security model](https://clientvm.joeldsouza.me/docs/security/)
