أنظمة الوكلاء المتعددين
قم ببناء تطبيقات متطورة عن طريق تجميع الوكلاء المتخصصين في فرق.
نظرة عامة على التسلسل الهرمي للوكلاء
ما ستقوم ببنائه
في هذا الدليل، ستقوم بإنشاء نظام خدمة عملاء حيث يقوم المنسق بتوجيه الاستفسارات إلى المتخصصين:
┌─────────────────────┐
User Query │ │
────────────────▶ │ COORDINATOR │
│ "Route to expert" │
└──────────┬──────────┘
│
┌───────────────┴───────────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ BILLING AGENT │ │ SUPPORT AGENT │
│ │ │ │
│ 💰 Payments │ │ 🔧 Tech Issues │
│ 📄 Invoices │ │ 🐛 Bug Reports │
│ 💳 Subscriptions│ │ ❓ How-To │
└──────────────────┘ └──────────────────┘
المفاهيم الأساسية:
- Coordinator - يتلقى جميع الطلبات، ويقرر من يتعامل معها
- Specialists - وكلاء مركزون يتفوقون في مجالات محددة
- Transfer - تسليم سلس من المنسق إلى المتخصص
بدء سريع
1. أنشئ مشروعك
cargo new multi_agent_demo
cd multi_agent_demo
أضف التبعيات إلى Cargo.toml:
[dependencies]
adk-rust = "2.0.0"
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
أنشئ .env باستخدام مفتاح API الخاص بك:
echo 'GOOGLE_API_KEY=your-api-key' > .env
2. مثال خدمة العملاء
إليك مثال عملي كامل:
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GOOGLE_API_KEY")?;
let model = Arc::new(GeminiModel::new(&api_key, "gemini-2.5-flash")?);
// Specialist: Billing Agent
let billing_agent = LlmAgentBuilder::new("billing_agent")
.description("Handles billing questions: payments, invoices, subscriptions, refunds")
.instruction("You are a billing specialist. Help customers with:\n\
- Invoice questions and payment history\n\
- Subscription plans and upgrades\n\
- Refund requests\n\
- Payment method updates\n\
Be professional and provide clear information about billing matters.")
.model(model.clone())
.build()?;
// Specialist: Technical Support Agent
let support_agent = LlmAgentBuilder::new("support_agent")
.description("Handles technical support: bugs, errors, troubleshooting, how-to questions")
.instruction("You are a technical support specialist. Help customers with:\n\
- Troubleshooting errors and bugs\n\
- How-to questions about using the product\n\
- Configuration and setup issues\n\
- Performance problems\n\
Be patient and provide step-by-step guidance.")
.model(model.clone())
.build()?;
// Coordinator: Routes to appropriate specialist
let coordinator = LlmAgentBuilder::new("coordinator")
.description("Main customer service coordinator")
.instruction("You are a customer service coordinator. Analyze each customer request:\n\n\
- For BILLING questions (payments, invoices, subscriptions, refunds):\n\
Transfer to billing_agent\n\n\
- For TECHNICAL questions (errors, bugs, how-to, troubleshooting):\n\
Transfer to support_agent\n\n\
- For GENERAL greetings or unclear requests:\n\
Respond yourself and ask clarifying questions\n\n\
When transferring, briefly acknowledge the customer and explain the handoff.")
.model(model.clone())
.sub_agent(Arc::new(billing_agent))
.sub_agent(Arc::new(support_agent))
.build()?;
println!("🏢 Customer Service Center");
println!(" Coordinator → Billing Agent | Support Agent");
println!();
Launcher::new(Arc::new(coordinator)).run().await?;
Ok(())
}
مثال على التفاعل:
You: I have a question about my last invoice
[Agent: coordinator]
Assistant: I'll connect you with our billing specialist to help with your invoice question.
[Agent: billing_agent]
Assistant: Hello! I can help you with your invoice. What specific question do you have about your last invoice?
You: Why was I charged twice?
[Agent: billing_agent]
Assistant: I understand your concern about the duplicate charge. Let me help you investigate this...
كيف يعمل نقل الوكلاء المتعددين
الصورة الكبيرة
عند إضافة وكلاء فرعيين إلى وكيل رئيسي، يكتسب LLM القدرة على تفويض المهام:
┌─────────────────────┐
User Message │ │
─────────────────▶ COORDINATOR │
│ │
└──────────┬──────────┘
│
"This is a billing question..."
│
┌────────────────┴────────────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ billing_agent │ │ support_agent │
│ 💰 Payments │ │ 🔧 Tech Issues │
│ 📄 Invoices │ │ 🐛 Bug Reports │
└──────────────────┘ └──────────────────┘
تدفق النقل خطوة بخطوة
إليك ما يحدث بالضبط عندما يسأل المستخدم سؤالاً عن الفواتير:
┌──────────────────────────────────────────────────────────────────────┐
│ STEP 1: User sends message │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ User: "Why was I charged twice on my invoice?" │
│ │
│ ↓ │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ COORDINATOR AGENT │ │
│ │ Receives message first │ │
│ └──────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────────────┐
│ STEP 2: LLM analyzes and decides to transfer │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ 🧠 LLM thinks: "This is about an invoice charge..." │
│ "Invoice = billing topic..." │
│ "I should transfer to billing_agent" │
│ │
│ 📞 LLM calls: transfer_to_agent(agent_name="billing_agent") │
│ │
└──────────────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────────────┐
│ STEP 3: Runner detects transfer and invokes target │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ transfer event ┌─────────────────┐ │
│ │ Runner │ ─────────────────────▶ │ billing_agent │ │
│ └─────────┘ (same user message) └─────────────────┘ │
│ │
│ • Runner finds "billing_agent" in agent tree │
│ • Creates new context with SAME user message │
│ • Invokes billing_agent immediately │
│ │
└──────────────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────────────┐
│ STEP 4: Target agent responds │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ billing_agent responds │ │
│ │ │ │
│ │ "I can help with your duplicate │ │
│ │ charge. Let me investigate..." │ │
│ └─────────────────────────────────────────┘ │
│ │
│ ✅ User sees seamless response - no interruption! │
│ │
└──────────────────────────────────────────────────────────────────────┘
ما الذي يجعلها تعمل
| المكون | الدور |
|---|---|
.sub_agent() | يسجل المتخصصين تحت الأصل |
transfer_to_agent أداة | يتم حقنه تلقائيًا عند وجود sub-Agents |
| أوصاف Agent | يساعد LLM في تحديد أي Agent يتعامل مع ماذا |
| Runner | يكتشف أحداث النقل ويستدعي Agent الهدف |
| Session مشتركة | الحالة والسجل محفوظان عبر عمليات النقل |
قبل وبعد إضافة الوكلاء الفرعيين
بدون وكلاء فرعيين - وكيل واحد يقوم بكل شيء:
User ──▶ coordinator ──▶ Response (handles billing AND support)
مع وكلاء فرعيين - المتخصصون يتعاملون مع مجالهم:
User ──▶ coordinator ──▶ billing_agent ──▶ Response (billing expert)
──▶ support_agent ──▶ Response (tech expert)
أنظمة الوكلاء المتعددة الهرمية
للسيناريوهات المعقدة، يمكنك إنشاء تسلسلات هرمية متعددة المستويات. يمكن لكل وكيل أن يكون لديه وكلاؤه الفرعيون، مما يشكل شجرة:
مرئي: فريق محتوى من 3 مستويات
┌─────────────────────┐
│ PROJECT MANAGER │ ← Level 1: Top-level coordinator
│ "Manage projects" │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ CONTENT CREATOR │ ← Level 2: Mid-level coordinator
│ "Coordinate R&W" │
└──────────┬──────────┘
│
┌────────────────┴────────────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ RESEARCHER │ │ WRITER │ ← Level 3: Specialists
│ │ │ │
│ 📚 Gather facts │ │ ✍️ Write content │
│ 🔍 Analyze data │ │ 📝 Polish text │
│ 📊 Find sources │ │ 🎨 Style & tone │
└──────────────────┘ └──────────────────┘
كيف تتدفق الطلبات
User: "Create a blog post about electric vehicles"
│
▼
┌─────────────────────────────────────────────────────────────┐
│ PROJECT MANAGER: "This is a content task" │
│ → transfers to content_creator │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ CONTENT CREATOR: "Need research first, then writing" │
│ → transfers to researcher │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ RESEARCHER: "Here's what I found about EVs..." │
│ → provides research summary │
└─────────────────────────────────────────────────────────────┘
مثال كامل للتعليمات البرمجية
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GOOGLE_API_KEY")?;
let model = Arc::new(GeminiModel::new(&api_key, "gemini-2.5-flash")?);
// Level 3: Leaf specialists
let researcher = LlmAgentBuilder::new("researcher")
.description("Researches topics and gathers comprehensive information")
.instruction("You are a research specialist. When asked to research a topic:\n\
- Gather key facts and data\n\
- Identify main themes and subtopics\n\
- Note important sources or references\n\
Provide thorough, well-organized research summaries.")
.model(model.clone())
.build()?;
let writer = LlmAgentBuilder::new("writer")
.description("Writes polished content based on research")
.instruction("You are a content writer. When asked to write:\n\
- Create engaging, clear content\n\
- Use appropriate tone for the audience\n\
- Structure content logically\n\
- Polish for grammar and style\n\
Produce professional, publication-ready content.")
.model(model.clone())
.build()?;
// Level 2: Content coordinator
let content_creator = LlmAgentBuilder::new("content_creator")
.description("Coordinates content creation by delegating research and writing")
.instruction("You are a content creation lead. For content requests:\n\n\
- If RESEARCH is needed: Transfer to researcher\n\
- If WRITING is needed: Transfer to writer\n\
- For PLANNING or overview: Handle yourself\n\n\
Coordinate between research and writing phases.")
.model(model.clone())
.sub_agent(Arc::new(researcher))
.sub_agent(Arc::new(writer))
.build()?;
// Level 1: Top-level manager
let project_manager = LlmAgentBuilder::new("project_manager")
.description("Manages projects and coordinates with content team")
.instruction("You are a project manager. For incoming requests:\n\n\
- For CONTENT creation tasks: Transfer to content_creator\n\
- For PROJECT STATUS or general questions: Handle yourself\n\n\
Keep track of overall project goals and deadlines.")
.model(model.clone())
.sub_agent(Arc::new(content_creator))
.build()?;
println!("📊 Hierarchical Multi-Agent System");
println!();
println!(" project_manager");
println!(" └── content_creator");
println!(" ├── researcher");
println!(" └── writer");
println!();
Launcher::new(Arc::new(project_manager)).run().await?;
Ok(())
}
التسلسل الهرمي للوكلاء:
project_manager
└── content_creator
├── researcher
└── writer
أمثلة على المطالبات:
- "إنشاء منشور مدونة حول الذكاء الاصطناعي في الرعاية الصحية" ← PM ← Content Creator ← Writer
- "البحث عن المركبات الكهربائية" ← PM ← Content Creator ← Researcher
تكوين الوكيل الفرعي
أضف وكلاء فرعيين إلى أي LlmAgent باستخدام طريقة البناء sub_agent():
let parent = LlmAgentBuilder::new("parent")
.description("Coordinates specialized tasks")
.instruction("Route requests to appropriate specialists.")
.model(model.clone())
.sub_agent(Arc::new(specialist_a))
.sub_agent(Arc::new(specialist_b))
.build()?;
النقاط الرئيسية:
- يمكن لكل Agent أن يكون لديه عدة sub-agents
- يمكن للـ sub-agents أن يكون لديهم sub-agents خاصون بهم (تسلسلات هرمية متعددة المستويات)
- يجب أن تكون أسماء Agent فريدة داخل التسلسل الهرمي
- تساعد الأوصاف LLM في تحديد Agent الذي سيتم النقل إليه
كتابة تعليمات نقل فعالة
لنجاح عمليات نقل Agent، قدم تعليمات وأوصافًا واضحة:
تعليمات الوكيل الأصل
let coordinator = LlmAgentBuilder::new("coordinator")
.description("Main customer service coordinator")
.instruction("You are a customer service coordinator. Analyze each request:\n\n\
- For BILLING questions (payments, invoices, subscriptions):\n\
Transfer to billing_agent\n\n\
- For TECHNICAL questions (errors, bugs, troubleshooting):\n\
Transfer to support_agent\n\n\
- For GENERAL greetings or unclear requests:\n\
Respond yourself and ask clarifying questions")
.model(model.clone())
.sub_agent(Arc::new(billing_agent))
.sub_agent(Arc::new(support_agent))
.build()?;
أوصاف الوكيل الفرعي
let billing_agent = LlmAgentBuilder::new("billing_agent")
.description("Handles billing questions: payments, invoices, subscriptions, refunds")
.instruction("You are a billing specialist. Help with payment and subscription issues.")
.model(model.clone())
.build()?;
let support_agent = LlmAgentBuilder::new("support_agent")
.description("Handles technical support: bugs, errors, troubleshooting, how-to questions")
.instruction("You are a technical support specialist. Provide step-by-step guidance.")
.model(model.clone())
.build()?;
أفضل الممارسات:
- استخدم أسماء Agent وصفية تشير بوضوح إلى الغرض منها
- اكتب أوصافًا مفصلة - يستخدمها LLM لاتخاذ قرارات النقل
- قم بتضمين كلمات مفتاحية محددة في الأوصاف التي تتطابق مع طلبات المستخدم المحتملة
- قدم قواعد تفويض واضحة في تعليمات Agent الأصل
- استخدم مصطلحات متسقة عبر أوصاف Agent
اختبار نظام الوكلاء المتعددين الخاص بك
تشغيل الأمثلة
cargo run --manifest-path examples/tier_examples/enterprise/Cargo.toml --bin 14-enterprise-multi-agent
أمثلة على مطالبات الاختبار
خدمة العملاء:
- "لدي سؤال حول فاتورتي الأخيرة" ← يجب أن يوجه إلى
billing_agent - "التطبيق يستمر في التعطل" ← يجب أن يوجه إلى
support_agent - "كيف أقوم بترقية خطتي؟" ← يجب أن يوجه إلى
billing_agent - "مرحباً، أحتاج مساعدة" ← يجب أن يبقى مع
coordinatorللتوضيح
هرمي:
- "إنشاء منشور مدونة حول الذكاء الاصطناعي في الرعاية الصحية" ← PM ← Content Creator ← Writer
- "البحث في تاريخ المركبات الكهربائية" ← PM ← Content Creator ← Researcher
- "ما هي حالة مشاريعنا الحالية؟" ← يجب أن يبقى مع
project_manager
تصحيح أخطاء النقل
إذا لم تعمل عمليات النقل كما هو متوقع:
- تحقق من أسماء Agent - يجب أن تتطابق تمامًا في استدعاءات النقل
- راجع الأوصاف - اجعلها أكثر تحديدًا وغنية بالكلمات المفتاحية
- وضح التعليمات - كن صريحًا بشأن متى يتم النقل
- اختبر حالات الحافة - جرب طلبات غامضة لمعرفة سلوك التوجيه
- ابحث عن مؤشرات النقل -
[Agent: name]يوضح أي Agent يستجيب
التعليمات العامة
الاستخدام الأساسي
let agent = LlmAgentBuilder::new("assistant")
.description("A helpful assistant")
.global_instruction(
"You are a professional assistant for Acme Corp. \
Always maintain a friendly but professional tone. \
Our company values are: customer-first, innovation, and integrity."
)
.instruction("Help users with their questions and tasks.")
.model(model.clone())
.build()?;
التعليمات العامة مقابل تعليمات الوكيل
- التعليمات العامة: تُطبق على جميع Agents في التسلسل الهرمي، وتحدد الشخصية/السياق العام
- تعليمات Agent: خاصة بكل Agent، وتحدد دوره وسلوكه الخاص
يتم تضمين كلتا التعليمات في سجل المحادثة، مع ظهور التعليمات العامة أولاً.
تعليمات عامة ديناميكية
للسيناريوهات الأكثر تقدمًا، يمكنك استخدام موفر تعليمات عامة يحسب التعليمات ديناميكيًا:
use adk_core::GlobalInstructionProvider;
let provider: GlobalInstructionProvider = Arc::new(|ctx| {
Box::pin(async move {
// Access context information
let user_id = ctx.user_id();
// Compute dynamic instruction
let instruction = format!(
"You are assisting user {}. Tailor your responses to their preferences.",
user_id
);
Ok(instruction)
})
});
let agent = LlmAgentBuilder::new("assistant")
.description("A personalized assistant")
.global_instruction_provider(provider)
.model(model.clone())
.build()?;
حقن متغير الحالة
تدعم كل من التعليمات العامة وتعليمات Agent حقن متغير الحالة باستخدام بناء الجملة {variable}:
// Set state in a previous agent or tool
// state["company_name"] = "Acme Corp"
// state["user_role"] = "manager"
let agent = LlmAgentBuilder::new("assistant")
.global_instruction(
"You are an assistant for {company_name}. \
The user is a {user_role}."
)
.instruction("Help with {user_role}-level tasks.")
.model(model.clone())
.build()?;
يقوم الإطار تلقائيًا بحقن القيم من حالة الجلسة في قوالب التعليمات.
أنماط الوكلاء المتعددين الشائعة
نمط المنسق/الموزع
يقوم وكيل مركزي بتوجيه الطلبات إلى وكلاء فرعيين متخصصين:
let billing = LlmAgentBuilder::new("billing")
.description("Handles billing and payment questions")
.model(model.clone())
.build()?;
let support = LlmAgentBuilder::new("support")
.description("Provides technical support")
.model(model.clone())
.build()?;
let coordinator = LlmAgentBuilder::new("coordinator")
.instruction("Route requests to billing or support agents as appropriate.")
.sub_agent(Arc::new(billing))
.sub_agent(Arc::new(support))
.model(model.clone())
.build()?;
مثال على المحادثة:
User: I have a question about my last invoice
[Agent: coordinator]
Assistant: I'll connect you with our billing specialist.
🔄 [Transfer requested to: billing]
[Agent: billing]
Assistant: Hello! I can help you with your invoice.
What specific question do you have?
User: Why was I charged twice?
[Agent: billing]
Assistant: Let me investigate that duplicate charge for you...
النقاط الرئيسية:
- يقوم المنسق بتحليل الطلب وينقله إلى وكيل الفواتير
- يستجيب وكيل الفواتير فورًا في نفس الدور
- تستمر الرسائل اللاحقة مع وكيل الفواتير
- تظهر مؤشرات النقل (
🔄) عند حدوث التسليم
تفكيك المهام الهرمي
تسلسلات هرمية متعددة المستويات لتفكيك المهام المعقدة:
// Low-level specialists
let researcher = LlmAgentBuilder::new("researcher")
.description("Researches topics and gathers information")
.model(model.clone())
.build()?;
let writer = LlmAgentBuilder::new("writer")
.description("Writes content based on research")
.model(model.clone())
.build()?;
// Mid-level coordinator
let content_creator = LlmAgentBuilder::new("content_creator")
.description("Creates content by coordinating research and writing")
.sub_agent(Arc::new(researcher))
.sub_agent(Arc::new(writer))
.model(model.clone())
.build()?;
// Top-level manager
let project_manager = LlmAgentBuilder::new("project_manager")
.description("Manages content creation projects")
.sub_agent(Arc::new(content_creator))
.model(model.clone())
.build()?;
الدمج مع وكلاء سير العمل
تعمل أنظمة الوكلاء المتعددين بشكل جيد مع وكلاء سير العمل (Sequential, Parallel, Loop):
use adk_agent::workflow::{SequentialAgent, ParallelAgent};
// Create specialized agents
let validator = LlmAgentBuilder::new("validator")
.instruction("Validate the input data.")
.output_key("validation_result")
.model(model.clone())
.build()?;
let processor = LlmAgentBuilder::new("processor")
.instruction("Process data if {validation_result} is valid.")
.output_key("processed_data")
.model(model.clone())
.build()?;
// Combine in a sequential workflow
let pipeline = SequentialAgent::new(
"validation_pipeline",
vec![Arc::new(validator), Arc::new(processor)]
);
// Use the pipeline as a sub-agent
let coordinator = LlmAgentBuilder::new("coordinator")
.description("Coordinates data processing")
.sub_agent(Arc::new(pipeline))
.model(model.clone())
.build()?;
التواصل بين الوكلاء
يتواصل الوكلاء في التسلسل الهرمي من خلال حالة الجلسة المشتركة:
// Agent A saves data to state
let agent_a = LlmAgentBuilder::new("agent_a")
.instruction("Analyze the topic and save key points.")
.output_key("key_points") // Automatically saves output to state
.model(model.clone())
.build()?;
// Agent B reads data from state
let agent_b = LlmAgentBuilder::new("agent_b")
.instruction("Expand on the key points: {key_points}")
.model(model.clone())
.build()?;
يقوم تكوين output_key تلقائيًا بحفظ الاستجابة النهائية للوكيل في حالة الجلسة، مما يجعلها متاحة للوكلاء اللاحقين.
AgentTool إعادة توجيه الحالة والتحف
عند استخدام AgentTool لتغليف Agents كـ tools، يتم إعادة توجيه تغييرات الحالة والتحف من sub-agents تلقائيًا إلى السياق الأصل:
use adk_tool::AgentTool;
// Create a sub-agent that modifies state
let data_processor = LlmAgentBuilder::new("data_processor")
.instruction("Process the data and save results.")
.output_key("processed_data")
.model(model.clone())
.build()?;
// Wrap as a tool - state_delta and artifact_delta are forwarded
let processor_tool = AgentTool::new(Arc::new(data_processor));
// Parent agent can use the tool and see state changes
let coordinator = LlmAgentBuilder::new("coordinator")
.instruction("Use the data_processor tool, then access {processed_data}.")
.model(model.clone())
.tool(Arc::new(processor_tool))
.build()?;
يقوم AgentTool بتشغيل sub-agents في وضع عدم البث (StreamingMode::None) داخليًا، لذلك يقوم sub-agent بتجميع استجابته الكاملة قبل إعادتها إلى الأصل. هذا يمنع المشكلات حيث يمكن أن تنتج أجزاء البث الجزئية نتائج فارغة.
هذا يتيح تدفقًا سلسًا للبيانات بين Agents الأصل والفرعي عند استخدام نمط AgentTool.
تشغيل أنظمة الوكلاء المتعددين
استخدام المشغل
يوفر Launcher طريقة سهلة لتشغيل واختبار أنظمة الوكلاء المتعددين:
use adk_rust::Launcher;
let coordinator = /* your multi-agent setup */;
Launcher::new(Arc::new(coordinator))
.run()
.await?;
أوضاع التشغيل:
# Interactive console mode
cargo run --manifest-path examples/tier_examples/enterprise/Cargo.toml --bin 14-enterprise-multi-agent
# Use a generated API project when you need HTTP serving
cargo adk new multi_agent_api --template api
الميزات:
- مؤشرات Agent: تُظهر أي Agent يستجيب
[Agent: coordinator] - تصور النقل: يعرض أحداث النقل
🔄 [Transfer requested to: billing_agent] - تسليم سلس: يستجيب Agent الهدف فورًا بعد النقل
- سجل المحادثة: يحافظ على السياق عبر عمليات نقل Agent
اختبار عمليات النقل
للتحقق من أن نظام الوكلاء المتعددين يعمل بشكل صحيح:
- تحقق من أسماء Agent التي تظهر بين قوسين عند الاستجابة
- ابحث عن مؤشرات النقل (
🔄) عندما يقوم Agents بالتسليم - تحقق من الاستجابات الفورية من Agents الهدف دون إعادة المطالبة
- اختبر أنواع الطلبات المختلفة لضمان التوجيه الصحيح
- تحقق من حالات الحافة مثل النقل إلى Agents غير موجودين
تصحيح أخطاء النقل
إذا لم تعمل عمليات النقل:
- تحقق من إضافة sub-agents عبر
.sub_agent() - تحقق من أوصاف Agent - يستخدمها LLM لاتخاذ قرارات النقل
- راجع التعليمات - يجب أن يذكر الأصل متى يتم النقل
- تحقق من أسماء Agent - يجب أن تتطابق تمامًا في استدعاءات النقل
- قم بتمكين التسجيل لرؤية إجراءات النقل في تدفق الأحداث
أفضل الممارسات
- أوصاف واضحة: اكتب أسماء وأوصاف Agent وصفية لمساعدة LLM على اتخاذ قرارات نقل جيدة
- تعليمات محددة: امنح كل Agent تعليمات واضحة ومركزة لدوره
- استخدم التعليمات العامة: قم بتعيين شخصية وسياق متسقين عبر جميع Agents
- إدارة الحالة: استخدم
output_keyومتغيرات الحالة لتواصل Agent - الحد من عمق التسلسل الهرمي: حافظ على التسلسلات الهرمية ضحلة (2-3 مستويات) لتحسين سهولة الصيانة
- اختبار منطق النقل: تحقق من أن Agents ينتقلون إلى sub-agents الصحيحين لطلبات مختلفة
ذات صلة
- LLM Agent - تكوين Agent الأساسي
- Workflow Agents - وكلاء Sequential و Parallel و Loop
- Sessions - إدارة حالة الجلسة
السابق: ← Workflow Agents | التالي: Graph Agents →