Skip to main content
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.
import Anchorbrowser from 'anchorbrowser';

(async () => {
  const anchorClient = new Anchorbrowser({
    apiKey: process.env.ANCHOR_API_KEY
  });

  const response = await anchorClient.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.',
    {
      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);
})();
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)
Human-in-the-loop is most effective when combined with clear system messages that define specific intervention triggers and provide context for decision-making.

Webhooks

Instead of polling the endpoints below, you can subscribe to webhook 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 for setup, Events for the full payload reference, and Signature verification to verify incoming deliveries.

Get Pending Requests

To retrieve pending human intervention requests from the agent, use the GET endpoint:
(async () => {
  const response = await fetch(`https://api.anchorbrowser.io/v1/sessions/${sessionId}/agent/requested-human-intervention`, {
    method: 'GET',
    headers: {
      'anchor-api-key': process.env.ANCHOR_API_KEY
    }
  });

  const data = await response.json();
  console.log('Intervention requests:', data.data.requests);
})();
import requests
import os

response = requests.get(
    f'https://api.anchorbrowser.io/v1/sessions/{session_id}/agent/requested-human-intervention',
    headers={
        'anchor-api-key': os.getenv('ANCHOR_API_KEY')
    }
)

data = response.json()
print('Intervention requests:', data['data']['requests'])

Send Intervention Response

To send a response to a pending human intervention request, use the POST endpoint:
(async () => {
  const response = await fetch(`https://api.anchorbrowser.io/v1/sessions/${sessionId}/agent/respond-to-human-intervention`, {
    method: 'POST',
    headers: {
      'anchor-api-key': process.env.ANCHOR_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      requestId: 'request-id-from-intervention-request',
      response: 'Your response to the agent\'s request'
    })
  });

  const data = await response.json();
  console.log('Response:', data);
})();
import requests
import os

response = requests.post(
    f'https://api.anchorbrowser.io/v1/sessions/{session_id}/agent/respond-to-human-intervention',
    headers={
        'anchor-api-key': os.getenv('ANCHOR_API_KEY'),
        'Content-Type': 'application/json'
    },
    json={
        'requestId': 'request-id-from-intervention-request',
        'response': 'Your response to the agent\'s request'
    }
)

data = response.json()
print('Response:', data)