웹 브라우저 통합
웹 브라우저 통합 (Web browser integration)
LangChain JavaScript로 웹 브라우저 툴과 통합해요.
Webbrowser 툴은 에이전트가 웹사이트를 방문해 정보를 추출할 수 있게 해줘요. 에이전트에게 이렇게 설명돼요:
useful for when you need to find something on or summarize a webpage. input should be a comma separated list of "valid URL including protocol","what you want to find on the page or empty string for a summary".
두 가지 작동 모드를 제공해요:
- 에이전트가 URL만으로 호출하면 웹사이트 콘텐츠의 요약을 생성해요
- 에이전트가 URL과 찾을 내용에 대한 설명으로 호출하면, 인메모리 Vector Store를 사용해 가장 관련성 높은 스니펫을 찾아 그 스니펫들을 요약해요
설정 (Setup)
Webbrowser 툴을 사용하려면 의존성을 설치해야 해요:
npm install cheerio axios
단독 사용법 (Usage, standalone)
import { WebBrowser } from "@langchain/classic/tools/webbrowser";
import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";
export async function run() {
const model = new ChatOpenAI({ model: "gpt-5.4-mini", temperature: 0 });
const embeddings = new OpenAIEmbeddings();
const browser = new WebBrowser({ model, embeddings });
const result = await browser.invoke(
`"https://www.themarginalian.org/2015/04/09/find-your-bliss-joseph-campbell-power-of-myth","who is joseph campbell"`
);
console.log(result);
/*
Joseph Campbell was a mythologist and writer who discussed spirituality, psychological archetypes, cultural myths, and the mythology of self. ...
*/
}
에이전트 내 사용법 (Usage, in an Agent)
import { OpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "@langchain/classic/agents";
import { Calculator } from "@langchain/community/tools/calculator";
import { WebBrowser } from "@langchain/classic/tools/webbrowser";
import { SerpAPI } from "@langchain/community/tools/serpapi";
export const run = async () => {
const model = new OpenAI({ temperature: 0 });
const embeddings = new OpenAIEmbeddings();
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
new WebBrowser({ model, embeddings }),
];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
});
console.log("Loaded agent.");
const input = `What is the word of the day on merriam webster. What is the top result on google for that word`;
console.log(`Executing with input "${input}"...`);
const result = await executor.invoke({ input });
console.log(`Got output ${JSON.stringify(result, null, 2)}`);
};
관련 (Related)
- 툴 개념 가이드
- 툴 how-to 가이드
출처: 문서
본문
Webbrowser 툴은 에이전트가 웹사이트를 방문해 정보를 추출하도록 해요. URL만 주어지면 페이지를 요약하고, URL과 찾을 내용 설명이 함께 주어지면 인메모리 벡터 스토어로 관련 스니펫을 찾아 요약해요. @langchain/classic/tools/webbrowser의 WebBrowser를 모델·임베딩과 함께 인스턴스화해 단독 사용하거나, initializeAgentExecutorWithOptions로 에이전트에 툴로 등록할 수 있어요. cheerio와 axios 설치가 필요해요.