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

> ## Agent Instructions
> Anchor Browser provides cloud browsers for AI agents and automation: stealth browsing with residential proxies, managed authentication into third-party web apps, and browser sessions that run reliably at scale. AI agents that need Anchor credentials should start with https://docs.anchorbrowser.io/quickstart/agent-access. This flow lets agents obtain an API key programmatically without creating a dashboard account. Read that page before attempting authentication or API access.

# Human-in-the-Loop

> Enable human intervention during AI agent task execution

Enabling Human-in-the-loop (HITL) allows the AI agent to pause execution and request human intervention when needed. This feature is essential for tasks that require human judgment, approval, or handling of unexpected situations.

## Basic Usage

### How It Works

When HITL is enabled, the agent sends its intervention requests to a session-specific queue. The agent then continues execution based on your instructions.

<CodeGroup>
  ```javascript node.js theme={null}
  import { client, agentTask } from 'anchorbrowser';

  (async () => {
    client.setConfig({ auth: () => process.env.ANCHOR_API_KEY });

    const response = await agentTask(
      'Research information about Python programming on Wikipedia and create a summary. Ask for human verification if you find any controversial or disputed information.',
      {
        taskOptions: {
          url: 'https://en.wikipedia.org/wiki/Python_(programming_language)',
          humanIntervention: true,
          extendedSystemMessage: 'Request human intervention when you encounter disputed or controversial claims about Python'
        }
      }
    );

    console.log(response);
  })();
  ```

  ```python python theme={null}
  from anchorbrowser import Anchorbrowser
  import os

  anchor_client = Anchorbrowser(api_key=os.environ.get("ANCHOR_API_KEY"))

  response = anchor_client.agent.task(
      'Research information about Python programming on Wikipedia and create a summary. Ask for human verification if you find any controversial or disputed information.',
      task_options={
          'url': 'https://en.wikipedia.org/wiki/Python_(programming_language)',
          'human_intervention': True,
          'extended_system_message': 'Request human intervention when you encounter disputed or controversial claims about Python'
      }
  )

  print(response)
  ```
</CodeGroup>

<Tip>
  Human-in-the-loop is most effective when combined with clear system messages that define specific intervention triggers and provide context for decision-making.
</Tip>

## Webhooks

Instead of polling the endpoints below, you can subscribe to [webhook](/webhooks/overview) events and receive a push notification whenever the agent requests human input.

Subscribe to `intervention.requested` to get notified when the agent pauses — the payload includes the `request_id`, the agent's message, and a `live_view_url` for one-click live takeover. Subscribe to `intervention.resolved` if you need to know when an intervention was answered.

See [Webhooks](/webhooks/overview) for setup, [Events](/webhooks/events) for the full payload reference, and [Signature verification](/webhooks/signature-verification) to verify incoming deliveries.

## Get Pending Requests

To retrieve pending human intervention requests from the agent, use the GET endpoint:

<CodeGroup>
  ```javascript node.js theme={null}
  import { client, Agent } from 'anchorbrowser';

  client.setConfig({ auth: () => process.env.ANCHOR_API_KEY });

  (async () => {
    const data = await Agent.getRequestedHumanIntervention({
      path: { session_id: sessionId }
    });

    console.log('Intervention requests:', data.data.requests);
  })();
  ```

  ```python python theme={null}
  import os
  from anchorbrowser import Anchorbrowser

  anchor_client = Anchorbrowser(api_key=os.getenv('ANCHOR_API_KEY'))

  data = anchor_client.agent.get_requested_human_intervention(session_id)
  print('Intervention requests:', data.data.requests)
  ```
</CodeGroup>

## Send Intervention Response

To send a response to a pending human intervention request, use the POST endpoint:

<CodeGroup>
  ```javascript node.js theme={null}
  import { client, Agent } from 'anchorbrowser';

  client.setConfig({ auth: () => process.env.ANCHOR_API_KEY });

  (async () => {
    const data = await Agent.respondToHumanIntervention({
      path: { session_id: sessionId },
      body: {
        requestId: 'request-id-from-intervention-request',
        response: 'Your response to the agent\'s request'
      }
    });

    console.log('Response:', data);
  })();
  ```

  ```python python theme={null}
  import os
  from anchorbrowser import Anchorbrowser

  anchor_client = Anchorbrowser(api_key=os.getenv('ANCHOR_API_KEY'))

  data = anchor_client.agent.respond_to_human_intervention(
      session_id,
      request_id='request-id-from-intervention-request',
      response="Your response to the agent's request",
  )
  print('Response:', data)
  ```
</CodeGroup>
