Agent Deep Research ของ Gemini จะวางแผน ดำเนินการ และสังเคราะห์งานค้นคว้าหาข้อมูลแบบหลายขั้นตอนโดยอัตโนมัติ ฟีเจอร์นี้ทำงานด้วย Gemini 3 Pro โดยจะสำรวจข้อมูลที่ซับซ้อน โดยใช้การค้นเว็บและข้อมูลของคุณเองเพื่อสร้างรายงานแบบละเอียด ที่มีการอ้างอิง
งานค้นคว้าข้อมูลเกี่ยวข้องกับการค้นหาและการอ่านซ้ำๆ และอาจใช้เวลาหลายนาทีจึงจะเสร็จสมบูรณ์ คุณต้องใช้การดำเนินการในเบื้องหลัง (ตั้งค่า background=true)
เพื่อเรียกใช้เอเจนต์แบบอะซิงโครนัสและสำรวจผลลัพธ์ ดูรายละเอียดเพิ่มเติมได้ที่การจัดการงานที่ใช้เวลานาน
ตัวอย่างต่อไปนี้แสดงวิธีเริ่มงานวิจัยในเบื้องหลัง และสำรวจผลลัพธ์
Python
import time
from google import genai
client = genai.Client()
interaction = client.interactions.create(
input="Research the history of Google TPUs.",
agent='deep-research-pro-preview-12-2025',
background=True
)
print(f"Research started: {interaction.id}")
while True:
interaction = client.interactions.get(interaction.id)
if interaction.status == "completed":
print(interaction.outputs[-1].text)
break
elif interaction.status == "failed":
print(f"Research failed: {interaction.error}")
break
time.sleep(10)
JavaScript
import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
input: 'Research the history of Google TPUs.',
agent: 'deep-research-pro-preview-12-2025',
background: true
});
console.log(`Research started: ${interaction.id}`);
while (true) {
const result = await client.interactions.get(interaction.id);
if (result.status === 'completed') {
console.log(result.outputs[result.outputs.length - 1].text);
break;
} else if (result.status === 'failed') {
console.log(`Research failed: ${result.error}`);
break;
}
await new Promise(resolve => setTimeout(resolve, 10000));
}
REST
# 1. Start the research task
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Research the history of Google TPUs.",
"agent": "deep-research-pro-preview-12-2025",
"background": true
}'
# 2. Poll for results (Replace INTERACTION_ID)
# curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/INTERACTION_ID" \
# -H "x-goog-api-key: $GEMINI_API_KEY"
ค้นคว้าด้วยข้อมูลของคุณเอง
Deep Research มีสิทธิ์เข้าถึงเครื่องมือต่างๆ โดยค่าเริ่มต้น เอเจนต์จะมีสิทธิ์เข้าถึง
ข้อมูลบนอินเทอร์เน็ตสาธารณะโดยใช้เครื่องมือ google_search และ url_context
คุณไม่จำเป็นต้องระบุเครื่องมือเหล่านี้โดยค่าเริ่มต้น อย่างไรก็ตาม หากคุณต้องการให้ตัวแทนเข้าถึงข้อมูลของคุณเองด้วยโดยใช้เครื่องมือค้นหาไฟล์ คุณจะต้องเพิ่มเครื่องมือดังกล่าวตามที่แสดงในตัวอย่างต่อไปนี้
Python
import time
from google import genai
client = genai.Client()
interaction = client.interactions.create(
input="Compare our 2025 fiscal year report against current public web news.",
agent="deep-research-pro-preview-12-2025",
background=True,
tools=[
{
"type": "file_search",
"file_search_store_names": ['fileSearchStores/my-store-name']
}
]
)
JavaScript
const interaction = await client.interactions.create({
input: 'Compare our 2025 fiscal year report against current public web news.',
agent: 'deep-research-pro-preview-12-2025',
background: true,
tools: [
{ type: 'file_search', file_search_store_names: ['fileSearchStores/my-store-name'] },
]
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Compare our 2025 fiscal year report against current public web news.",
"agent": "deep-research-pro-preview-12-2025",
"background": true,
"tools": [
{"type": "file_search", "file_search_store_names": ["fileSearchStores/my-store-name"]},
]
}'
การควบคุมและการจัดรูปแบบ
คุณสามารถควบคุมเอาต์พุตของเอเจนต์ได้โดยระบุวิธีการจัดรูปแบบที่เฉพาะเจาะจง ในพรอมต์ ซึ่งจะช่วยให้คุณจัดโครงสร้างรายงานเป็นส่วนและส่วนย่อยที่เฉพาะเจาะจง รวมถึงใส่ตารางข้อมูลหรือปรับโทนสำหรับกลุ่มเป้าหมายต่างๆ ได้ (เช่น "เทคนิค" "ผู้บริหาร" "ลำลอง")
กำหนดรูปแบบเอาต์พุตที่ต้องการอย่างชัดเจนในข้อความอินพุต
Python
prompt = """
Research the competitive landscape of EV batteries.
Format the output as a technical report with the following structure:
1. Executive Summary
2. Key Players (Must include a data table comparing capacity and chemistry)
3. Supply Chain Risks
"""
interaction = client.interactions.create(
input=prompt,
agent="deep-research-pro-preview-12-2025",
background=True
)
JavaScript
const prompt = `
Research the competitive landscape of EV batteries.
Format the output as a technical report with the following structure:
1. Executive Summary
2. Key Players (Must include a data table comparing capacity and chemistry)
3. Supply Chain Risks
`;
const interaction = await client.interactions.create({
input: prompt,
agent: 'deep-research-pro-preview-12-2025',
background: true,
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Research the competitive landscape of EV batteries.\n\nFormat the output as a technical report with the following structure: \n1. Executive Summary\n2. Key Players (Must include a data table comparing capacity and chemistry)\n3. Supply Chain Risks",
"agent": "deep-research-pro-preview-12-2025",
"background": true
}'
การจัดการงานที่ใช้เวลานาน
Deep Research เป็นกระบวนการแบบหลายขั้นตอนที่เกี่ยวข้องกับการวางแผน การค้นหา การอ่าน และการเขียน โดยปกติแล้ววงจรนี้จะเกินขีดจำกัดการหมดเวลามาตรฐานของการเรียก API แบบซิงโครนัส
ตัวแทนต้องใช้ background=True API จะแสดงผลออบเจ็กต์ Partial
Interaction ทันที คุณใช้พร็อพเพอร์ตี้ id เพื่อดึงข้อมูล
การโต้ตอบสำหรับการทำโพลได้ สถานะการโต้ตอบจะเปลี่ยนจาก
in_progress เป็น completed หรือ failed
สตรีมมิง
Deep Research รองรับการสตรีมเพื่อรับข้อมูลอัปเดตแบบเรียลไทม์เกี่ยวกับความคืบหน้าในการค้นคว้า
คุณต้องตั้งค่า stream=True และ background=True
ตัวอย่างต่อไปนี้แสดงวิธีเริ่มงานวิจัยและประมวลผลสตรีม
ที่สำคัญคือวิดีโอนี้แสดงวิธีติดตาม interaction_id จาก
interaction.start เหตุการณ์ คุณจะต้องใช้รหัสนี้เพื่อเริ่มสตรีมต่อหาก
เครือข่ายหยุดชะงัก โค้ดนี้ยังแนะนำตัวแปร event_id
ซึ่งช่วยให้คุณกลับมาทำงานต่อจากจุดที่ยกเลิกการเชื่อมต่อได้
Python
stream = client.interactions.create(
input="Research the history of Google TPUs.",
agent="deep-research-pro-preview-12-2025",
background=True,
stream=True,
agent_config={
"type": "deep-research",
"thinking_summaries": "auto"
}
)
interaction_id = None
last_event_id = None
for chunk in stream:
if chunk.event_type == "interaction.start":
interaction_id = chunk.interaction.id
print(f"Interaction started: {interaction_id}")
if chunk.event_id:
last_event_id = chunk.event_id
if chunk.event_type == "content.delta":
if chunk.delta.type == "text":
print(chunk.delta.text, end="", flush=True)
elif chunk.delta.type == "thought_summary":
print(f"Thought: {chunk.delta.content.text}", flush=True)
elif chunk.event_type == "interaction.complete":
print("\nResearch Complete")
JavaScript
const stream = await client.interactions.create({
input: 'Research the history of Google TPUs.',
agent: 'deep-research-pro-preview-12-2025',
background: true,
stream: true,
agent_config: {
type: 'deep-research',
thinking_summaries: 'auto'
}
});
let interactionId;
let lastEventId;
for await (const chunk of stream) {
// 1. Capture Interaction ID
if (chunk.event_type === 'interaction.start') {
interactionId = chunk.interaction.id;
console.log(`Interaction started: ${interactionId}`);
}
// 2. Track IDs for potential reconnection
if (chunk.event_id) lastEventId = chunk.event_id;
// 3. Handle Content
if (chunk.event_type === 'content.delta') {
if (chunk.delta.type === 'text') {
process.stdout.write(chunk.delta.text);
} else if (chunk.delta.type === 'thought_summary') {
console.log(`Thought: ${chunk.delta.content.text}`);
}
} else if (chunk.event_type === 'interaction.complete') {
console.log('\nResearch Complete');
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Research the history of Google TPUs.",
"agent": "deep-research-pro-preview-12-2025",
"background": true,
"stream": true,
"agent_config": {
"type": "deep-research",
"thinking_summaries": "auto"
}
}'
# Note: Look for the 'interaction.start' event to get the interaction ID.
กำลังเชื่อมต่อสตรีมอีกครั้ง
การหยุดชะงักของเครือข่ายอาจเกิดขึ้นระหว่างงานวิจัยที่ใช้เวลานาน หากต้องการจัดการ
ปัญหานี้อย่างราบรื่น แอปพลิเคชันควรตรวจหาข้อผิดพลาดในการเชื่อมต่อและกลับมา
สตรีมต่อโดยใช้ client.interactions.get()
คุณต้องระบุค่า 2 ค่าเพื่อดำเนินการต่อ ดังนี้
- รหัสการโต้ตอบ: ได้รับจากเหตุการณ์
interaction.startใน สตรีมเริ่มต้น - รหัสเหตุการณ์ล่าสุด: รหัสของเหตุการณ์ที่ประมวลผลสำเร็จล่าสุด ซึ่งจะบอกให้เซิร์ฟเวอร์กลับมาส่งเหตุการณ์หลังจากจุดที่เฉพาะเจาะจงนั้น หากไม่ได้ระบุ คุณจะได้รับจุดเริ่มต้นของสตรีม
ตัวอย่างต่อไปนี้แสดงรูปแบบที่ยืดหยุ่น นั่นคือ การพยายามสตรีมคำขอ create เริ่มต้น และกลับไปใช้ลูป get หากการเชื่อมต่อขาดหายไป
Python
import time
from google import genai
client = genai.Client()
# Configuration
agent_name = 'deep-research-pro-preview-12-2025'
prompt = 'Compare golang SDK test frameworks'
# State tracking
last_event_id = None
interaction_id = None
is_complete = False
def process_stream(event_stream):
"""Helper to process events from any stream source."""
global last_event_id, interaction_id, is_complete
for event in event_stream:
# Capture Interaction ID
if event.event_type == "interaction.start":
interaction_id = event.interaction.id
print(f"Interaction started: {interaction_id}")
# Capture Event ID
if event.event_id:
last_event_id = event.event_id
# Print content
if event.event_type == "content.delta":
if event.delta.type == "text":
print(event.delta.text, end="", flush=True)
elif event.delta.type == "thought_summary":
print(f"Thought: {event.delta.content.text}", flush=True)
# Check completion
if event.event_type in ['interaction.complete', 'error']:
is_complete = True
# 1. Attempt initial streaming request
try:
print("Starting Research...")
initial_stream = client.interactions.create(
input=prompt,
agent=agent_name,
background=True,
stream=True,
agent_config={
"type": "deep-research",
"thinking_summaries": "auto"
}
)
process_stream(initial_stream)
except Exception as e:
print(f"\nInitial connection dropped: {e}")
# 2. Reconnection Loop
# If the code reaches here and is_complete is False, we resume using .get()
while not is_complete and interaction_id:
print(f"\nConnection lost. Resuming from event {last_event_id}...")
time.sleep(2)
try:
resume_stream = client.interactions.get(
id=interaction_id,
stream=True,
last_event_id=last_event_id
)
process_stream(resume_stream)
except Exception as e:
print(f"Reconnection failed, retrying... ({e})")
JavaScript
let lastEventId;
let interactionId;
let isComplete = false;
// Helper to handle the event logic
const handleStream = async (stream) => {
for await (const chunk of stream) {
if (chunk.event_type === 'interaction.start') {
interactionId = chunk.interaction.id;
}
if (chunk.event_id) lastEventId = chunk.event_id;
if (chunk.event_type === 'content.delta') {
if (chunk.delta.type === 'text') {
process.stdout.write(chunk.delta.text);
} else if (chunk.delta.type === 'thought_summary') {
console.log(`Thought: ${chunk.delta.content.text}`);
}
} else if (chunk.event_type === 'interaction.complete') {
isComplete = true;
}
}
};
// 1. Start the task with streaming
try {
const stream = await client.interactions.create({
input: 'Compare golang SDK test frameworks',
agent: 'deep-research-pro-preview-12-2025',
background: true,
stream: true,
agent_config: {
type: 'deep-research',
thinking_summaries: 'auto'
}
});
await handleStream(stream);
} catch (e) {
console.log('\nInitial stream interrupted.');
}
// 2. Reconnect Loop
while (!isComplete && interactionId) {
console.log(`\nReconnecting to interaction ${interactionId} from event ${lastEventId}...`);
try {
const stream = await client.interactions.get(interactionId, {
stream: true,
last_event_id: lastEventId
});
await handleStream(stream);
} catch (e) {
console.log('Reconnection failed, retrying in 2s...');
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
REST
# 1. Start the research task (Initial Stream)
# Watch for event: interaction.start to get the INTERACTION_ID
# Watch for "event_id" fields to get the LAST_EVENT_ID
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Compare golang SDK test frameworks",
"agent": "deep-research-pro-preview-12-2025",
"background": true,
"stream": true,
"agent_config": {
"type": "deep-research",
"thinking_summaries": "auto"
}
}'
# ... Connection interrupted ...
# 2. Reconnect (Resume Stream)
# Pass the INTERACTION_ID and the LAST_EVENT_ID you saved.
curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/INTERACTION_ID?stream=true&last_event_id=LAST_EVENT_ID&alt=sse" \
-H "x-goog-api-key: $GEMINI_API_KEY"
คำถามติดตามผลและการโต้ตอบ
คุณสนทนาต่อได้หลังจากที่ตัวแทนส่งรายงานสุดท้ายกลับมาโดยใช้previous_interaction_id ซึ่งช่วยให้คุณขอคำชี้แจง
สรุป หรือขยายความในส่วนที่เฉพาะเจาะจงของงานวิจัยได้โดยไม่ต้อง
เริ่มงานทั้งหมดใหม่
Python
import time
from google import genai
client = genai.Client()
interaction = client.interactions.create(
input="Can you elaborate on the second point in the report?",
model="gemini-3-pro-preview",
previous_interaction_id="COMPLETED_INTERACTION_ID"
)
print(interaction.outputs[-1].text)
JavaScript
const interaction = await client.interactions.create({
input: 'Can you elaborate on the second point in the report?',
agent: 'deep-research-pro-preview-12-2025',
previous_interaction_id: 'COMPLETED_INTERACTION_ID'
});
console.log(interaction.outputs[-1].text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"input": "Can you elaborate on the second point in the report?",
"agent": "deep-research-pro-preview-12-2025",
"previous_interaction_id": "COMPLETED_INTERACTION_ID"
}'
กรณีที่ควรใช้เอเจนต์ Gemini Deep Research
Deep Research เป็นเอเจนต์ ไม่ใช่แค่โมเดล เหมาะที่สุดสำหรับภาระงาน ที่ต้องใช้แนวทาง "นักวิเคราะห์ในกล่อง" มากกว่าแชทที่มีเวลาในการตอบสนองต่ำ
| ฟีเจอร์ | โมเดล Gemini มาตรฐาน | เอเจนต์ Deep Research ของ Gemini |
|---|---|---|
| เวลาในการตอบสนอง | วินาที | นาที (ไม่พร้อมกัน/เบื้องหลัง) |
| กระบวนการ | สร้าง -> เอาต์พุต | วางแผน -> ค้นหา -> อ่าน -> ทำซ้ำ -> ผลลัพธ์ |
| เอาต์พุต | ข้อความสนทนา โค้ด สรุปสั้นๆ | รายงานโดยละเอียด การวิเคราะห์แบบยาว ตารางเปรียบเทียบ |
| เหมาะสำหรับ | แชทบ็อต การแยกข้อมูล การเขียนเชิงสร้างสรรค์ | การวิเคราะห์ตลาด การตรวจสอบวิเคราะห์เนื่อง การทบทวนวรรณกรรม การเปรียบเทียบการแข่งขัน |
ความพร้อมให้บริการและการกำหนดราคา
- ความพร้อมใช้งาน: เข้าถึงได้โดยใช้ Interactions API ใน Google AI Studio และ Gemini API
- ราคา: ดูอัตราและรายละเอียดที่เฉพาะเจาะจงได้ในหน้าราคา
ข้อควรพิจารณาด้านความปลอดภัย
การให้สิทธิ์ตัวแทนเข้าถึงเว็บและไฟล์ส่วนตัวของคุณต้องพิจารณาความเสี่ยงด้านความปลอดภัยอย่างรอบคอบ
- การแทรกพรอมต์โดยใช้ไฟล์: เอเจนต์จะอ่านเนื้อหาของไฟล์ที่คุณระบุ ตรวจสอบว่าเอกสารที่อัปโหลด (PDF, ไฟล์ข้อความ) มาจากแหล่งที่มาที่เชื่อถือได้ ไฟล์ที่เป็นอันตรายอาจมีข้อความที่ซ่อนไว้ซึ่งออกแบบมาเพื่อ บิดเบือนเอาต์พุตของเอเจนต์
- ความเสี่ยงของเนื้อหาบนเว็บ: เอเจนต์จะค้นหาเว็บสาธารณะ แม้ว่าเราจะใช้ตัวกรองความปลอดภัยที่มีประสิทธิภาพ แต่ก็ยังมีความเสี่ยงที่เอเจนต์อาจพบและประมวลผลหน้าเว็บที่เป็นอันตราย เราขอแนะนำให้คุณตรวจสอบ
citationsที่ระบุ ในการตอบกลับเพื่อยืนยันแหล่งที่มา - การขโมยข้อมูล: โปรดระมัดระวังเมื่อขอให้เอเจนต์สรุปข้อมูลภายในที่ละเอียดอ่อน หากคุณอนุญาตให้เอเจนต์ท่องเว็บด้วย
แนวทางปฏิบัติแนะนำ
- แจ้งให้ทราบถึงสิ่งที่ไม่รู้จัก: สั่งให้เอเจนต์ทราบวิธีจัดการข้อมูลที่ขาดหายไป เช่น เพิ่ม "หากไม่มีตัวเลขที่เฉพาะเจาะจงสำหรับปี 2025 ให้ระบุอย่างชัดเจนว่าเป็นค่าประมาณหรือไม่มีข้อมูล แทนการประมาณ" ลงในพรอมต์
- ระบุบริบท: สร้างพื้นฐานการค้นคว้าของเอเจนต์โดยให้ข้อมูลพื้นฐานหรือข้อจำกัดในพรอมต์อินพุตโดยตรง
- อินพุตหลายรูปแบบ ตัวแทน Deep Research รองรับอินพุตหลายรูปแบบ โปรดใช้อย่างระมัดระวัง เนื่องจากจะเพิ่มต้นทุนและเสี่ยงต่อการล้นหน้าต่างบริบท
ข้อจำกัด
- สถานะเบต้า: Interactions API อยู่ในเวอร์ชันเบต้าแบบสาธารณะ ฟีเจอร์และ สคีมาอาจมีการเปลี่ยนแปลง
- เครื่องมือที่กำหนดเอง: ขณะนี้คุณยังไม่สามารถระบุเครื่องมือเรียกใช้ฟังก์ชันที่กำหนดเอง หรือเซิร์ฟเวอร์ MCP (Model Context Protocol) ระยะไกลให้กับเอเจนต์ Deep Research
- เอาต์พุตที่มีโครงสร้างและการอนุมัติแผน: ปัจจุบันเอเจนต์ Deep Research ยังไม่รองรับการวางแผนที่ได้รับการอนุมัติจากมนุษย์หรือเอาต์พุตที่มีโครงสร้าง
- เวลาค้นคว้าสูงสุด: ตัวแทน Deep Research มีเวลาค้นคว้าสูงสุด 60 นาที งานส่วนใหญ่ควรเสร็จสมบูรณ์ภายใน 20 นาที
- ข้อกำหนดของ Store: การดำเนินการของเอเจนต์โดยใช้
background=Trueต้องมีstore=True - Google Search: Google Search จะเปิดใช้โดย ค่าเริ่มต้นและข้อจำกัด เฉพาะ จะมีผลกับผลการค้นหาที่อิงตามข้อมูลพื้นฐาน
- อินพุตเสียง: ไม่รองรับอินพุตเสียง
ขั้นตอนถัดไป
- ดูข้อมูลเพิ่มเติมเกี่ยวกับ Interactions API
- อ่านเกี่ยวกับโมเดล Gemini 3 Pro ที่ขับเคลื่อน Agent นี้
- ดูวิธีใช้ข้อมูลของคุณเองโดยใช้เครื่องมือการค้นหาไฟล์