18%

2.5 Built-in Tools

Built-in Tools คืออะไร

Anthropic มี built-in tools ที่พร้อมใช้กับ Claude โดยไม่ต้องเขียนเอง — เป็น tools ที่ Anthropic ออกแบบมาให้ Claude ใช้งานได้อย่างมีประสิทธิภาพ แต่ละ tool มีจุดประสงค์เฉพาะ:

Computer Use (Beta)

ให้ Claude ควบคุมหน้าจอคอมพิวเตอร์ — click, type, scroll, screenshot:

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    tools=[{"type": "computer_20250124", "display_width": 1920, "display_height": 1080}],
    messages=[{"role": "user", "content": "เปิด browser แล้วไปที่ google.com"}]
)

ใช้เมื่อ: ต้อง interact กับ GUI, test web apps, automate desktop tasks ข้อจำกัด: ช้า (ต้อง screenshot ทุก step), ต้องการ display, cost สูง

Text Editor Tool

อ่านและแก้ไขไฟล์อย่าง precise — view, create, replace text:

tools = [{"type": "text_editor_20250124"}]
# Claude จะเรียก: view (อ่านไฟล์), create (สร้างใหม่), 
# str_replace (แก้ text เฉพาะจุด), insert (เพิ่ม text)

ใช้เมื่อ: แก้ code, edit config files, precise text manipulation ข้อดี: Surgical edits (ไม่ต้อง rewrite ทั้งไฟล์), undo-friendly

Bash Tool

Execute shell commands:

tools = [{"type": "bash_20250124"}]
# Claude จะเรียก bash(command="ls -la src/")

ใช้เมื่อ: run tests, install packages, git operations, system commands ข้อจำกัด: security risk (ต้อง sandbox), environment-dependent

ค้นหาข้อมูลจาก internet:

tools = [{"type": "web_search_20250305"}]
# Claude จะค้นหาเมื่อต้องการข้อมูลล่าสุดที่ไม่อยู่ใน training data

ใช้เมื่อ: ต้องการข้อมูล real-time, latest documentation, current events ข้อจำกัด: results อาจไม่ครบ, ต้อง verify

Code Execution

Run code ใน sandbox environment:

tools = [{"type": "code_execution_20250522"}]
# Claude จะเขียนและ run code เพื่อทดสอบ logic, คำนวณ, generate output

ใช้เมื่อ: ต้องคำนวณ, ทดสอบ code snippet, data processing ข้อดี: Safe sandbox, ไม่กระทบ host system

เลือก Tool ไหนเมื่อไหร่

TaskTool
แก้ codeText Editor
Run testsBash
ค้นหาข้อมูลใหม่Web Search
ทดสอบ logicCode Execution
Automate GUIComputer Use

Exam Tips

  • Built-in tools มี type field แทน name + input_schema — format ต่างจาก custom tools
  • Computer Use มี cost สูงสุดเพราะต้อง screenshot ทุก action
  • Text Editor ดีกว่า Bash + sed สำหรับ file editing — precise และ trackable
  • Web Search ให้ข้อมูลที่ใหม่กว่า training data cutoff
  • ข้อสอบอาจถาม trade-offs ระหว่าง built-in tools — จำ use case ของแต่ละ tool