# Your first agent action · Booki

> Mount a React button, find it through Booki’s bridge and run the same action a person can take. Try the example in your browser.

Source: https://booki.dev/docs/first-action

# Your first agent action

Give a person and an agent the same task button. Click it once, then ask the bridge to press it. Both presses update the counter through one React handler.

## Try it here

Use this live example and your browser console.

Tasks added 0

Click Add task. With the counter at 1, run this in the browser console.

```javascript
const button = window.agent.snapshot().find(
  (entry) => entry.label === "Add task" && entry.actions.includes("press")
)
if (!button) throw new Error("Open the page with the task button")

const result = await window.agent.act({
  steps: [{ ref: button.ref, action: "press", args: [] }],
})
console.log(result)
```

The result has `ok: true`. The counter now reads 2. The snapshot supplied the current button reference and its supported action.

## Run it in your app

Start in a Vite React 19+ TypeScript app.

Install the packages using the pinned versions in the [installation guide](https://booki.dev/docs/installation#install). Save the two files below and start the app’s dev server.

```jsx
import { Button } from "@booki-aui/react";
import { useState } from "react";

export function TaskButton({ label, totalLabel }: { label: string; totalLabel: string }) {
  const [count, setCount] = useState(0);
  return (
    <div>
      <Button onClick={() => setCount((previous) => previous + 1)}>{label}</Button>
      <p role="status">
        {totalLabel} {count}
      </p>
    </div>
  );
}
```

```jsx
import { createBookiAgent } from "@booki-aui/react"
import { createRoot } from "react-dom/client"
import { TaskButton } from "./task-button"
import "@booki-aui/styles"

const agent = createBookiAgent({ agentId: "assistant" })
if (import.meta.env.DEV) Object.assign(window, { agent })

createRoot(document.getElementById("root")!).render(
  <TaskButton label="Add task" totalLabel="Tasks added" />
)
```

Open the local page and repeat the console example. The bridge is created before the button mounts. The dev-only assignment lets you inspect it in the console.

## Troubleshooting

`window.agent` is undefined

Run the example in the browser console of this guide or in your local Vite dev server. Check that your main entry creates the bridge and exposes it in development.

The button is missing from the snapshot

Check that the Booki Button is mounted and the label matches the current language. Read a fresh snapshot after navigating or remounting the control.

An action was refused

Read `result.error.message` when `result.ok === false`. Use an action listed for the current control. For an action reserved for a person, hand the decision back to them.

Next, inspect the [button reference](https://booki.dev/docs/button) or add [confirmation and person-only actions](https://booki.dev/docs/installation#approval).
