Skip to content

लाइव कोडिंग एजेंट अवलोकन

कोडिंग एजेंट को असल समय में काम करते देखें, pause, rollback और branching के साथ। तीन बैकएंड समर्थित हैं: लोकल मॉडल के लिए Ollama, Anthropic API, और Claude Agent SDK।

v2.4.0 में नया

स्थिर ट्रेस एनोटेशन बताता है कि एजेंट ने क्या किया। लाइव अवलोकन बताता है कि मानवीय मार्गदर्शन मिलने पर एजेंट क्या करता है। Potato का लाइव कोडिंग एजेंट मोड एनोटेटरों को कोडिंग एजेंट का काम असल समय में देखने देता है -- फ़ाइलें पढ़ना, कोड संपादित करना, टेस्ट चलाना -- और किसी भी बिंदु पर दख़ल देने देता है। एजेंट को रोकें, नए निर्देश भेजें, किसी पुराने चेकपॉइंट पर लौटें, या दूसरे तरीक़े आज़माने के लिए ट्रैजेक्टरी की शाखा बनाएँ।

इससे अकेले स्थिर ट्रेस के मुक़ाबले ज़्यादा भरा-पूरा एनोटेशन डेटा मिलता है। आपको टाइमस्टैम्प सहित पूरी ट्रैजेक्टरी मिलती है, एनोटेटर के दख़ल मिलते हैं, शाखा बनने के निर्णय-बिंदु मिलते हैं, और वैकल्पिक रास्तों से तुलनात्मक डेटा मिलता है। यह डेटा प्रोसेस रिवॉर्ड मॉडल, प्रेफ़रेंस मॉडल और निर्देश-पालन मूल्यांकनकर्ता प्रशिक्षित करने में सीधे काम आता है।

आवश्यकताएँ

  • Python 3.10+
  • Git (चेकपॉइंट सिस्टम git कमिट इस्तेमाल करता है)
  • इनमें से कोई एक एजेंट बैकएंड:
    • लोकल मॉडल इन्फ़रेंस के लिए Ollama (API कुंजी की ज़रूरत नहीं)
    • Anthropic API तक पहुँच के लिए ANTHROPIC_API_KEY
    • पूरे Claude Code एजेंट अनुभव के लिए Claude Agent SDK

बैकएंड

Potato कोडिंग एजेंट चलाने के लिए तीन बैकएंड समर्थित करता है। हर बैकएंड एजेंट को एक सबप्रोसेस में चलाता है और उसकी क्रियाएँ असल समय में एनोटेशन इंटरफ़ेस तक स्ट्रीम करता है।

1. Ollama (लोकल मॉडल)

कोडिंग एजेंट लोकल चलाएँ, बिना किसी API कुंजी के। Ollama ओपन-वेट मॉडल के लिए तेज़ इन्फ़रेंस देता है। विकास, परीक्षण, और उन हालात के लिए सबसे उपयुक्त जहाँ डेटा लोकल मशीन से बाहर नहीं जा सकता।

सेटअप:

bash
# 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

कॉन्फ़िगरेशन:

yaml
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: 60

2. Anthropic API

Anthropic API के ज़रिए Claude मॉडल इस्तेमाल करें। टूल इस्तेमाल की क्षमता के साथ मज़बूत कोडिंग प्रदर्शन देता है। इसके लिए API कुंजी चाहिए।

सेटअप:

bash
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."
 
# Or add to .env file
echo "ANTHROPIC_API_KEY=sk-ant-..." >> .env

कॉन्फ़िगरेशन:

yaml
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: 120

3. Claude Agent SDK

Claude Agent SDK पूरा Claude Code एजेंट अनुभव देता है, जिसमें अपने आप टूल ऑर्केस्ट्रेशन, संदर्भ प्रबंधन और बहु-फ़ाइल तर्क शामिल है। यह सबसे सक्षम बैकएंड है, पर इसके लिए SDK इंस्टॉल होना ज़रूरी है।

सेटअप:

bash
# Install the Claude Agent SDK
pip install claude-agent-sdk
 
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."

कॉन्फ़िगरेशन:

yaml
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

एजेंट को चरणों के बीच रोकने के लिए Pause पर क्लिक करें। एजेंट अपना मौजूदा चरण पूरा करके रुक जाता है। एनोटेटर मौजूदा स्थिति देख सकता है, फ़ाइलें जाँच सकता है, और तय कर सकता है कि एजेंट को आगे बढ़ने देना है या दख़ल देना है। एजेंट को आगे बढ़ने देने के लिए Resume पर क्लिक करें।

yaml
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"

निर्देश भेजना

एजेंट रुका हुआ हो तब एनोटेटर नए निर्देश भेजकर उसका रुख़ बदल सकते हैं। यह तब काम आता है जब एजेंट ग़लत रास्ते पर जा रहा हो, या जब एनोटेटर परखना चाहे कि मार्गदर्शन मिलने पर एजेंट कैसे प्रतिक्रिया देता है।

yaml
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 विकल्प तय करता है कि वे सिस्टम संदेश (आधिकारिक निर्देश) के रूप में दिखें या उपयोगकर्ता संदेश (बातचीत जैसा मार्गदर्शन) के रूप में।

Rollback

Rollback परियोजना को किसी पुराने git चेकपॉइंट पर लौटा देता है। एजेंट जो भी फ़ाइल बदलाव करता है वह अपने आप कमिट हो जाता है, इसलिए एनोटेटर टाइमलाइन में किसी भी पिछले चरण पर क्लिक करके ठीक उसी स्थिति में लौट सकता है। एजेंट का संवाद संदर्भ भी उसी हिसाब से छाँट दिया जाता है।

yaml
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"

शाखा और रीप्ले

शाखा और रीप्ले rollback को निर्देश भेजने के साथ जोड़ देता है। एनोटेटर किसी चेकपॉइंट पर लौटता है और अलग निर्देश भेजता है, जिससे शाखाओं वाली ट्रैजेक्टरी बनती है। प्रेफ़रेंस डेटा जुटाते समय यह काम आता है: आप एक ही शुरुआती बिंदु से दो अलग तरीक़े आज़माकर नतीजों की तुलना कर सकते हैं।

yaml
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 इस्तेमाल करता है। इससे भरोसेमंद rollback, branching और पूरा बदलाव इतिहास मिलता है।

यह कैसे काम करता है

  1. एजेंट के शुरू होने से पहले Potato potato-session-{session_id} नाम की एक नई git शाखा बनाता है
  2. हर फ़ाइल बदलाव (edit, write, create, delete) के बाद Potato अपने आप एक वर्णनात्मक संदेश के साथ कमिट कर देता है
  3. हर कमिट को चेकपॉइंट के रूप में टैग किया जाता है, जो टाइमलाइन में दिखता है
  4. Rollback किसी भी चेकपॉइंट की वर्किंग डायरेक्टरी लौटाने के लिए git checkout इस्तेमाल करता है
  5. Branching चेकपॉइंट कमिट से एक नई git शाखा बनाता है

कॉन्फ़िगरेशन

yaml
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

चेकपॉइंट का मैन्युअल प्रबंधन

bash
# 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

डेटा फ़ॉर्मैट

लाइव कोडिंग एजेंट टास्क का इनपुट डेटा टास्क विवरण बताता है, और चाहे तो एक शुरुआती फ़ाइल या डायरेक्टरी भी:

json
{
  "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नहींएजेंट के संदर्भ में पहले से लोड की जाने वाली फ़ाइलें

कॉन्फ़िगरेशन संदर्भ

लाइव कोडिंग एजेंट अवलोकन टास्क का पूरा कॉन्फ़िगरेशन:

yaml
annotation_task_name: "Live Coding Agent Observation"
task_dir: "."
 
data_files:
  - "data/coding_tasks.jsonl"
 
item_properties:
  id_key: id
  text_key: task_description
 
instance_display:
  fields:
    - key: structured_turns
      type: coding_trace
      label: "Agent session"
      display_options:
        diff_view: unified
        terminal_theme: dark
        collapse_long_outputs: true
        max_output_lines: 50
        show_file_tree: true
        show_step_numbers: true
        show_reasoning: 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: trajectory_eval
    name: step_quality
    description: "Rate each agent step as you observe it"
    steps_key: agentic_steps
    correctness_options:
      - "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/"
export_annotation_format: "jsonl"

शाखाओं वाली ट्रैजेक्टरी का निर्यात

जब एनोटेटर शाखा और रीप्ले इस्तेमाल करते हैं, तो आउटपुट में पूरा शाखा-वृक्ष शामिल होता है। यह फ़ॉर्मैट तुलनात्मक ट्रैजेक्टरी से प्रेफ़रेंस मॉडल और प्रोसेस रिवॉर्ड मॉडल प्रशिक्षित करने के लिए बना है।

json
{
  "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."
}

प्रेफ़रेंस लर्निंग के लिए शाखाओं वाली ट्रैजेक्टरी निर्यात करें:

bash
python -m potato.export \
  -c config.yaml \
  -f trajectory_correction \
  -o results/

सुरक्षा

लाइव एजेंट टास्क डेटा में बताई गई परियोजना डायरेक्टरी में चलता है। उस डायरेक्टरी के भीतर उसे फ़ाइलें पढ़ने, लिखने और चलाने की पहुँच होती है। इन सुरक्षा तरीक़ों पर ध्यान दें:

  • सैंडबॉक्सिंग: अविश्वसनीय कोड या अविश्वसनीय एजेंट मॉडल के लिए Potato को Docker कंटेनर या VM के भीतर चलाएँ। एजेंट कोई भी शेल कमांड चला सकता है, इसलिए अलगाव ज़रूरी है।
  • केवल-पठन मोड: अगर आप चाहते हैं कि एजेंट कोड बदले बिना सिर्फ़ उसका विश्लेषण करे, तो bash और write_file टूल बंद कर दें।
  • नेटवर्क पाबंदी: एजेंट को नेटवर्क अनुरोध करने से रोकने के लिए Docker का --network none फ़्लैग इस्तेमाल करें।
  • संसाधन सीमाएँ: भागते हुए एजेंट रोकने के लिए max_steps और step_timeout_seconds सेट करें।
yaml
# Restricted tool set for analysis-only tasks
live_agent:
  tools:
    - read_file
    - glob
    - grep
  # No edit_file, write_file, or bash

समस्या निवारण

Ollama नहीं चल रहा

text
Error: Connection refused at http://localhost:11434

Ollama सर्वर शुरू करें:

bash
ollama serve

जाँचें कि वह चल रहा है:

bash
ollama list

API कुंजी नदारद

text
Error: ANTHROPIC_API_KEY environment variable not set

एनवायरनमेंट वेरिएबल सेट करें:

bash
export ANTHROPIC_API_KEY="sk-ant-..."

या उसे अपनी परियोजना की .env फ़ाइल में जोड़ें। Potato .env फ़ाइलें अपने आप लोड कर लेता है।

Git शुरू नहीं किया गया

text
Error: Project directory is not a git repository

चेकपॉइंट सिस्टम के लिए git चाहिए। परियोजना डायरेक्टरी में एक रिपॉज़िटरी शुरू करें:

bash
cd /path/to/project
git init
git add -A
git commit -m "Initial commit"

एजेंट लूप में फँसा है

अगर एजेंट वही क्रिया बार-बार दोहराता है, तो शायद वह फँस गया है। जब एक ही टूल कॉल उन्हीं आर्गुमेंट के साथ 3 बार दोहराई जाती है तो Potato लूप पकड़ लेता है और एजेंट को अपने आप रोक देता है। यह सीमा आप बदल सकते हैं:

yaml
live_agent:
  loop_detection:
    enabled: true
    threshold: 3                     # pause after N identical consecutive steps
    action: pause                    # "pause" or "terminate"

सत्र शाखाओं की सफ़ाई

समय के साथ सत्र शाखाएँ जमा होती जाती हैं। उन्हें समय-समय पर साफ़ करें:

bash
# 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

यह भी देखें

कार्यान्वयन के विवरण के लिए स्रोत दस्तावेज़ देखें।