> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserwire.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Integration

> How to connect BrowserWire's discovered APIs to AI agents and automation scripts.

Once you've recorded and trained a site, BrowserWire serves its views and actions as REST endpoints via `bw run`. You can call these from any AI agent, automation script, or HTTP client.

## Working with the local API

### List discovered sites

Start by confirming which sites are available:

```bash theme={null}
curl http://127.0.0.1:8787/api/sites
```

```json theme={null}
[
  {
    "id": "mf_abc123",
    "domain": "example.com",
    "slug": "example-com",
    "stateCount": 4,
    "viewCount": 3,
    "actionCount": 7
  }
]
```

### Get the full manifest

Fetch the manifest to see all states, views, and actions:

```bash theme={null}
curl http://127.0.0.1:8787/api/sites/example-com/manifest
```

The manifest contains every state with its views and actions, including their input schemas. You can pass this to an LLM as context so it knows what operations are available.

### Call operations

<CodeGroup>
  ```bash View (read data) theme={null}
  # Views use GET — reads structured data from a page state
  curl http://127.0.0.1:8787/api/sites/example-com/views/HomePage/product_list
  ```

  ```bash Action (perform interaction) theme={null}
  # Actions use POST — executes an interaction on the page
  curl -X POST http://127.0.0.1:8787/api/sites/example-com/actions/LoginPage/submit_login \
    -H "Content-Type: application/json" \
    -d '{"email": "user@example.com", "password": "secret"}'
  ```
</CodeGroup>

## URL pattern

All endpoints follow this pattern:

```
/api/sites/{slug}/views/{state}/{viewName}     # GET
/api/sites/{slug}/actions/{state}/{actionName}  # POST
```

* **slug** — site identifier (e.g., `example-com`)
* **state** — page state name from the manifest (e.g., `HomePage`, `LoginPage`)
* **viewName** / **actionName** — the specific view or action within that state

## Feeding to an LLM agent

A practical approach for tool-using LLMs:

1. Fetch the manifest: `GET /api/sites/{slug}/manifest`
2. Extract the list of states, views, and actions into a tool schema
3. Let the LLM decide which endpoints to call based on the user's request
4. Execute the chosen endpoint and return the result

```python theme={null}
import requests

# Fetch manifest
manifest = requests.get("http://127.0.0.1:8787/api/sites/example-com/manifest").json()

# Build tool descriptions from states
tools = []
for state in manifest["states"]:
    for view in state.get("views", []):
        tools.append({
            "name": f"read_{state['name']}_{view['name']}",
            "description": f"Read {view['name']} from {state['name']}",
            "endpoint": f"GET /api/sites/example-com/views/{state['name']}/{view['name']}"
        })
    for action in state.get("actions", []):
        tools.append({
            "name": f"do_{state['name']}_{action['name']}",
            "description": f"Execute {action['name']} on {state['name']}",
            "inputs": action.get("inputs", []),
            "endpoint": f"POST /api/sites/example-com/actions/{state['name']}/{action['name']}"
        })

# Pass `tools` to your LLM as available functions
```

## Response format

All endpoints return JSON with an `ok` field:

**Success (view):**

```json theme={null}
{
  "ok": true,
  "data": [ ... ],
  "state": "HomePage",
  "steps": ["navigate:https://example.com/", "view:product_list"]
}
```

**Success (action):**

```json theme={null}
{
  "ok": true,
  "state": "DashboardPage",
  "steps": ["navigate:https://example.com/login", "action:submit_login"]
}
```

**Error:**

```json theme={null}
{
  "error": "Action 'submit_login' failed: element not found"
}
```

## CORS

The local server includes permissive CORS headers:

```
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
```

You can call the API directly from browser-based agents or frontends without proxy configuration.

<Note>
  The server listens on `127.0.0.1` by default (local only). The `bw run` command does not currently support a `--host` flag — it always binds to localhost.
</Note>
