يخطّط وكيل 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 هي عملية متعدّدة الخطوات تشمل التخطيط والبحث والقراءة والكتابة. يتجاوز هذا الإجراء عادةً حدود المهلة الزمنية العادية لطلبات البيانات المتزامنة من واجهة برمجة التطبيقات.
على الموظفين استخدام background=True. تعرض واجهة برمجة التطبيقات عنصر 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().
يجب تقديم قيمتَين لاستئناف العملية:
- معرّف التفاعل: يتم الحصول عليه من الحدث
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 Agent
Deep Research هي وكيل، وليست مجرد نموذج. وهي الأنسب لأحمال العمل التي تتطلّب أسلوب "محلّل جاهز" بدلاً من المحادثة ذات وقت الاستجابة المنخفض.
| الميزة | نماذج Gemini العادية | وكيل Deep Research في Gemini |
|---|---|---|
| وقت الاستجابة | الثواني | الدقائق (غير متزامن/في الخلفية) |
| المعالجة | إنشاء -> الناتج | التخطيط -> البحث -> القراءة -> التكرار -> الإخراج |
| الناتج | نص حواري ورموز وملخّصات قصيرة | التقارير التفصيلية والتحليلات الطويلة وجداول المقارنة |
| الأفضل لـ | برامج الدردشة الآلية واستخراج المعلومات والكتابة الإبداعية | تحليل السوق، وبذل العناية الواجبة، ومراجعات الأدبيات، وتحديد المنافسين |
التوفّر والأسعار
- التوفّر: يمكن الوصول إلى هذه الميزة باستخدام Interactions API في Google AI Studio وGemini API.
- الأسعار: يمكنك الاطّلاع على صفحة الأسعار للحصول على الأسعار والتفاصيل المحدّدة.
اعتبارات السلامة
يتطلّب منح أحد العملاء إذن الوصول إلى الويب وملفاتك الخاصة مراعاة دقيقة لمخاطر الأمان.
- إدخال تعليمات باستخدام الملفات: يقرأ الوكيل محتوى الملفات التي تقدّمها. تأكَّد من أنّ المستندات التي تم تحميلها (ملفات PDF وملفات نصية) واردة من مصادر موثوقة. قد يحتوي ملف ضار على نص مخفي مصمّم للتلاعب بمخرجات الوكيل.
- مخاطر المحتوى على الويب: يبحث الوكيل في شبكة الويب المتاحة للجميع. على الرغم من أنّنا نستخدم فلاتر أمان قوية، هناك احتمال أن يواجه الوكيل صفحات ويب ضارة ويعالجها. ننصحك بمراجعة
citationsالواردة في الردّ للتأكّد من المصادر. - استخراج البيانات: توخَّ الحذر عند الطلب من الوكيل تلخيص بيانات داخلية حساسة إذا كنت تسمح له أيضًا بتصفّح الويب.
أفضل الممارسات
- طلب معلومات غير معروفة: يمكنك توجيه الوكيل بشأن كيفية التعامل مع البيانات المفقودة. على سبيل المثال، أضِف "إذا لم تتوفّر أرقام محدّدة لعام 2025، اذكر بوضوح أنّها توقّعات أو غير متوفّرة بدلاً من تقديرها" إلى طلبك.
- توفير السياق: يمكنك توجيه بحث الوكيل من خلال تقديم معلومات أساسية أو قيود مباشرةً في طلب الإدخال.
- الإدخالات المتعددة الوسائط: يتيح Deep Research Agent الإدخالات المتعددة الوسائط. استخدِم هذه الميزة بحذر، لأنّها تزيد التكاليف وتزيد من خطر تجاوز قدرة الاستيعاب.
القيود
- حالة الإصدار التجريبي: يتوفّر الإصدار التجريبي العلني من Interactions API. قد تتغيّر الميزات والمخططات.
- أدوات مخصّصة: لا يمكنك حاليًا توفير أدوات مخصّصة لاستدعاء الدوال أو خوادم MCP (بروتوكول سياق النموذج) بعيدة لوكيل Deep Research.
- النتائج المنظَّمة والموافقة على الخطة: لا يتيح وكيل Deep Research حاليًا الموافقة البشرية على التخطيط أو النتائج المنظَّمة.
- الحد الأقصى لوقت البحث: يبلغ الحد الأقصى لوقت البحث الذي يستغرقه وكيل Deep Research 60 دقيقة. من المفترض أن تكتمل معظم المهام في غضون 20 دقيقة.
- متطلبات المتجر: يتطلّب تنفيذ الوكيل باستخدام
background=Trueتوفّرstore=True. - بحث Google: تكون ميزة بحث Google مفعّلة تلقائيًا، وتسري قيود محدّدة على النتائج المستندة إلى معلومات واقعية.
- الإدخالات الصوتية: لا تتوافق هذه الأجهزة مع الإدخالات الصوتية.
الخطوات التالية
- مزيد من المعلومات حول Interactions API
- يمكنك الاطّلاع على معلومات حول نموذج Gemini 3 Pro الذي يشغّل هذا الوكيل.
- تعرَّف على كيفية استخدام بياناتك الخاصة باستخدام أداة البحث في الملفات.