---
title: "Agents"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/guides/agents"
---
# Agents

Give `runApp` an `agent` and people can let an AI agent use the app while it runs in their terminal:

```ts
import { type Frame, runApp, text } from "tui"
import { agentServer } from "tui/agent"

function view(frame: Frame) {
  text(frame, 0, 0, "Files")
}

runApp({
  view,
  agent: agentServer({ name: "files", allow: (step) => step.component !== "dialog" }),
})
```

The HTML page runs [`examples/driven.ts`](https://github.com/vercel-labs/tui/blob/main/examples/driven.ts) here, in a terminal in the page.

`files mcp` is then an MCP server for the app. Add it to fx, or any agent that takes MCP servers, the way you add any other tool's:

```console
$ fx mcp add files -- files mcp
```

Its two tools drive the app that's running: `snapshot` lists every component that's drawn, with its state, its items, and the actions it takes, along with the screen as text; `act` runs steps through those actions or through keys, like `{ "ref": "Search", "action": "type", "args": ["read"] }`, and returns the changes and a new snapshot. When the app isn't running, a call says to start it. The app only listens on a socket in a directory only you can open.

Every change an agent makes reports the source `"agent"` to the component's change callback, and `allow` decides each step before it runs. A component drawn with `agent: "secret"` reads its values as `"[redacted]"`, and one with `agent: "hidden"` isn't listed.

`tui/agent` has the same `snapshot` and `act` for code of your own: `createAgent(app)` takes what `runApp` or `createTestApp` returns, and `agentTools` describes the two as tools for a model. Only an app that imports `tui/agent` carries its code.
