مراقبة وكيل البرمجة المباشر
راقب وكلاء البرمجة أثناء عملهم في الوقت الفعلي مع الإيقاف المؤقت والتراجع والتفريع. ثلاث واجهات خلفية مدعومة: Ollama للنماذج المحلية، وAnthropic API، وClaude Agent SDK.
جديد في الإصدار v2.4.0
يخبرك التعليق التوضيحي على التتبعات الساكنة بما فعله الوكيل. أما المراقبة المباشرة فتخبرك بما يفعله الوكيل استجابةً للتوجيه البشري. يتيح وضع وكيل البرمجة المباشر في Potato للمعلّقين مراقبة وكيل برمجة أثناء عمله في الوقت الفعلي -- يقرأ الملفات، ويحرر الكود، ويشغّل الاختبارات -- والتدخل في أي لحظة. أوقف الوكيل مؤقتاً، أو أرسل تعليمات جديدة، أو تراجع إلى نقطة تحقق سابقة، أو فرّع المسار لاستكشاف مقاربات بديلة.
ينتج هذا بيانات تعليق توضيحي أغنى مما تنتجه التتبعات الساكنة وحدها. تحصل على المسار الكامل بطوابعه الزمنية، وتدخلات المعلّق، ونقاط قرار التفريع، وبيانات مقارنة من المسارات البديلة. وهذه البيانات مفيدة مباشرةً في تدريب نماذج مكافأة العملية، ونماذج التفضيل، ومقيّمات اتباع التعليمات.
المتطلبات
- Python 3.10+
- Git (يعتمد نظام نقاط التحقق على commits في git)
- إحدى الواجهات الخلفية التالية للوكيل:
- Ollama للاستدلال بنماذج محلية (لا يلزم مفتاح API)
- ANTHROPIC_API_KEY للوصول إلى Anthropic API
- Claude Agent SDK لتجربة وكيل Claude Code الكاملة
الواجهات الخلفية
يدعم Potato ثلاث واجهات خلفية لتشغيل وكلاء البرمجة. تشغّل كل واجهة الوكيل في عملية فرعية وتبث إجراءاته إلى واجهة التعليق التوضيحي في الوقت الفعلي.
1. Ollama (نماذج محلية)
شغّل وكلاء البرمجة محلياً من دون مفتاح API. يوفر Ollama استدلالاً سريعاً للنماذج مفتوحة الأوزان. وهو الأنسب للتطوير والاختبار والحالات التي لا يجوز فيها للبيانات مغادرة الجهاز المحلي.
الإعداد:
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull a coding-capable model
ollama pull qwen2.5-coder:7b
# Or a larger model for better performance
ollama pull deepseek-coder-v2:16bالتهيئة:
agentic:
enabled: true
display_type: coding_trace
live_agent:
enabled: true
backend: ollama
model: qwen2.5-coder:7b
ollama:
host: "http://localhost:11434" # Ollama server URL
temperature: 0.2
num_ctx: 8192 # context window size
num_predict: 2048 # max tokens per response
keep_alive: "5m" # keep model loaded in memory
# Agent capabilities
tools:
- read_file
- edit_file
- write_file
- bash
- glob
- grep
max_steps: 50
step_timeout_seconds: 602. Anthropic API
استخدم نماذج Claude عبر Anthropic API. يعطي أداءً قوياً في البرمجة مع قدرات استخدام الأدوات. ويتطلب مفتاح API.
الإعداد:
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."
# Or add to .env file
echo "ANTHROPIC_API_KEY=sk-ant-..." >> .envالتهيئة:
agentic:
enabled: true
display_type: coding_trace
live_agent:
enabled: true
backend: anthropic
model: claude-sonnet-4-20250514
anthropic:
api_key: ${ANTHROPIC_API_KEY}
max_tokens: 4096
temperature: 0.2
system_prompt: |
You are a coding assistant working on a software project.
Read files before editing them. Run tests after making changes.
Explain your reasoning before each action.
# Agent capabilities
tools:
- read_file
- edit_file
- write_file
- bash
- glob
- grep
max_steps: 100
step_timeout_seconds: 1203. Claude Agent SDK
يوفر Claude Agent SDK تجربة وكيل Claude Code الكاملة، بما فيها تنسيق الأدوات التلقائي، وإدارة السياق، والتفكير عبر ملفات متعددة. وهذه أقدر الواجهات الخلفية، لكنها تتطلب تثبيت الـ SDK.
الإعداد:
# Install the Claude Agent SDK
pip install claude-agent-sdk
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."التهيئة:
agentic:
enabled: true
display_type: coding_trace
live_agent:
enabled: true
backend: claude_agent_sdk
claude_agent_sdk:
api_key: ${ANTHROPIC_API_KEY}
model: claude-sonnet-4-20250514
max_turns: 100
permission_mode: auto # auto-approve tool use
enable_thinking: true # show extended thinking
max_steps: 100
step_timeout_seconds: 180عناصر التحكم
توفر واجهة التعليق التوضيحي أربعة إجراءات تحكم تتيح للمعلّقين توجيه سلوك الوكيل.
إيقاف مؤقت / استئناف
انقر Pause لإيقاف الوكيل بين الخطوات. ينهي الوكيل خطوته الحالية ثم ينتظر. ويمكن للمعلّق مراجعة الحالة الراهنة، وفحص الملفات، وتقرير ما إذا كان سيدع الوكيل يواصل أم سيتدخل. انقر Resume ليتابع الوكيل.
live_agent:
controls:
pause_resume:
enabled: true
auto_pause_on_error: true # pause when a command fails
auto_pause_after_steps: 0 # pause after N steps (0 = disabled)
keyboard_shortcut: "Space"إرسال التعليمات
أثناء إيقاف الوكيل مؤقتاً، يمكن للمعلّقين إرسال تعليمات جديدة تعيد توجيهه. وهذا مفيد حين يسلك الوكيل مساراً خاطئاً، أو حين يريد المعلّق اختبار استجابته للتوجيه.
live_agent:
controls:
send_instructions:
enabled: true
placeholder: "Type instructions for the agent..."
inject_as: system_message # "system_message" or "user_message"
keyboard_shortcut: "Enter"
presets:
- "Try a different approach"
- "Read the error message more carefully"
- "Check the test file for expected behavior"
- "Revert your last change and try again"تُحقن التعليمات في سياق محادثة الوكيل. ويتحكم خيار inject_as في ظهورها كرسالة نظام (تعليمة آمرة) أو كرسالة مستخدم (توجيه حواري).
التراجع
يعيد التراجع المشروع إلى نقطة تحقق سابقة في git. فكل تغيير يجريه الوكيل على الملفات يُودَع تلقائياً، ما يتيح للمعلّق النقر على أي خطوة سابقة في الشريط الزمني والعودة إلى تلك الحالة بالضبط. ويُقتطع سياق محادثة الوكيل بما يوافقها.
live_agent:
controls:
rollback:
enabled: true
show_checkpoint_diff: true # show what will be undone
require_confirmation: true # "Are you sure?" dialog
keyboard_shortcut: "Ctrl+Z"التفريع وإعادة التشغيل
يجمع التفريع وإعادة التشغيل بين التراجع وإرسال التعليمات. يعود المعلّق إلى نقطة تحقق ويرسل تعليمات مختلفة، فينشأ مسار متفرع. وهذا يفيد عند جمع بيانات التفضيل: إذ يمكنك استكشاف مقاربتين مختلفتين من نقطة البداية نفسها ومقارنة النتائج.
live_agent:
controls:
branch:
enabled: true
max_branches: 5 # maximum branches from any checkpoint
branch_naming: auto # "auto" or "manual"
compare_view: true # side-by-side branch comparison
keyboard_shortcut: "Ctrl+B"يعرض عرض مقارنة الفروع فرعين جنباً إلى جنب مع إبراز موضع تباعدهما. ويمكن للمعلّقين تقييم أي فرع أنتج نتائج أفضل، فتتولد أزواج تفضيل لتدريب DPO.
نظام نقاط التحقق في Git
يستخدم وضع الوكيل المباشر git لتتبع كل تغيير في الملفات. وهذا يوفر تراجعاً موثوقاً وتفريعاً وسجلّ تغييرات كاملاً.
كيف يعمل
- قبل أن يبدأ الوكيل، ينشئ Potato فرع git جديداً باسم
potato-session-{session_id} - بعد كل تغيير في الملفات (تحرير، كتابة، إنشاء، حذف)، يودع Potato تلقائياً برسالة وصفية
- يُوسَم كل إيداع نقطةَ تحقق تظهر في الشريط الزمني
- يستخدم التراجع
git checkoutلاستعادة مجلد العمل إلى أي نقطة تحقق - ينشئ التفريع فرع git جديداً من إيداع نقطة التحقق
التهيئة
live_agent:
git_checkpoints:
enabled: true
branch_prefix: "potato-session"
commit_message_format: "Step {step}: {tool} {file_path}"
auto_commit: true
cleanup_on_complete: false # delete session branches when done
require_clean_working_dir: true # fail if there are uncommitted changesإدارة نقاط التحقق يدوياً
# List all Potato session branches
git branch | grep potato-session
# View checkpoints for a session
git log potato-session-abc123 --oneline
# Clean up old session branches
python -m potato.cleanup_sessions --older-than 7dصيغة البيانات
تحدد بيانات الإدخال لمهام وكيل البرمجة المباشر وصف المهمة، واختيارياً ملف أو مجلد بداية:
{
"id": "task_001",
"task_description": "Fix the bug in src/parser.py where empty input causes a crash",
"project_dir": "/path/to/project",
"start_file": "src/parser.py",
"test_command": "python -m pytest tests/test_parser.py -v",
"context_files": [
"src/parser.py",
"tests/test_parser.py"
]
}| الحقل | مطلوب | الوصف |
|---|---|---|
id | نعم | معرّف فريد للمهمة |
task_description | نعم | ما ينبغي للوكيل فعله |
project_dir | نعم | مسار مجلد المشروع |
start_file | لا | الملف الذي يُعرض للوكيل في البداية |
test_command | لا | الأمر الذي يتحقق من الإصلاح |
context_files | لا | ملفات تُحمَّل مسبقاً في سياق الوكيل |
مرجع التهيئة
تهيئة كاملة لمهمة مراقبة وكيل برمجة مباشر:
task_name: "Live Coding Agent Observation"
task_dir: "."
data_files:
- "data/coding_tasks.jsonl"
item_properties:
id_key: id
text_key: task_description
agentic:
enabled: true
display_type: coding_trace
coding_trace_display:
diff_style: unified
diff_context_lines: 3
syntax_highlight: true
show_line_numbers: true
terminal_theme: dark
file_tree:
enabled: true
position: left
click_to_navigate: true
live_agent:
enabled: true
backend: anthropic
model: claude-sonnet-4-20250514
anthropic:
api_key: ${ANTHROPIC_API_KEY}
max_tokens: 4096
temperature: 0.2
tools:
- read_file
- edit_file
- write_file
- bash
- glob
- grep
max_steps: 100
step_timeout_seconds: 120
controls:
pause_resume:
enabled: true
auto_pause_on_error: true
keyboard_shortcut: "Space"
send_instructions:
enabled: true
inject_as: system_message
presets:
- "Try a different approach"
- "Read the error message carefully"
- "Run the tests first"
rollback:
enabled: true
require_confirmation: true
branch:
enabled: true
max_branches: 5
compare_view: true
git_checkpoints:
enabled: true
branch_prefix: "potato-session"
auto_commit: true
cleanup_on_complete: false
annotation_schemes:
# Per-step ratings during observation
- annotation_type: per_turn_rating
name: step_quality
description: "Rate each agent step as you observe it"
target: agentic_steps
rating_type: radio
labels:
- "Good"
- "Acceptable"
- "Unnecessary"
- "Incorrect"
# Overall task completion after agent finishes
- annotation_type: radio
name: task_completion
description: "Did the agent complete the task?"
labels:
- "Fully Complete"
- "Partially Complete"
- "Failed"
# Branch comparison (when branching is used)
- annotation_type: radio
name: branch_preference
description: "Which branch produced a better result?"
labels:
- "Branch A"
- "Branch B"
- "Both Equal"
- "Both Failed"
# Notes on the observation
- annotation_type: text
name: observation_notes
description: "Describe what you observed and any interventions you made"
label_requirement:
required: false
output_annotation_dir: "output/"
output_annotation_format: "jsonl"تصدير المسارات المتفرعة
حين يستخدم المعلّقون التفريع وإعادة التشغيل، تتضمن المخرجات شجرة التفريع كاملة. وقد صُممت هذه الصيغة لتدريب نماذج التفضيل ونماذج مكافأة العملية من مسارات قابلة للمقارنة.
{
"id": "task_001",
"annotator": "observer_01",
"root_branch": {
"branch_id": "main",
"steps": [
{"step": 0, "type": "file_read", "file": "src/parser.py", "rating": "Good"},
{"step": 1, "type": "edit", "file": "src/parser.py", "rating": "Incorrect"}
],
"children": [
{
"branch_id": "branch_1",
"branch_point": 1,
"instruction": "Try a different approach -- use a try/except block instead",
"steps": [
{"step": 2, "type": "edit", "file": "src/parser.py", "rating": "Good"},
{"step": 3, "type": "terminal", "command": "pytest", "rating": "Good"}
],
"outcome": "Fully Complete",
"children": []
},
{
"branch_id": "branch_2",
"branch_point": 1,
"instruction": "Read the test file first to understand expected behavior",
"steps": [
{"step": 2, "type": "file_read", "file": "tests/test_parser.py", "rating": "Good"},
{"step": 3, "type": "edit", "file": "src/parser.py", "rating": "Good"},
{"step": 4, "type": "terminal", "command": "pytest", "rating": "Good"}
],
"outcome": "Fully Complete",
"children": []
}
]
},
"branch_preference": "Branch B",
"observation_notes": "Both branches solved the problem, but branch B produced cleaner code by reading the tests first."
}صدّر المسارات المتفرعة لتعلّم التفضيل:
# Export as DPO preference pairs from branch comparisons
python -m potato.export \
-i output/ \
-f branching_dpo \
-o results/branch_preferences.jsonl
# Export full trajectory trees
python -m potato.export \
-i output/ \
-f trajectory_tree \
-o results/trajectory_trees.jsonlالأمان
يعمل الوكيل المباشر داخل مجلد المشروع المحدد في بيانات المهمة، وله صلاحية قراءة الملفات وكتابتها وتنفيذها ضمن ذلك المجلد. خذ في الحسبان الممارسات الأمنية التالية:
- العزل في بيئة معزولة: للكود غير الموثوق أو نماذج الوكلاء غير الموثوقة، شغّل Potato داخل حاوية Docker أو آلة افتراضية. فالوكيل قادر على تنفيذ أوامر shell عشوائية، والعزل مهم هنا.
- وضع القراءة فقط: عطّل أداتَي
bashوwrite_fileإذا كنت تريد من الوكيل تحليل الكود فقط من دون تعديله. - قيود الشبكة: استخدم الراية
--network noneفي Docker لمنع الوكيل من إجراء طلبات شبكية. - حدود الموارد: اضبط
max_stepsوstep_timeout_secondsلمنع الوكلاء من الانفلات.
# Restricted tool set for analysis-only tasks
live_agent:
tools:
- read_file
- glob
- grep
# No edit_file, write_file, or bashمعالجة المشكلات
Ollama لا يعمل
Error: Connection refused at http://localhost:11434
شغّل خادم Ollama:
ollama serveوتحقق من أنه يعمل:
ollama listمفتاح API مفقود
Error: ANTHROPIC_API_KEY environment variable not set
اضبط متغير البيئة:
export ANTHROPIC_API_KEY="sk-ant-..."أو أضفه إلى ملف .env في مشروعك. يحمّل Potato ملفات .env تلقائياً.
Git غير مهيّأ
Error: Project directory is not a git repository
يتطلب نظام نقاط التحقق git. هيّئ مستودعاً في مجلد المشروع:
cd /path/to/project
git init
git add -A
git commit -m "Initial commit"الوكيل عالق في حلقة
إذا كرر الوكيل الإجراء نفسه مرات عدة، فقد يكون عالقاً. يكتشف Potato الحلقات حين يتكرر استدعاء الأداة نفسه بالمعاملات نفسها 3 مرات، فيوقف الوكيل مؤقتاً تلقائياً. ويمكنك تعديل هذه العتبة:
live_agent:
loop_detection:
enabled: true
threshold: 3 # pause after N identical consecutive steps
action: pause # "pause" or "terminate"تنظيف فروع الجلسات
تتراكم فروع الجلسات مع الوقت. نظّفها دورياً:
# Remove branches older than 7 days
python -m potato.cleanup_sessions --older-than 7d
# Remove all session branches
python -m potato.cleanup_sessions --all
# Dry run (show what would be deleted)
python -m potato.cleanup_sessions --older-than 7d --dry-runانظر أيضاً
- التعليق التوضيحي لوكيل البرمجة -- التعليق على تتبعات وكلاء البرمجة الساكنة
- تعليق مكافأة العملية -- جمع إشارات مكافأة لكل خطوة لتدريب PRM
- التعليق التوضيحي لمراجعة الأكواد -- مراجعة مضمّنة بنمط PR على GitHub لتغييرات الكود
- التعليق التوضيحي للوكلاء -- التعليق على تتبعات الوكلاء لأغراض عامة
للاطلاع على تفاصيل التنفيذ، راجع الوثائق المصدرية.