agents.mdx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. ---
  2. title: เอเจนต์
  3. description: เอเจนต์พิเศษและปรับแต่งได้
  4. ---
  5. เอเจนต์ (Agent) คือผู้ช่วย AI ที่เชี่ยวชาญในงานเฉพาะด้าน คุณสามารถสร้างเอเจนต์ที่มีเครื่องมือ (tools) ที่เหมาะสมกับงานและคำสั่งระบบ (system prompt) ที่ต้องการได้
  6. :::tip
  7. ใช้เอเจนต์ **Plan** เพื่อวิเคราะห์โค้ดและตรวจสอบเหตุผลก่อนทำการเปลี่ยนแปลงโค้ดใดๆ
  8. :::
  9. คุณสามารถสลับเอเจนต์ได้ระหว่างการสนทนาโดยใช้ปุ่ม **Tab** หรือเรียกใช้โดยระบุ `@`
  10. ---
  11. ## ประเภท
  12. OpenCode มีเอเจนต์สองประเภท: **Primary Agent** (เอเจนต์หลัก) และ **Subagent** (เอเจนต์ย่อย)
  13. ---
  14. ### Primary Agent (เอเจนต์หลัก)
  15. Primary Agent คือผู้ช่วยหลักที่คุณคุยด้วยโดยตรง คุณสามารถวนดูเอเจนต์หลักที่มีอยู่ได้โดยกดปุ่ม **Tab** หรือปุ่ม `switch_agent` ที่ตั้งค่าไว้ เอเจนต์เหล่านี้สามารถจัดการงานที่ซับซ้อนและเข้าถึงเครื่องมือที่มีความเสี่ยงสูงได้ เช่น **Build** ที่มีเครื่องมือทั้งหมด หรือ **Plan** ที่ถูกจำกัดสิทธิ์
  16. :::tip
  17. **Tab** จะเก็บประวัติการสนทนาไว้เมื่อสลับระหว่างเอเจนต์
  18. :::
  19. OpenCode มีเอเจนต์หลักในตัวได้แก่ **Build** และ **Plan**
  20. ดูรายละเอียดด้านล่าง
  21. ---
  22. ### Subagent (เอเจนต์ย่อย)
  23. Subagent คือผู้ช่วยเฉพาะทางที่ Primary Agent สามารถเรียกใช้งานได้ หรือคุณสามารถเรียกใช้โดยตรงโดยพิมพ์ **@** ตามด้วยชื่อเอเจนต์ในข้อความของคุณ
  24. OpenCode มี subagent ในตัวได้แก่ **General**, **Explore** และ **Scout** ดูรายละเอียดด้านล่าง
  25. ---
  26. ## บิวท์อิน
  27. OpenCode มาพร้อมกับเอเจนต์หลัก 2 ตัวและ subagent ในตัว 3 ตัว
  28. ---
  29. ### Build
  30. _Mode_: `primary`
  31. เอเจนต์หลักสำหรับ **การพัฒนา** มาพร้อมกับเครื่องมือทั้งหมดเพื่อให้มีสิทธิ์การเข้าถึงไฟล์และคำสั่งระบบโดยสมบูรณ์
  32. ---
  33. ### Plan
  34. _Mode_: `primary`
  35. เอเจนต์ที่ถูกจำกัดสิทธิ์ เน้นการคิดวิเคราะห์และวางแผน โดยป้องกันการเปลี่ยนแปลงไฟล์โดยไม่ได้ตั้งใจ
  36. เครื่องมือต่อไปนี้จะถูกตั้งค่าเป็น `ask` (ต้องขออนุญาต):
  37. - `file edits`: การแก้ไขไฟล์, patch, และการเขียนไฟล์
  38. - `bash`: คำสั่ง bash ทั้งหมด
  39. เอเจนต์นี้มีประโยชน์เมื่อต้องการให้ LLM ตรวจสอบโค้ด หรือสร้างแผนงานก่อนที่จะลงมือทำจริง
  40. ---
  41. ### General
  42. _Mode_: `subagent`
  43. เอเจนต์สำหรับตอบคำถามทั่วไปและการคิดวิเคราะห์หลายขั้นตอน อนุญาตให้เข้าถึงเครื่องมือต่างๆ (ยกเว้นการแก้ไขไฟล์) ใช้สิ่งนี้เมื่อต้องการรันงานที่ไม่ต้องแก้ไขโค้ด
  44. ---
  45. ### Explore
  46. _Mode_: `subagent`
  47. เอเจนต์ความเร็วสูงสำหรับอ่านและสำรวจ codebase ใช้สิ่งนี้เมื่อคุณต้องการค้นหาไฟล์อย่างรวดเร็ว, ค้นหาโค้ดด้วยคำสำคัญ, หรือสอบถามเกี่ยวกับโครงสร้าง codebase
  48. ---
  49. ### Scout
  50. _Mode_: `subagent`
  51. เอเจนต์แบบอ่านอย่างเดียวสำหรับค้นคว้าเอกสารภายนอกและ dependency ใช้สิ่งนี้เมื่อคุณต้องการ clone repository ของ dependency เข้าไปใน cache ที่ OpenCode จัดการให้, ตรวจสอบ source code ของไลบรารี, หรือเทียบโค้ดในเครื่องกับ implementation จาก upstream โดยไม่แก้ไข workspace ของคุณ
  52. ---
  53. ### Compact
  54. _Mode_: `primary`
  55. เอเจนต์ระบบที่มีหน้าที่สรุปประวัติการสนทนาที่ยาวให้สั้นลง โดยยังคงใจความสำคัญไว้
  56. ---
  57. ### Name
  58. _Mode_: `primary`
  59. เอเจนต์ระบบที่มีหน้าที่สร้างชื่อ session ให้สั้นและได้ใจความ ทำงานอัตโนมัติโดยไม่ต้องมี UI
  60. ---
  61. ### Summarize
  62. _Mode_: `primary`
  63. เอเจนต์ระบบที่มีหน้าที่สร้างสรุปการเปลี่ยนแปลงและงานที่ทำไป ทำงานอัตโนมัติโดยไม่ต้องมี UI
  64. ---
  65. ## การใช้งาน
  66. 1. สำหรับ Primary Agent ให้ใช้ปุ่ม **Tab** เพื่อวนดูเอเจนต์ที่มีอยู่ หรือใช้ keybind `switch_agent` ที่คุณตั้งค่าไว้
  67. 2. สำหรับ Subagent:
  68. - เรียกใช้โดย Primary Agent โดยอัตโนมัติตามความเหมาะสม
  69. - เรียกใช้ด้วยตนเองโดยพิมพ์ **@** ตามด้วยชื่อ subagent ในข้อความของคุณ เช่น
  70. ```txt frame="none"
  71. @general help me search for this function
  72. ```
  73. 3. **การนำทางระหว่าง Agent**: เมื่อ Subagent ทำงานเสร็จและส่งผลลัพธ์กลับมายัง Primary Agent คุณสามารถดูประวัติการทำงานได้:
  74. - **\<Leader>+Right** (หรือ `session_child_cycle` keybind) เพื่อวนผ่าน parent → child1 → child2 → ... → parent
  75. - **\<Leader>+Left** (หรือ `session_child_cycle_reverse` keybind) เพื่อวนย้อนกลับผ่าน parent ← child1 ← child2 ← ... ← parent
  76. ---
  77. ## การกำหนดค่า
  78. คุณสามารถปรับแต่งเอเจนต์ที่มีอยู่หรือสร้างเอเจนต์ใหม่ได้สองวิธี:
  79. ---
  80. ### JSON
  81. กำหนดค่าเอเจนต์ในไฟล์ `opencode.json` ของคุณ:
  82. ```json title="opencode.json"
  83. {
  84. "$schema": "https://opencode.ai/config.json",
  85. "agent": {
  86. "build": {
  87. "mode": "primary",
  88. "model": "anthropic/claude-sonnet-4-20250514",
  89. "prompt": "{file:./prompts/build.txt}",
  90. "tools": {
  91. "write": true,
  92. "edit": true,
  93. "bash": true
  94. }
  95. },
  96. "plan": {
  97. "mode": "primary",
  98. "model": "anthropic/claude-haiku-4-20250514",
  99. "tools": {
  100. "write": false,
  101. "edit": false,
  102. "bash": false
  103. }
  104. },
  105. "code-reviewer": {
  106. "description": "Reviews code for best practices and potential issues",
  107. "mode": "subagent",
  108. "model": "anthropic/claude-sonnet-4-20250514",
  109. "prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
  110. "tools": {
  111. "write": false,
  112. "edit": false
  113. }
  114. }
  115. }
  116. }
  117. ```
  118. ---
  119. ### Markdown
  120. คุณสามารถกำหนดเอเจนต์ด้วยไฟล์ Markdown ได้ใน:
  121. - ระดับผู้ใช้ (Global): `~/.config/opencode/agents/`
  122. - ระดับโปรเจ็กต์: `.opencode/agents/`
  123. ```markdown title="~/.config/opencode/agents/review.md"
  124. ---
  125. description: Reviews code for quality and best practices
  126. mode: subagent
  127. model: anthropic/claude-sonnet-4-20250514
  128. temperature: 0.1
  129. tools:
  130. write: false
  131. edit: false
  132. bash: false
  133. ---
  134. You are in code review mode. Focus on:
  135. - Code quality and best practices
  136. - Potential bugs and edge cases
  137. - Performance implications
  138. - Security considerations
  139. Provide constructive feedback without making direct changes.
  140. ```
  141. ชื่อไฟล์ Markdown จะกลายเป็นชื่อเอเจนต์ เช่น `review.md` สร้างเอเจนต์ `review`
  142. ---
  143. ## ตัวเลือก
  144. มาดูรายละเอียดของตัวเลือกต่างๆ
  145. ---
  146. ### Description (คำอธิบาย)
  147. ใช้ฟิลด์ `description` เพื่ออธิบายว่าเอเจนต์นี้ทำอะไร
  148. ```json title="opencode.json"
  149. {
  150. "agent": {
  151. "review": {
  152. "description": "Reviews code for best practices and potential issues"
  153. }
  154. }
  155. }
  156. ```
  157. ฟิลด์นี้ **จำเป็น** สำหรับ JSON
  158. ---
  159. ### Temperature (อุณหภูมิ)
  160. ควบคุมความสุ่มและความคิดสร้างสรรค์ของการตอบกลับของ LLM ด้วย `temperature`
  161. ค่าที่ต่ำกว่าจะให้ผลลัพธ์ที่แน่นอนและแม่นยำกว่า ส่วนค่าที่สูงกว่าจะให้ความหลากหลายและความคิดสร้างสรรค์มากกว่า
  162. ```json title="opencode.json"
  163. {
  164. "agent": {
  165. "plan": {
  166. "temperature": 0.1
  167. },
  168. "creative": {
  169. "temperature": 0.8
  170. }
  171. }
  172. }
  173. ```
  174. ช่วงอุณหภูมิอยู่ระหว่าง 0.0 ถึง 1.0:
  175. - **0.0-0.2**: แน่นอนและแม่นยำ เหมาะสำหรับการเขียนโค้ดและการวางแผน
  176. - **0.3-0.5**: สมดุล เหมาะสำหรับการพัฒนาทั่วไป
  177. - **0.6-1.0**: สร้างสรรค์ เหมาะสำหรับการระดมสมอง
  178. ```json title="opencode.json"
  179. {
  180. "agent": {
  181. "analyze": {
  182. "temperature": 0.1,
  183. "prompt": "{file:./prompts/analysis.txt}"
  184. },
  185. "build": {
  186. "temperature": 0.3
  187. },
  188. "brainstorm": {
  189. "temperature": 0.7,
  190. "prompt": "{file:./prompts/creative.txt}"
  191. }
  192. }
  193. }
  194. ```
  195. หมายเหตุ: OpenCode ค่าเริ่มต้นคือ 0 สำหรับโมเดลส่วนใหญ่ และ 0.55 สำหรับโมเดล Qwen
  196. ---
  197. ### Steps (ขั้นตอน)
  198. จำกัดจำนวนการวนซ้ำ (iterations) สูงสุดที่เอเจนต์สามารถทำได้ เพื่อควบคุมค่าใช้จ่ายและป้องกันการทำงานไม่รู้จบ
  199. หากไม่ได้ตั้งค่านี้ เอเจนต์จะทำงานต่อไปจนกว่างานจะเสร็จหรือผู้ใช้ขัดจังหวะ
  200. ```json title="opencode.json"
  201. {
  202. "agent": {
  203. "quick-thinker": {
  204. "description": "Fast reasoning with limited iterations",
  205. "prompt": "You are a quick thinker. Solve problems with minimal steps.",
  206. "steps": 5
  207. }
  208. }
  209. }
  210. ```
  211. เมื่อถึงขีดจำกัด เอเจนต์จะได้รับพรอมต์พิเศษเพื่อสรุปงานและสิ่งที่เหลืออยู่
  212. :::caution
  213. ฟิลด์ `maxSteps` แบบเดิมเลิกใช้แล้ว โปรดใช้ `steps` แทน
  214. :::
  215. ---
  216. ### Disable (ปิดใช้งาน)
  217. ตั้งค่าเป็น `true` เพื่อปิดการใช้งานเอเจนต์
  218. ```json title="opencode.json"
  219. {
  220. "agent": {
  221. "review": {
  222. "disable": true
  223. }
  224. }
  225. }
  226. ```
  227. ---
  228. ### พรอมต์
  229. ระบุ System Prompt สำหรับเอเจนต์นี้ด้วย `prompt`
  230. ```json title="opencode.json"
  231. {
  232. "agent": {
  233. "review": {
  234. "prompt": "{file:./prompts/code-review.txt}"
  235. }
  236. }
  237. }
  238. ```
  239. รองรับเส้นทางสัมพัทธ์ (Relative paths) ซึ่งทำให้ใช้งานได้สะดวกทั้งในระดับ Global และ Project
  240. ---
  241. ### Model (โมเดล)
  242. ใช้ตัวเลือก `model` เพื่อกำหนดโมเดลเฉพาะสำหรับเอเจนต์นี้ มีประโยชน์เมื่อต้องการใช้โมเดลที่เชี่ยวชาญเฉพาะด้าน หรือโมเดลที่มี Context window ขนาดใหญ่สำหรับการตรวจสอบ codebase
  243. :::tip
  244. หากไม่ได้ระบุโมเดล เอเจนต์จะใช้ [โมเดลเริ่มต้น](/docs/config#models) ของ OpenCode
  245. :::
  246. ```json title="opencode.json"
  247. {
  248. "agent": {
  249. "plan": {
  250. "model": "anthropic/claude-haiku-4-20250514"
  251. }
  252. }
  253. }
  254. ```
  255. ID ของโมเดลใช้รูปแบบ `provider/model-id`
  256. ---
  257. ### เครื่องมือ
  258. กำหนดเครื่องมือที่เอเจนต์สามารถใช้งานได้ด้วย `tools` คุณสามารถระบุชื่อเครื่องมือ หรือใช้ wildcard
  259. ```json title="opencode.json" {3-6,9-12}
  260. {
  261. "$schema": "https://opencode.ai/config.json",
  262. "tools": {
  263. "write": true,
  264. "bash": true
  265. },
  266. "agent": {
  267. "plan": {
  268. "tools": {
  269. "write": false,
  270. "bash": false
  271. }
  272. }
  273. }
  274. }
  275. ```
  276. :::note
  277. การกำหนดค่าเครื่องมือในระดับเอเจนต์จะมีความสำคัญเหนือกว่าระดับ Global
  278. :::
  279. คุณสามารถใช้ wildcard `*` เพื่อควบคุมเครื่องมือหลายรายการพร้อมกัน เช่น เครื่องมือจากเซิร์ฟเวอร์ MCP:
  280. ```json title="opencode.json"
  281. {
  282. "$schema": "https://opencode.ai/config.json",
  283. "agent": {
  284. "readonly": {
  285. "tools": {
  286. "mymcp_*": false,
  287. "write": false,
  288. "edit": false
  289. }
  290. }
  291. }
  292. }
  293. ```
  294. [เรียนรู้เพิ่มเติมเกี่ยวกับเครื่องมือ](/docs/tools)
  295. ---
  296. ### Permissions (สิทธิ์)
  297. กำหนดสิทธิ์สำหรับเครื่องมือที่มีความละเอียดอ่อน เช่น `edit`, `bash` และ `webfetch`:
  298. - `"ask"` — ต้องขออนุมัติจากผู้ใช้ก่อน
  299. - `"allow"` — อนุญาตให้ทำงานได้โดยไม่ต้องถาม
  300. - `"deny"` — ไม่อนุญาตให้ใช้
  301. ```json title="opencode.json"
  302. {
  303. "$schema": "https://opencode.ai/config.json",
  304. "permission": {
  305. "edit": "deny"
  306. }
  307. }
  308. ```
  309. คุณสามารถกำหนดสิทธิ์ในระดับเอเจนต์ได้:
  310. ```json title="opencode.json" {3-5,8-10}
  311. {
  312. "$schema": "https://opencode.ai/config.json",
  313. "permission": {
  314. "edit": "deny"
  315. },
  316. "agent": {
  317. "build": {
  318. "permission": {
  319. "edit": "ask"
  320. }
  321. }
  322. }
  323. }
  324. ```
  325. ใน Markdown agent:
  326. ```markdown title="~/.config/opencode/agents/review.md"
  327. ---
  328. description: Code review without edits
  329. mode: subagent
  330. permission:
  331. edit: deny
  332. bash:
  333. "*": ask
  334. "git diff": allow
  335. "git log*": allow
  336. "grep *": allow
  337. webfetch: deny
  338. ---
  339. Only analyze code and suggest changes.
  340. ```
  341. คุณสามารถกำหนดสิทธิ์สำหรับคำสั่ง bash เฉพาะได้:
  342. ```json title="opencode.json" {7}
  343. {
  344. "$schema": "https://opencode.ai/config.json",
  345. "agent": {
  346. "build": {
  347. "permission": {
  348. "bash": {
  349. "git push": "ask",
  350. "grep *": "allow"
  351. }
  352. }
  353. }
  354. }
  355. }
  356. ```
  357. รองรับ glob patterns:
  358. ```json title="opencode.json" {7}
  359. {
  360. "$schema": "https://opencode.ai/config.json",
  361. "agent": {
  362. "build": {
  363. "permission": {
  364. "bash": {
  365. "git *": "ask"
  366. }
  367. }
  368. }
  369. }
  370. }
  371. ```
  372. ใช้ `*` wildcard เพื่อตั้งค่าเริ่มต้นสำหรับคำสั่งอื่นๆ ทั้งหมด กฎที่ตรงกันล่าสุดจะมีผลบังคับใช้ (Last match wins):
  373. ```json title="opencode.json" {8}
  374. {
  375. "$schema": "https://opencode.ai/config.json",
  376. "agent": {
  377. "build": {
  378. "permission": {
  379. "bash": {
  380. "*": "ask",
  381. "git status *": "allow"
  382. }
  383. }
  384. }
  385. }
  386. }
  387. ```
  388. [เรียนรู้เพิ่มเติมเกี่ยวกับสิทธิ์](/docs/permissions)
  389. ---
  390. ### Mode (โหมด)
  391. กำหนดโหมดของเอเจนต์ด้วย `mode`
  392. ```json title="opencode.json"
  393. {
  394. "agent": {
  395. "review": {
  396. "mode": "subagent"
  397. }
  398. }
  399. }
  400. ```
  401. `mode` สามารถเป็น `primary`, `subagent` หรือ `all` หากไม่ระบุ ค่าเริ่มต้นจะเป็น `all`
  402. ---
  403. ### Hidden (ซ่อน)
  404. ซ่อน subagent จากเมนู autocomplete `@` ด้วย `hidden: true` มีประโยชน์สำหรับ subagent ภายในที่ถูกเรียกใช้โดยเอเจนต์อื่นผ่านเครื่องมือ task เท่านั้น
  405. ```json title="opencode.json"
  406. {
  407. "agent": {
  408. "internal-helper": {
  409. "mode": "subagent",
  410. "hidden": true
  411. }
  412. }
  413. }
  414. ```
  415. :::note
  416. ใช้ได้กับเอเจนต์ที่มี `mode: subagent` เท่านั้น
  417. :::
  418. ---
  419. ### Task Permissions (สิทธิ์งาน)
  420. กำหนดว่า subagent ใดที่เอเจนต์นี้สามารถเรียกใช้ได้ผ่านเครื่องมือ task ด้วย `permission.task`
  421. ```json title="opencode.json"
  422. {
  423. "agent": {
  424. "orchestrator": {
  425. "mode": "primary",
  426. "permission": {
  427. "task": {
  428. "*": "deny",
  429. "orchestrator-*": "allow",
  430. "code-reviewer": "ask"
  431. }
  432. }
  433. }
  434. }
  435. }
  436. ```
  437. หากตั้งเป็น `deny` เอเจนต์จะมองไม่เห็นเครื่องมือ task สำหรับ subagent นั้นๆ
  438. :::tip
  439. กฎทำงานตามลำดับ และ **กฎที่ตรงกันล่าสุดจะมีผล** ในตัวอย่างข้างต้น `orchestrator-planner` ตรงกับทั้ง `*` (deny) และ `orchestrator-*` (allow) แต่เนื่องจาก `orchestrator-*` มาทีหลัง ผลลัพธ์จึงเป็น `allow`
  440. :::
  441. ---
  442. ### สี
  443. ปรับแต่งสีของเอเจนต์ใน UI ด้วยตัวเลือก `color`
  444. ใช้รหัสสี hex (เช่น `#FF5733`) หรือชื่อสีมาตรฐาน: `primary`, `secondary`, `accent`, `success`, `warning`, `error`, `info`
  445. ```json title="opencode.json"
  446. {
  447. "agent": {
  448. "creative": {
  449. "color": "#ff6b6b"
  450. },
  451. "code-reviewer": {
  452. "color": "accent"
  453. }
  454. }
  455. }
  456. ```
  457. ---
  458. ### Top P
  459. ควบคุมความหลากหลายของการตอบกลับด้วยตัวเลือก `top_p`
  460. ```json title="opencode.json"
  461. {
  462. "agent": {
  463. "brainstorm": {
  464. "top_p": 0.9
  465. }
  466. }
  467. }
  468. ```
  469. ช่วงค่า 0.0 ถึง 1.0 ค่าที่ต่ำกว่าจะเน้นไปที่โทเค็นที่มีความน่าจะเป็นสูง
  470. ---
  471. ### Additional (เพิ่มเติม)
  472. คุณสมบัติอื่นๆ ที่คุณระบุใน object ของเอเจนต์จะถูก **ส่งผ่านโดยตรง** ไปยัง LLM config
  473. เช่น สำหรับโมเดลที่มีการให้เหตุผลของ OpenAI:
  474. ```json title="opencode.json" {6,7}
  475. {
  476. "agent": {
  477. "deep-thinker": {
  478. "description": "Agent that uses high reasoning effort for complex problems",
  479. "model": "openai/gpt-5",
  480. "reasoningEffort": "high",
  481. "textVerbosity": "low"
  482. }
  483. }
  484. }
  485. ```
  486. ตรวจสอบเอกสารของแต่ละโมเดลสำหรับตัวเลือกที่รองรับ
  487. :::tip
  488. ใช้ `opencode models` เพื่อดูรายการตัวเลือกทั้งหมด
  489. :::
  490. ---
  491. ## การสร้างเอเจนต์
  492. สร้างเอเจนต์ใหม่ด้วยคำสั่ง:
  493. ```bash
  494. opencode agent create
  495. ```
  496. คำสั่งแบบโต้ตอบจะถาม:
  497. 1. สถานที่บันทึก (Global หรือ Project)
  498. 2. คำอธิบายหน้าที่ของเอเจนต์
  499. 3. สร้างพรอมต์และเลือกไอคอนที่เหมาะสม
  500. 4. เลือกเครื่องมือที่เอเจนต์สามารถใช้ได้
  501. 5. สร้างไฟล์ Markdown ของเอเจนต์
  502. ---
  503. ## ตัวอย่างการใช้งาน
  504. ต่อไปนี้เป็นกรณีการใช้งานทั่วไปสำหรับเอเจนต์ต่างๆ
  505. - **Developer**: งานพัฒนาทั่วไป ใช้เครื่องมือทั้งหมด
  506. - **Planner**: วิเคราะห์และวางแผนโดยไม่ทำการเปลี่ยนแปลง
  507. - **Reviewer**: ตรวจสอบโค้ดแบบอ่านอย่างเดียว (Read-only)
  508. - **Debugger**: แก้ไขข้อผิดพลาดโดยเน้นการอ่าน log และทดสอบ
  509. - **Docs Writer**: เขียนและปรับปรุงเอกสาร
  510. ---
  511. ## ตัวอย่างเอเจนต์
  512. นี่คือตัวอย่างเอเจนต์ที่คุณอาจพบว่ามีประโยชน์
  513. :::tip
  514. คุณมีเอเจนต์เจ๋งๆ ที่ต้องการแบ่งปันหรือไม่? [ส่ง PR มาที่นี่](https://github.com/anomalyco/opencode)
  515. :::
  516. ### Docs Writer
  517. ```markdown title="~/.config/opencode/agents/docs-writer.md"
  518. ---
  519. description: Writes and maintains project documentation
  520. mode: subagent
  521. tools:
  522. bash: false
  523. ---
  524. You are a technical writer. Create clear, comprehensive documentation.
  525. Focus on:
  526. - Clear explanations
  527. - Proper structure
  528. - Code examples
  529. - User-friendly language
  530. ```
  531. ---
  532. ### Security Auditor
  533. ```markdown title="~/.config/opencode/agents/security-auditor.md"
  534. ---
  535. description: Performs security audits and identifies vulnerabilities
  536. mode: subagent
  537. tools:
  538. write: false
  539. edit: false
  540. ---
  541. You are a security expert. Focus on identifying potential security issues.
  542. Look for:
  543. - Input validation vulnerabilities
  544. - Authentication and authorization flaws
  545. - Data exposure risks
  546. - Dependency vulnerabilities
  547. - Configuration security issues
  548. ```