Plan-then-act derin — yapılandırılmış plan ve validasyon
Plan-then-act deep dive — structured plan and validation
Bu derste neler öğreneceksin
- Structured plan'in zorunlu alanlarını ve şema validasyonunu öğrenmek
- 4 katmanlı plan validasyonu (schema → policy → safety → human) zincirini kavramak
- GitHub'da plan-then-act'i somut olarak uygulamayı görmek (PR description + branch protection)
- 'Plan onaylanmadan aksiyon yok' kuralının trap'lerini ayırt etmek
Önceki dersin (Modül 2 — Domain 1 özet) plan-then-act modelini tanımlamıştı. Bu ders model’in derin pratiğine iner — şema, validasyon katmanları, GitHub’da somut uygulama.
Yapılandırılmış (structured) plan zorunlu alanları
Sınav structured plan demek bir şemaya uyumlu plan demek. Minimum alanlar:
plan:
goal: "PR review yorumlarını çöz ve testleri yeşilleştir"
inputs:
- "PR #123 (current)"
- "Failing tests: src/auth.test.ts (3 fail)"
steps:
- id: 1
action: "Read failing test output"
tool: "actions-logs"
expected_output: "Failure reason + line numbers"
- id: 2
action: "Patch the source"
tool: "file-edit"
depends_on: 1
- id: 3
action: "Run tests locally"
tool: "bash"
depends_on: 2
success_criteria: "All tests pass"
success_criteria: "PR checks green + reviewer comments resolved"
risks:
- "Test fix may break other tests"
- "Code change may affect downstream dependencies"
mitigations:
- "Run full test suite, not just changed"
- "Update dependent code in same PR"
abort_conditions:
- "Tests still fail after 3 attempts"
- "Reviewer rejects approach"
Bu şema diff’lenebilir (PR description’da revize edilebilir), doğrulanabilir (alanlar dolu mu? schema valid mi?), ve audit-uyumlu (PR history kalıcı kayıt).
4 katmanlı plan validasyonu
Plan onaylanmadan aksiyon yok kuralı için 4 katman:
| Katman | Ne kontrol eder | Otomatik mi? |
|---|---|---|
| 1. Schema check | Alanlar dolu mu, tipler doğru mu, depends_on geçerli mi | ✅ Otomatik |
| 2. Policy check | Yasak aksiyon var mı (örn. rm -rf, prod write) | ✅ Otomatik |
| 3. Safety check | Risk yüksek mi, abort conditions makul mi | ⚠️ Yarı (heuristic + insan) |
| 4. Human review | Yargısal “bu plan mantıklı mı” | 👤 İnsan |
Katmanlama mantığı: ucuz/hızlı otomatik gate’ler önce; insan en yüksek değer ekledikleri yerde devreye girer. Sınavın istediği layered defense.
GitHub’da somut uygulama
Adım 1: Agent’a structured plan üretmeyi öğret
.github/copilot-instructions.md’de:
## Plan output format
Before executing ANY non-trivial task, output a structured plan in the PR
description using this schema:
```yaml
plan:
goal: <string>
inputs: <list>
steps: <list of {id, action, tool, expected_output, depends_on?}>
success_criteria: <string>
risks: <list>
mitigations: <list>
abort_conditions: <list>
Do NOT execute steps until the PR has at least 1 review approval.
### Adım 2: Schema check otomatik
GitHub Actions workflow:
```yaml
name: plan-validation
on:
pull_request:
types: [opened, edited]
permissions:
contents: read
pull-requests: write
jobs:
validate-plan:
runs-on: ubuntu-latest
steps:
- name: Extract plan from PR body
id: extract
run: |
gh pr view ${{ github.event.pull_request.number }} --json body \
| jq -r '.body' | yq eval '.plan' > plan.yaml
- name: Validate schema
run: yq -e 'has("goal") and has("steps") and has("success_criteria")' plan.yaml
Adım 3: Policy check
Aynı workflow’da ek step:
- name: Check for forbidden actions
run: |
if grep -E "rm -rf|DROP TABLE|force.push" plan.yaml; then
echo "::error::Policy violation: forbidden action in plan"
exit 1
fi
Adım 4: Human review
Branch protection ayarı:
- “Require a pull request before merging” ✅
- “Require approvals” ≥ 1 ✅
- “Require status checks to pass” →
plan-validation✅
Bu setup’ta: agent plan yazar → otomatik gate’ler çalışır → insan bakar → onay → merge → aksiyon (post-merge step). Plan onaylanmadan hiçbir aksiyon yok.
Sık karıştırılan: “Plan validate” ≠ “plan execution”
| Plan validation | Plan execution | |
|---|---|---|
| Ne zaman | PR aşaması | Merge sonrası |
| Ne yapar | Plan’ın yapısı/güvenliği OK mi | Plan’ı adım adım uygula |
| Çıktı | ”Plan kabul/red" | "Adım tamamlandı/başarısız” |
| Geri alma | Plan red → revise | Adım fail → rollback (Domain 2) |
Sınavda “agent şu noktada ne yapmalı?” sorusu validation aşamasına işaret ediyorsa cevap plan revize/blokla; execution aşamasına işaret ediyorsa retry/rollback/escalation (Domain 2 zinciri).
Mini quiz — Plan-then-act derin (3 soru)
Sırada ne var?
Bir sonraki derste observability ve inspectable artifact’i derinlemesine işliyoruz — otonom agent’ın izini PR/issue/Actions logs üzerinden nasıl sürdürürsün, neyi sakla / saklama.