بنية المطالبات الوكيلية

التصحيح الذاتي واسترداد الأخطاء

5 دقيقة للقراءة

وكلاء الذكاء الاصطناعي في الإنتاج يجب أن يتعاملوا مع الفشل برشاقة. المطالبات النظامية الحقيقية تكشف آليات تصحيح ذاتي متطورة تفصل الوكلاء القوية عن الهشة.

تصنيف الأخطاء

وكلاء الإنتاج يصنفون الأخطاء للتعامل المناسب:

Error Classification System:
1. RECOVERABLE - Can fix automatically
   - Syntax errors in generated code
   - Missing imports
   - Type mismatches
   - Rate limits (retry with backoff)

2. CORRECTABLE - Needs adjustment
   - Wrong file modified
   - Incorrect approach taken
   - Partial solution needs extension

3. BLOCKING - Requires escalation
   - Missing permissions
   - Unknown API or library
   - Conflicting requirements
   - Ambiguous instructions

4. CRITICAL - Stop and alert
   - Data loss risk
   - Security vulnerability introduced
   - Breaking production code

أنماط التحقق الذاتي

التحقق قبل التنفيذ

تحقق قبل الفعل:

Pre-Execution Checklist:
Before modifying any file:
[ ] Have I read the file first?
[ ] Do I understand the existing code?
[ ] Is my change targeted and minimal?
[ ] Will this break existing functionality?
[ ] Are there tests I should run after?

If any check fails, STOP and reconsider.

التحقق بعد التنفيذ

تحقق بعد التغييرات:

Post-Execution Verification:
After each modification:
1. Check for syntax errors
2. Verify imports resolve
3. Run type checker if available
4. Execute related tests
5. Confirm expected behavior

If verification fails:
- Analyze the error
- Determine root cause
- Apply fix or rollback

بروتوكولات سلامة Claude Code

من المطالبة النظامية لـ Claude Code:

Git Safety Protocol:
- NEVER update git config
- NEVER run destructive commands (push --force, hard reset)
- NEVER skip hooks (--no-verify)
- NEVER force push to main/master

Commit Amend Rules:
Only use --amend when ALL conditions are met:
1. User explicitly requested amend, OR commit succeeded
   but pre-commit hook auto-modified files
2. HEAD commit was created by you in this conversation
3. Commit has NOT been pushed to remote

If commit FAILED or was REJECTED by hook:
- NEVER amend
- Fix the issue
- Create a NEW commit

منطق التراجع في Claude Code

Rollback Decision Tree:
If change causes errors:
├── Can error be fixed quickly?
│   ├── Yes → Apply fix
│   └── No → Consider rollback
├── Is the change critical path?
│   ├── Yes → Prioritize fix
│   └── No → Rollback, address later
└── Does user need working state?
    ├── Yes → Rollback immediately
    └── No → Continue debugging

استرداد أخطاء Cursor

وكلاء Cursor يتعاملون مع الفشل بشكل منهجي:

Cursor Error Recovery:
On task failure:
1. Capture full error output
2. Analyze error type:
   - Compilation error → Fix code
   - Runtime error → Debug logic
   - Test failure → Update test or code
   - Environment error → Check setup

3. Apply appropriate fix strategy:
   - Targeted edit for simple errors
   - Broader refactor for design issues
   - User consultation for ambiguous cases

4. Verify fix resolves original error
5. Check for regression

استرداد وكلاء الخلفية

وكلاء الخلفية في Cursor لديهم استرداد خاص:

Background Agent Failure Protocol:
If background agent fails:
1. Save all progress to checkpoint
2. Log detailed error context
3. Notify user with:
   - What was attempted
   - Where it failed
   - What was completed
   - Suggested next steps
4. Preserve partial work
5. Allow user to resume or retry

بروتوكول التصعيد لـ Devin

من معالجة أخطاء Devin 2.0:

Escalation Levels:
LEVEL 1: Self-Recovery
- Retry transient failures (max 3)
- Auto-fix common errors
- Continue without user

LEVEL 2: Inform User
- Log the issue
- Provide workaround
- Continue with degraded functionality

LEVEL 3: Seek Guidance
- Present problem clearly
- Offer alternative approaches
- Wait for user decision

LEVEL 4: Full Stop
- Halt all operations
- Preserve state
- Require explicit user restart

معالجة أخطاء الوكلاء المتعددة

فشل تنسيق وكلاء Devin:

Agent Coordination Failure:
If dispatched agent fails:
1. Capture agent's final state
2. Analyze failure point
3. Decision:
   - Retry with same agent
   - Dispatch different agent
   - Absorb task to main agent
   - Escalate to user

Communication protocol:
{
  "agent_id": "test_writer_01",
  "status": "failed",
  "error": "...",
  "partial_work": {...},
  "retry_recommended": true
}

استرداد Windsurf بمساعدة الذاكرة

Windsurf يستخدم الذاكرة لاسترداد أذكى:

Memory-Aided Recovery:
On error, check memory for:
- Similar past errors and solutions
- User's preferred error handling
- Project-specific workarounds
- Known problematic patterns

Memory query:
<memory_search>
  type: error_resolution
  error_pattern: {{current_error}}
  project: {{current_project}}
</memory_search>

Apply learned solution if confidence > 80%

آليات النقد الذاتي

وكلاء الإنتاج ينتقدون عملهم:

Self-Critique Protocol:
After generating solution:
1. Review from user's perspective
   - Does this solve the actual problem?
   - Is it the simplest solution?

2. Review from maintainer's perspective
   - Is the code readable?
   - Will future developers understand it?

3. Review from security perspective
   - Any vulnerabilities introduced?
   - Input validation adequate?

4. Review from performance perspective
   - Any obvious inefficiencies?
   - Will it scale?

Score each dimension 1-5
If any score < 3, revise before presenting

حلقة التحسين الذاتي التكرارية

Self-Improvement Loop:
Generate → Critique → Improve

Iteration 1:
- Generate initial solution
- Critique: "Missing error handling"
- Improve: Add try-catch blocks

Iteration 2:
- Review improved solution
- Critique: "Error messages not helpful"
- Improve: Add descriptive messages

Iteration 3:
- Final review
- Critique: "Acceptable quality"
- Present to user

Max iterations: 3
Quality threshold: All dimensions ≥ 3

التدهور الرشيق

عندما لا يمكن الحل الكامل:

Graceful Degradation Strategy:
If cannot complete full task:
1. Complete what's possible
2. Document what's missing
3. Provide partial solution
4. Explain blockers clearly
5. Suggest manual steps

Example output:
"I completed 3 of 4 requested features:
✓ User authentication
✓ Password reset
✓ Email verification
✗ OAuth integration (blocked by missing API keys)

For OAuth, you'll need to:
1. Add API keys to .env
2. Run: npm run setup-oauth
3. I can complete once keys are available"

أنماط أخطاء الإنتاج

أنماط شائعة من المطالبات النظامية الحقيقية:

النمط متى تستخدم مثال
إعادة المحاولة مع تراجع الفشل المؤقت حدود معدل API
التراجع التغييرات المكسرة إعادة هيكلة فاشلة
الإكمال الجزئي المهام المحظورة بيانات اعتماد مفقودة
تصعيد المستخدم الغموض متطلبات غير واضحة
نقطة الفحص المهام الطويلة تغييرات متعددة الملفات

رؤية رئيسية: وكلاء الإنتاج لا يحاولون النجاح فقط—يخططون للفشل. تصنيف الأخطاء، نقاط التحقق، بروتوكولات التصعيد، والتدهور الرشيق تنشئ أنظمة قوية تحافظ على ثقة المستخدم حتى عندما تسوء الأمور.

في الاختبار، سنختبر فهمك لأنماط بنية المطالبات الوكيلية. :::

اختبار

الوحدة 3: بنية المطالبات الوكيلية

خذ الاختبار