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

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);
})();

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);
})();