> For the complete documentation index, see [llms.txt](https://whitepaper.aitech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.aitech.io/agentforge/tools/stagehand.md).

# stagehand

[Stagehand](https://stagehand.com/) is a tool that allows you to extract structured data from webpages using Browserbase and OpenAI.

With Stagehand, you can:

* **Extract structured data**: Extract structured data from webpages using Browserbase and OpenAI
* **Save data to a database**: Save the extracted data to a database
* **Automate workflows**: Automate workflows to extract data from webpages

In Agent Forge, the Stagehand integration enables your agents to extract structured data from webpages using Browserbase and OpenAI. The extracted data to a database, and automate workflows to extract data from webpages.

This integration bridges the gap between your AI workflows and your data management system, enabling seamless data extraction and integration.

By connecting Agent Forge with Stagehand, you can automate data extraction processes, maintain up-to-date information repositories, generate reports, and organize information intelligently - all through your intelligent agents.

### Usage Instructions

Use Stagehand to extract structured data from webpages using Browserbase and OpenAI.

### Where to Get Your OpenAI API Key

You can find and generate your API keys through the **OpenAI Platform dashboard**.

Here is the simple, step-by-step process:

{% stepper %}
{% step %}

### Log in to the OpenAI Platform

Navigate to the [**OpenAI Platform website**](https://platform.openai.com/) and log in to your account.
{% endstep %}

{% step %}

### Access the Key Management Page

* Click on your **profile icon** (usually in the top-right corner).
* From the dropdown menu, select **"View API keys."**
  {% endstep %}

{% step %}

### Generate a New Key

* Click the **"+ Create new secret key"** button.
* Give your key a descriptive name and click "Create secret key."
  {% endstep %}

{% step %}

### Copy and Securely Save the Key

* **Your Secret Key is shown only once.** Copy the entire key string immediately and store it securely (e.g., in a password manager or your project's `.env` file).
* If you lose the key, you will have to generate a new one, as it cannot be retrieved.
  {% endstep %}
  {% endstepper %}

### Tools

#### `stagehand_extract`

Extract structured data from a webpage using Stagehand

**Input**

| Parameter     | Type   | Required | Description                                               |
| ------------- | ------ | -------- | --------------------------------------------------------- |
| `url`         | string | Yes      | URL of the webpage to extract data from                   |
| `instruction` | string | Yes      | Instructions for extraction                               |
| `apiKey`      | string | Yes      | OpenAI API key for extraction (required by Stagehand)     |
| `schema`      | json   | Yes      | JSON schema defining the structure of the data to extract |

**Output**

| Parameter | Type | Description    |
| --------- | ---- | -------------- |
| `data`    | json | Extracted data |

### Notes

* Category: `tools`
* Type: `stagehand`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.aitech.io/agentforge/tools/stagehand.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
