An AI agent that answers questions by searching the web.
Create it locally
$scrapely create my-actor --template js-langgraph-agent
Main file
.JS
src/main.jsimport { HumanMessage } from '@langchain/core/messages';
import { ChatOpenAI } from '@langchain/openai';
import { createAgent } from 'langchain';
import { Actor, log } from 'scrapely';
import { webBrowserTool } from './tools.js';
await Actor.init();
log.info('Charging Actor start event.');
await Actor.charge({ eventName: 'actor-start' });
// LLM calls go through the Scrapely LLM gateway (OpenAI-compatible API, OpenRouter model IDs).
// The run token is used as the API key and token usage is billed to your Scrapely account,
// so no provider API key is needed. If running locally, call `scrapely login` in your terminal first.
const { SCRAPELY_TOKEN } = process.env;
const LLM_BASE_URL = process.env.SCRAPELY_LLM_BASE_URL || 'https://api.scrape.ly/v2/llm/api/v1';
const { query, modelName = 'openai/gpt-4o' } = (await Actor.getInput()) ?? {};
if (!SCRAPELY_TOKEN) {
throw new Error(
'Please configure the SCRAPELY_TOKEN environment variable. Call `scrapely login` in your terminal.',
);
}
const llm = new ChatOpenAI({
temperature: 0,
model: modelName,
apiKey: SCRAPELY_TOKEN,
configuration: { baseURL: LLM_BASE_URL },
});
const agent = createAgent({
model: llm,
tools: [webBrowserTool],
systemPrompt:
'You are a helpful research assistant. When the question refers to a web page or website, ' +
'use the browse_web_page tool to read it and base your answer on its content. Cite the URLs you used.',
});
log.info('Starting agent...');
const agentFinalState = await agent.invoke(
{ messages: [new HumanMessage(query)] },
{ configurable: { thread_id: '1' } },
);
if (!agentFinalState?.messages?.length) {
throw new Error('Agent did not return a valid response.');
}
const answer = agentFinalState.messages.at(-1).content;
log.info(`Question: ${query}`);
log.info(`Agent response: ${answer}`);
log.info(`Number of messages: ${agentFinalState.messages.length}`);
log.info('Pushing data to the dataset');
await Actor.pushData({ question: query, answer });
log.info('Charging for task completion');
await Actor.charge({ eventName: 'task-completed' });
await Actor.exit();
JavaScript web research agent (LangGraph)
An AI agent that answers questions by reading web pages with a built-in browsing tool.
Included features
- Scrapely SDK — Actor lifecycle, input, storage and proxies
- LangGraph — agent workflows
- Scrapely LLM gateway — call OpenRouter models with the run token; usage is billed to your Scrapely account, no provider API key needed
- Input schema — define and validate the Actor's input (
.actor/input_schema.json) - Dataset schema — structured results with a preview view (
.actor/dataset_schema.json)
Getting started locally
npm install
npm run start # run the Actor
LLM calls go to SCRAPELY_LLM_BASE_URL (set automatically on the platform) with the run's
SCRAPELY_TOKEN, so the agent works inside a Scrapely run without any provider API key.
Deploying to Scrapely
Create an Actor from this template in the Scrapely Console (Develop new → template → Git). Scrapely creates a repository in your account, pushes this code, and builds the Actor. Every push to your repository triggers a new build.