> 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_agent.md).

# stagehand\_agent

[Stagehand](https://www.stagehand.dev/) is an autonomous web agent platform that enables AI systems to navigate and interact with websites just like a human would. It provides a powerful solution for automating complex web tasks without requiring custom code or browser automation scripts.

With Stagehand, you can:

* **Automate web navigation**: Enable AI to browse websites, click links, fill forms, and interact with web elements
* **Extract structured data**: Collect specific information from websites in a structured, usable format
* **Complete complex workflows**: Perform multi-step tasks across different websites and web applications
* **Handle authentication**: Navigate login processes and maintain sessions across websites
* **Process dynamic content**: Interact with JavaScript-heavy sites and single-page applications
* **Maintain context awareness**: Keep track of the current state and history while navigating
* **Generate detailed reports**: Receive comprehensive logs of actions taken and data collected

The Agent Forge **Stagehand integration** enables your agents to **seamlessly interact with web-based systems** within their workflows.

This allows for **sophisticated automation** by bridging the gap between your AI agents and the web's vast information and functionality. Agents can search for information, interact with web applications, and extract data, incorporating these capabilities into their decision-making.

By connecting Agent Forge with Stagehand, you can create agents that **navigate the web just like a human**—filling forms, clicking buttons, reading content, and extracting valuable information to complete tasks more effectively, extending beyond traditional API-based integrations.

### Usage Instructions

Use Stagehand to create an autonomous web browsing agent that can navigate across websites, perform tasks, and return structured data.

### Where to Get Your Anthropic API Key (Claude)

Your Anthropic API key is generated and managed through the **Anthropic Console**.

Here is the step-by-step process:

{% stepper %}
{% step %}

### Log in to the Anthropic Console

Navigate to [**console.anthropic.com**](https://console.anthropic.com/) and log in to your developer account. (If you don't have one, you will need to sign up first.)
{% endstep %}

{% step %}

### Navigate to the API Key Section

Once you are in the dashboard, find and click the **"API Keys"** item in the left-hand navigation sidebar.
{% endstep %}

{% step %}

### Generate a New Key

On the API Keys page, click the **"+ Create Key"** button. You will be prompted to give your new key a descriptive name.
{% endstep %}

{% step %}

### Copy and Securely Save the Key

* The key will be displayed **only once** immediately after creation.
* **Critically, copy this full key string and save it** in a secure location (like a password manager or a `.env` file). Anthropic cannot retrieve this key for you later.
* When using the key in your code, it should typically be set as the environment variable **`ANTHROPIC_API_KEY`**.

{% hint style="warning" %}
Before your API key will work for making requests, you generally need to visit the **"Plans & Billing"** section to set up a payment method and purchase an initial amount of credits. New accounts often receive a small credit balance for testing, but you must still complete the billing setup process to activate API usage.
{% endhint %}
{% endstep %}
{% endstepper %}

### Tools

#### `stagehand_agent`

Run an autonomous web agent to complete tasks and extract structured data

**Input**

| Parameter      | Type   | Required | Description                                                                                        |
| -------------- | ------ | -------- | -------------------------------------------------------------------------------------------------- |
| `startUrl`     | string | Yes      | URL of the webpage to start the agent on                                                           |
| `task`         | string | Yes      | The task to complete or goal to achieve on the website                                             |
| `variables`    | json   | No       | Optional variables to substitute in the task (format: {key: value}). Reference in task using %key% |
| `apiKey`       | string | Yes      | OpenAI API key for agent execution (required by Stagehand)                                         |
| `outputSchema` | json   | No       | Optional JSON schema defining the structure of data the agent should return                        |

**Output**

| Parameter          | Type | Description            |
| ------------------ | ---- | ---------------------- |
| `agentResult`      | json | Agent execution result |
| `structuredOutput` | any  | Structured output data |

### Notes

* Category: `tools`
* Type: `stagehand_agent`


---

# 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_agent.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.
