Code Assistant¶
เอเจนต์ orchestrator พร้อมการรันโค้ด, file I/O และการเข้าถึง shell มันเขียนสคริปต์ อ่านและอธิบายโค้ด รันเทสต์ แก้บั๊ก และรันคำสั่ง shell ได้ -- ทั้งหมดในเครื่องของคุณเอง
Quickstart (5 นาที)¶
1. ติดตั้งและเริ่มต้น¶
git clone https://github.com/open-jarvis/OpenJarvis.git
cd OpenJarvis
uv sync --extra dev
jarvis init --preset code-assistant
คำสั่งนี้จะเขียน ~/.openjarvis/config.toml ที่ตั้งค่าไว้ล่วงหน้าสำหรับ code assistant
2. เริ่ม LLM ในเครื่องผ่าน Ollama¶
3. ถามคำถามเกี่ยวกับโค้ด¶
เอเจนต์ orchestrator จะวางแผนวิธีการ เขียนโค้ด และรันได้หากคุณอนุมัติ
คำสั่ง CLI¶
# Ask a coding question (uses orchestrator agent by default with this config)
jarvis ask "Write a Python script that parses JSON from stdin"
# Read and explain existing code
jarvis ask "Read main.py and explain the architecture"
# Fix a bug
jarvis ask "Find and fix the bug in test_utils.py"
# Run tests
jarvis ask "Run the test suite and summarize any failures"
# Explicitly specify agent and tools
jarvis ask --agent orchestrator --tools code_interpreter "Calculate the first 20 Fibonacci numbers"
# Interactive chat for iterative coding
jarvis chat
เอกสารอ้างอิง Configuration¶
preset นี้จะเขียนสิ่งนี้ลงใน ~/.openjarvis/config.toml:
[engine]
default = "ollama"
[intelligence]
default_model = "qwen3.5:9b"
# default_model = "qwen3.5:35b" # Better for complex code tasks
[agent]
default_agent = "orchestrator" # Multi-turn with tool selection
max_turns = 10
[tools]
enabled = ["code_interpreter", "file_read", "file_write", "shell_exec", "web_search", "think", "calculator"]
การตั้งค่าหลัก¶
| การตั้งค่า | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|
intelligence.default_model |
qwen3.5:9b |
โมเดลสำหรับสร้างโค้ด ใช้ qwen3.5:35b สำหรับงานซับซ้อน เช่น refactor หรือเปลี่ยนแปลงหลายไฟล์ |
agent.default_agent |
orchestrator |
เอเจนต์แบบหลายรอบที่เลือก tool ซ้ำๆ จนกว่าจะได้คำตอบ |
agent.max_turns |
10 |
จำนวนรอบการเรียกใช้ tool สูงสุด เพิ่มค่านี้สำหรับงานหลายขั้นตอน |
tools.enabled |
7 tools | code_interpreter (รัน Python), file_read, file_write, shell_exec (รันคำสั่ง shell), web_search, think, calculator |
อธิบาย Tools¶
| Tool | สิ่งที่มันทำ |
|---|---|
code_interpreter |
รันโค้ด Python ใน sandbox แล้วคืนผลลัพธ์ |
file_read |
อ่านไฟล์พร้อมตรวจสอบ path เอเจนต์ตรวจดูซอร์สโค้ด, config, log ได้ |
file_write |
เขียนหรือแก้ไขไฟล์ เอเจนต์สร้างสคริปต์, patch โค้ด, เขียน config ได้ |
shell_exec |
รันคำสั่ง shell (เช่น git status, pytest, ls) |
web_search |
ค้นหาเว็บหาเอกสาร, คำตอบจาก Stack Overflow ฯลฯ |
think |
พื้นที่ร่างความคิดภายในสำหรับวางแผนวิธีแก้ปัญหาหลายขั้นตอน |
calculator |
ประเมินนิพจน์ทางคณิตศาสตร์ |
ตัวอย่างงาน¶
# Write a new script
jarvis ask "Write a Python script that converts YAML to JSON"
# Explain existing code
jarvis ask "Read src/openjarvis/core/events.py and explain the EventBus pattern"
# Debug a failing test
jarvis ask "Run pytest tests/test_memory.py -v and fix any failures"
# Refactor code
jarvis ask "Read utils.py and refactor the parse_config function to use dataclasses"
# Generate tests
jarvis ask "Read src/openjarvis/tools/calculator.py and write unit tests for it"
# Shell tasks
jarvis ask "Find all Python files larger than 100KB in this repo"
ข้อควรระวังด้านความปลอดภัย¶
Tool shell_exec และ code_interpreter รันคำสั่งจริงบนเครื่องของคุณ โปรดจำสิ่งเหล่านี้ไว้:
- shell_exec รันคำสั่งใน context ผู้ใช้ปัจจุบันของคุณ มันอ่าน เขียน และลบไฟล์ได้ หลีกเลี่ยงการรันเอเจนต์บนไดเรกทอรีที่มีข้อมูล sensitive โดยไม่ตรวจสอบการเรียก tool ก่อน
- code_interpreter รันโค้ด Python มันเข้าถึง Python environment และแพ็กเกจที่ติดตั้งไว้ของคุณ
- เอเจนต์จะขอการยืนยันก่อนรันคำสั่งที่อาจทำลายข้อมูล เมื่อรันในโหมดโต้ตอบ (
jarvis chat) - สำหรับการแยกตัว (isolation) ที่แข็งแกร่งกว่า ใช้เอเจนต์แบบ sandboxed:
jarvis ask --agent sandboxed --tools code_interpreter "..."ซึ่งรันภายใน container ของ Docker/Podman
การแก้ปัญหา¶
"Tool not found: code_interpreter" -- ตรวจสอบว่า config.toml ของคุณมี code_interpreter อยู่ในรายการ tools.enabled
เอเจนต์วนลูปโดยไม่มีความคืบหน้า -- เพิ่ม max_turns หากงานซับซ้อน หรือใช้โมเดลที่ใหญ่กว่า (qwen3.5:35b) โมเดล 9b จัดการงานไฟล์เดียวส่วนใหญ่ได้ ส่วนการ refactor หลายไฟล์จะได้ประโยชน์จากพารามิเตอร์ที่มากกว่า
คำสั่ง Shell ล้มเหลว -- Tool shell_exec รันคำสั่งสัมพัทธ์กับตำแหน่งที่คุณเปิด jarvis ใช้ cd /path && command ใน prompt ของคุณหากจำเป็น หรือรัน jarvis จากไดเรกทอรีโปรเจกต์
การค้นหาเว็บใช้งานไม่ได้ -- ติดตั้งด้วย uv sync --extra tools-search และตั้งค่า TAVILY_API_KEY
การรันโค้ดค้าง -- code_interpreter มี timeout เริ่มต้นอยู่ สคริปต์ที่รันนานจะถูกยกเลิก แบ่งงานใหญ่ออกเป็นขั้นตอนย่อยๆ