Google 통합
Google 통합 (Google integration)
LangChain JavaScript로 Google Gemini 툴과 통합해요.
@langchain/google 패키지는 Gemini의 내장 툴을 지원해요. 여기에는 웹 검색 grounding, 코드 실행, URL 컨텍스트 검색 등의 기능이 포함돼요. 이러한 툴은 bindTools() 또는 tools 호출 옵션을 통해 Gemini 네이티브 객체로 ChatGoogle에 전달돼요.
Google Search
googleSearch 툴은 실시간 Google 검색 결과로 모델 응답에 grounding을 제공해요. 최신 뉴스나 특정 사실에 대한 질문에 유용해요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
googleSearch: {},
},
]);
const res = await llm.invoke("Who won the latest World Series?");
console.log(res.text);
검색 결과를 특정 시간 범위로 선택적으로 필터링할 수 있어요:
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
googleSearch: {
timeRangeFilter: {
startTime: "2025-01-01T00:00:00Z",
endTime: "2025-12-31T23:59:59Z",
},
},
},
]);
자세한 내용은 Google의 Grounding with Google Search 문서를 참고하세요.
코드 실행 (Code execution)
codeExecution 툴은 Gemini가 복잡한 문제를 해결하기 위해 Python 코드를 생성하고 실행할 수 있게 해줘요. 모델이 코드를 작성하고, 실행하고, 결과를 반환해요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
codeExecution: {},
},
]);
const res = await llm.invoke("Calculate the 100th Fibonacci number.");
console.log(res.contentBlocks);
응답에는 생성된 코드와 실행 결과가 모두 contentBlocks 필드에 포함돼요:
for (const block of res.contentBlocks) {
if (block.type === "tool_code") {
console.log("Code:", block.toolCode);
} else if (block.type === "tool_result") {
console.log("Result:", block.toolResult);
}
}
자세한 내용은 Google의 Code Execution 문서를 참고하세요.
URL 컨텍스트 (URL context)
urlContext 툴은 Gemini가 URL에서 콘텐츠를 가져와 사용해 응답에 grounding을 제공할 수 있게 해줘요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
urlContext: {},
},
]);
const res = await llm.invoke("Summarize this page: https://js.langchain.com/");
console.log(res.text);
자세한 내용은 Google의 URL Context 문서를 참고하세요.
Google Maps
googleMaps 툴은 Google Maps의 지리공간 컨텍스트로 응답에 grounding을 제공해요. 장소 관련 질문에 유용해요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
googleMaps: {},
},
]);
const res = await llm.invoke("What are the best coffee shops near Times Square?");
console.log(res.text);
Google Maps 위젯을 렌더링하기 위한 위젯 컨텍스트 토큰을 활성화할 수 있어요:
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
googleMaps: {
enableWidget: true,
},
},
]);
const res = await llm.invoke("Find Italian restaurants in downtown Chicago");
// Access the widget context token from grounding metadata
const groundingMetadata = res.response_metadata?.groundingMetadata;
console.log(groundingMetadata?.googleMapsWidgetContextToken);
자세한 내용은 Google의 Google Maps grounding 문서를 참고하세요.
파일 검색 (File search)
fileSearch 툴은 파일 검색 스토어에서 의미론적 검색(semantic retrieval)을 수행해요. 파일은 먼저 Gemini File API를 사용해 가져와야 해요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
fileSearch: {
fileSearchStoreNames: ["fileSearchStores/my-store-123"],
},
},
]);
const res = await llm.invoke("What does the report say about Q4 revenue?");
console.log(res.text);
구성 옵션:
fileSearchStoreNames(필수) -- 검색할 파일 검색 스토어의 이름metadataFilter(선택) -- 검색에 적용할 메타데이터 필터topK(선택) -- 반환할 의미론적 검색 청크의 개수
자세한 내용은 Google의 File Search 문서를 참고하세요.
컴퓨터 사용 (Computer use)
computerUse 툴은 Gemini가 브라우저 환경과 상호작용할 수 있게 해줘요. 모델이 스크린샷을 보고 클릭, 타이핑, 스크롤 같은 동작을 수행할 수 있어요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
computerUse: {
environment: "ENVIRONMENT_BROWSER",
},
},
]);
구성 옵션:
environment(필수) -- 운영 중인 환경 (예:"ENVIRONMENT_BROWSER")excludedPredefinedFunctions(선택) -- 액션 공간에서 제외할 사전 정의된 함수
자세한 내용은 Google의 Computer Use 문서를 참고하세요.
MCP 서버
mcpServers 필드는 Gemini가 원격 MCP(Model Context Protocol) 서버에 연결할 수 있게 해줘요. 다른 네이티브 툴과 달리 MCP 서버는 툴 객체의 배열로 지정돼요.
import { ChatGoogle } from "@langchain/google";
const llm = new ChatGoogle("gemini-2.5-flash")
.bindTools([
{
mcpServers: [
{
name: "my-mcp-server",
streamableHttpTransport: {
url: "https://my-mcp-server.example.com/mcp",
},
},
],
},
]);
const res = await llm.invoke("Use the tools from the MCP server to help me.");
console.log(res.text);
자세한 내용은 Google의 MCP 문서를 참고하세요.
Gemini Enterprise Agent Platform 데이터스토어의 Agent Search
Gemini Enterprise Agent Platform(platformType: "gcp")을 사용한다면 Agent Search 데이터스토어로 응답에 grounding을 제공할 수 있어요.
import { ChatGoogle } from "@langchain/google";
const projectId = "YOUR_PROJECT_ID";
const datastoreId = "YOUR_DATASTORE_ID";
const llm = new ChatGoogle({
model: "gemini-2.5-pro",
platformType: "gcp",
}).bindTools([
{
retrieval: {
vertexAiSearch: {
datastore: `projects/${projectId}/locations/global/collections/default_collection/dataStores/${datastoreId}`,
},
disableAttribution: false,
},
},
]);
const res = await llm.invoke(
"What is the score of Argentina vs Bolivia football game?"
);
console.log(res.text);
자세한 내용은 Google의 Agent Search grounding 문서를 참고하세요.
출처: 문서
본문
@langchain/google 패키지는 Gemini의 내장 툴(googleSearch, codeExecution, urlContext, googleMaps, fileSearch, computerUse, mcpServers, 그리고 GCP 플랫폼의 vertexAiSearch 기반 retrieval)을 지원해요. 이 툴들은 bindTools()나 tools 호출 옵션을 통해 Gemini 네이티브 객체로 전달하며, Gemini 네이티브 툴과 표준 LangChain 툴을 같은 요청에 섞을 수는 없어요. 각 툴은 모델 응답에 검색·지리공간·파일·브라우저 컨텍스트를 grounding하는 역할을 해요.