โหมดตัวแทน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Gemini ในโหมดเอเจนต์ของ Android Studio ออกแบบมาเพื่อจัดการงานพัฒนาที่ซับซ้อนและมีหลายขั้นตอน
ซึ่งมากกว่าที่คุณจะได้รับจากการแชทกับ
Gemini เพียงอย่างเดียว คุณสามารถอธิบายเป้าหมายระดับสูง แล้วเอเจนต์จะสร้างและ
ดำเนินการตามแผน โดยเรียกใช้เครื่องมือที่จำเป็น ทำการเปลี่ยนแปลง
ในหลายไฟล์ และแก้ไขข้อบกพร่องซ้ำๆ ขั้นตอนการทำงานที่ได้รับความช่วยเหลือจากตัวแทนนี้
ช่วยให้คุณรับมือกับความท้าทายที่ซับซ้อนและเร่งกระบวนการพัฒนา
ได้
เริ่มต้นใช้งาน
หากต้องการเริ่มต้นใช้งานโหมดตัวแทนใน Android Studio ให้ทำตามขั้นตอนต่อไปนี้
- คลิก Gemini
ในแถบด้านข้าง ลงชื่อเข้าใช้และเริ่มต้นใช้งานหากจำเป็น
- เลือกแท็บตัวแทน
- อธิบายงานที่คุณต้องการให้เอเจนต์ดำเนินการ
เมื่อตัวแทนทำตามขั้นตอนเพื่อทำงานให้เสร็จ คุณจะมี
ตัวเลือกในการตรวจสอบและอนุมัติการเปลี่ยนแปลง
ไม่บังคับ: หากต้องการอนุมัติการเปลี่ยนแปลงโดยอัตโนมัติ ให้เลือกตัวเลือกเอเจนต์
> อนุมัติการเปลี่ยนแปลงโดยอัตโนมัติ
กรณีการใช้งาน
ตัวอย่างกรณีการใช้งานที่ตัวแทนช่วยคุณได้มีดังนี้
แก้ไขข้อผิดพลาดในการสร้าง เมื่อคุณขอให้ตัวแทนแก้ไขข้อผิดพลาดในการบิลด์โดยใช้พรอมต์
เช่น "แก้ไขข้อผิดพลาดในการบิลด์ในโปรเจ็กต์ของฉัน" ตัวแทนจะใช้การแก้ไขที่แนะนำ บิลด์
โปรเจ็กต์เพื่อยืนยันโซลูชัน และทำซ้ำจนกว่าปัญหาจะได้รับการแก้ไข
โหมดตัวแทนสามารถเพิ่มหรืออัปเดตองค์ประกอบ UI ได้ด้วยตัวเอง เช่น ขอให้
เอเจนต์ "ตั้งค่าดาร์กโหมดเป็นค่าเริ่มต้นในการตั้งค่าของผู้ใช้" แล้วเอเจนต์จะค้นหา
ไฟล์ที่เกี่ยวข้องและแนะนำการเปลี่ยนแปลงเพื่อให้งานสำเร็จ คุณดูตัวอย่างการอัปเดต UI ได้ทันทีในหน้าต่างเครื่องมืออุปกรณ์ที่ทำงานอยู่
การมีข้อมูลจำลองจะเป็นประโยชน์เมื่อสร้างต้นแบบและทดสอบแอป คุณสามารถมอบหมายงานนี้ให้กับเอเจนต์แทนที่จะสร้างข้อมูลปลอมด้วยตนเอง
ในที่นี้ เราได้ขอให้เอเจนต์ "เพิ่มเซสชันอีก 2 รายการลงในข้อมูลปลอม" โดยจะค้นหาไฟล์ที่เกี่ยวข้องและเพิ่มเหตุการณ์อีก 2 รายการลงในรายการ mockSessions
พรอมต์อื่นๆ ที่ควรลองใช้
- "เขียนการทดสอบหน่วยสำหรับ <class> ใน <module>"
- "สร้างเอกสารสำหรับไฟล์ที่เปิดอยู่"
- "เปลี่ยนชื่อแอปจาก <ชื่อปัจจุบัน> เป็น <ชื่อใหม่>"
- "แก้ไขข้อยกเว้นตัวชี้ Null"
- "ปรับโครงสร้างโค้ดโดยย้าย Composable <ชื่อ Composable> ไปยังไฟล์ใหม่
ตรวจสอบว่าได้อัปเดตการนำเข้าทั้งหมดแล้ว"
- "เพิ่มปุ่มใหม่ลงในหน้าจอหลักของแอปชื่อ "ติดตาม" ซึ่งจะนำคุณไปยัง
รายการหัวข้อ"
- "ใน Composable <ชื่อ Composable> ให้ลดระยะขอบของตัวแก้ไข <ชื่อตัวแก้ไข
modifier>"
- "สร้างปุ่มแชร์เพื่อแชร์ไปยังโซเชียลมีเดีย"
วิธีการทำงานของเอเจนต์
ในโหมดตัวแทน ระบบจะส่งพรอมต์ของคุณไปยัง Gemini API พร้อมกับรายการเครื่องมือที่พร้อมใช้งาน
คุณสามารถคิดว่าเครื่องมือเป็นทักษะได้ โดยเครื่องมือจะรวมถึงความสามารถในการ
ค้นหาไฟล์ อ่านไฟล์ ค้นหาข้อความภายในไฟล์ ใช้เซิร์ฟเวอร์ MCP ที่คุณกำหนดค่าไว้ และอื่นๆ
เมื่อคุณมอบหมายงานให้ Agent แล้ว Agent จะวางแผนและพิจารณาว่าต้องใช้เครื่องมือใด เครื่องมือบางอย่างอาจกำหนดให้คุณต้องให้สิทธิ์ก่อน
ที่เอเจนต์จะใช้ได้ เมื่อคุณให้สิทธิ์แล้ว เอเจนต์จะใช้เครื่องมือเพื่อ
ดำเนินการที่จำเป็นและส่งผลลัพธ์กลับไปยัง Gemini API Gemini
จะประมวลผลผลลัพธ์ของการดำเนินการและสร้างคำตอบอื่น วงจรการ
ดำเนินการและการประเมินนี้จะดำเนินต่อไปจนกว่างานจะเสร็จสมบูรณ์
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-05 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-05 UTC"],[],[],null,["# Agent Mode\n\nGemini in Android Studio's Agent Mode is designed to handle complex, multi-stage\ndevelopment tasks that go beyond what you can experience by just chatting with\nGemini. You can describe a high-level goal, and the agent will create and\nexecute a plan, invoking the necessary [tools](#how-it-works), making changes\nacross multiple files, and iteratively fixing bugs. This agent-assisted workflow\nempowers you to tackle intricate challenges, accelerating your development\nprocess.\n\nGet started\n-----------\n\nTo get started in Agent Mode in Android Studio, follow these steps:\n\n1. Click **Gemini** in the side bar. Sign in and onboard if you need to.\n2. Select the **Agent** tab.\n3. Describe the task you want the agent to perform.\n4. As the agent goes through the steps to accomplish the task, you'll have the\n option to review and approve any changes.\n\n5. Optional: To automatically approve changes, select **Agent options\n \\\u003e Auto-approve changes**.\n\nUse cases\n---------\n\nHere are some examples of use cases that the agent can help you with:\n\n- Fix build errors. When you ask the agent to fix a build error using a prompt\n like \"Fix build errors in my project,\" it will apply a recommended fix, build\n the project to verify the solution, and iterate until the issue is resolved.\n\n- Agent Mode can add or update UI elements all on its own. For example, ask the\n agent to \"Make dark mode the default in user preferences\" and it'll search for\n the relevant files and suggest changes to accomplish the task. You can\n immediately preview the UI updates in the **Running devices** tool window.\n\n- It's helpful to have mock data when prototyping and testing your app. Instead\n of manually creating fake data yourself, you can give that task to the agent.\n Here we've asked the agent to \"Add two more sessions to the fake data.\" It\n finds the relevant file and adds two more events to the `mockSessions` list.\n\nSome other prompts to try:\n\n- \"Write unit tests for \\\u003cclass\\\u003e in \\\u003cmodule\\\u003e.\"\n- \"Generate documentation for the currently open file.\"\n- \"Change the app title from \\\u003ccurrent name\\\u003e to \\\u003cnew name\\\u003e.\"\n- \"Resolve the null pointer exception.\"\n- \"Refactor my code by moving the \\\u003ccomposable name\\\u003e composable to a new file. Ensure all imports are updated.\"\n- \"Add a new button to the app's home screen called 'Follow' that takes you to a list of topics.\"\n- \"In the \\\u003ccomposable name\\\u003e composable, reduce the padding of the \\\u003cmodifier name\\\u003e modifier.\"\n- \"Create a share button to share to social media.\"\n\nHow the agent works\n-------------------\n\nIn Agent Mode, your prompt is sent to the Gemini API with a list of *tools* that\nare available. You can think of tools as skills: they include the ability to\nsearch for files, read files, search the text within files, use any\n[MCP servers](/studio/gemini/add-mcp-server) you have configured, and more.\n\nWhen you give the agent a task, it comes up with a plan and figures out which\ntools are needed. Some of these tools might need you to grant permission before\nthe agent can use them. Once you grant permission, the agent uses the tool to\nperform the necessary action and sends the result back to the Gemini API. Gemini\nprocesses the result of the action and generates another response. This cycle of\naction and evaluation continues until the task is complete."]]