ผสานรวมเอเจนต์ Gemini Enterprise กับ Google Workspace

1. ก่อนเริ่มต้น

83e1c1629d14fb31.png

Gemini Enterprise คืออะไร

Gemini Enterprise เป็นแพลตฟอร์มเอเจนต์ขั้นสูงที่นำสิ่งที่ดีที่สุดจาก AI ของ Google มาให้พนักงานทุกคนได้ใช้ในทุกเวิร์กโฟลว์ ซึ่งช่วยให้ทีมค้นพบ สร้าง แชร์ และเรียกใช้เอเจนต์ AI ได้ในสภาพแวดล้อมที่ปลอดภัยเพียงที่เดียว

  • เข้าถึงโมเดลขั้นสูง: ผู้ใช้จะได้รับสิทธิ์เข้าถึง AI แบบมัลติโมดัลที่ทรงพลังที่สุดของ Google ซึ่งรวมถึง Gemini ได้ทันทีเพื่อรับมือกับความท้าทายทางธุรกิจที่ซับซ้อน
  • ใช้ประโยชน์จากเอเจนต์เฉพาะทาง: ชุดเครื่องมือนี้มีเอเจนต์ของ Google ที่พร้อมใช้งานสำหรับการวิจัย การเขียนโค้ด และการจดบันทึกเพื่อมอบมูลค่าในทันที
  • เพิ่มประสิทธิภาพให้กับพนักงานทุกคน: ตัวเลือกแบบไม่ต้องเขียนโค้ดและแบบเขียนโค้ดช่วยให้เจ้าหน้าที่ในทุกแผนกสามารถสร้างและจัดการเอเจนต์ที่กำหนดเองเพื่อการทำงานอัตโนมัติของเวิร์กโฟลว์ได้
  • อิงตามข้อมูล: เชื่อมต่อ Agent กับข้อมูลภายในบริษัทและแอปพลิเคชันของบุคคลที่สามได้อย่างปลอดภัยเพื่อให้มั่นใจว่าคำตอบของ Agent จะถูกต้องตามบริบท
  • การกำกับดูแลแบบรวมศูนย์: ผู้ดูแลระบบสามารถแสดงภาพและตรวจสอบกิจกรรมของเอเจนต์ทั้งหมดเพื่อให้แน่ใจว่าองค์กรเป็นไปตามมาตรฐานด้านความปลอดภัยและการปฏิบัติตามข้อกำหนดที่เข้มงวด
  • ขยายด้วยระบบนิเวศ: แพลตฟอร์มนี้ผสานรวมกับเครือข่ายแอปพลิเคชันพาร์ทเนอร์และผู้ให้บริการที่หลากหลายเพื่อขยายการทำงานอัตโนมัติในระบบต่างๆ

127f2ed7d484722c.png

Google Workspace คืออะไร

Google Workspace คือชุดโซลูชันด้านประสิทธิภาพการทำงานและการทำงานร่วมกันบนระบบคลาวด์ที่ออกแบบมาสำหรับบุคคล โรงเรียน และธุรกิจ

  • การสื่อสาร: บริการอีเมลแบบมืออาชีพ (Gmail), การประชุมทางวิดีโอ (Meet) และการรับส่งข้อความของทีม (Chat)
  • การสร้างเนื้อหา: เครื่องมือสำหรับเขียนเอกสาร (เอกสาร), สร้างสเปรดชีต (ชีต) และออกแบบงานนำเสนอ (สไลด์)
  • การจัดระเบียบ: ปฏิทินที่ใช้ร่วมกัน (ปฏิทิน) และการจดบันทึกดิจิทัล (Keep)
  • พื้นที่เก็บข้อมูล: พื้นที่เก็บข้อมูลระบบคลาวด์ส่วนกลางสำหรับบันทึกและแชร์ไฟล์อย่างปลอดภัย (ไดรฟ์)
  • การจัดการ: การควบคุมดูแลระบบเพื่อจัดการผู้ใช้และการตั้งค่าความปลอดภัย (คอนโซลผู้ดูแลระบบ Workspace)

การผสานรวมที่กำหนดเองประเภทใด

Google Workspace และ Gemini Enterprise สร้างวงจรความคิดเห็นที่มีประสิทธิภาพ ซึ่ง Workspace จะให้ข้อมูลแบบเรียลไทม์และบริบทการทำงานร่วมกัน ขณะที่ Gemini Enterprise จะมีโมเดล การให้เหตุผลแบบเอเจนต์ และการประสานงานที่จำเป็นต่อการทำให้เวิร์กโฟลว์อัจฉริยะเป็นไปโดยอัตโนมัติ

  • การเชื่อมต่ออัจฉริยะ: ที่เก็บข้อมูล, API และเซิร์ฟเวอร์ MCP (ที่ Google จัดการและที่กำหนดเอง) ที่ Google จัดการช่วยให้ตัวแทนเข้าถึงข้อมูล Workspace ได้อย่างปลอดภัยและราบรื่น รวมถึงดำเนินการในนามของผู้ใช้
  • เอเจนต์ที่กำหนดเอง: ทีมสามารถสร้างเอเจนต์เฉพาะทางที่อิงตามข้อมูลและการดำเนินการใน Workspace ที่ผู้ดูแลระบบควบคุมได้โดยใช้ดีไซเนอร์แบบไม่ต้องเขียนโค้ดหรือเฟรมเวิร์กแบบเขียนโค้ด
  • การผสานรวมดั้งเดิม: ส่วนเสริม Workspace ช่วยเชื่อมช่องว่างระหว่างระบบ AI กับแอปพลิเคชันต่างๆ เช่น Chat และ Gmail ไม่ว่าจะผ่านคอมโพเนนต์ UI เฉพาะหรือกระบวนการเบื้องหลัง ซึ่งช่วยให้ตัวแทนสามารถพบปะผู้ใช้ได้ทุกที่ทุกเวลาเพื่อรับความช่วยเหลือที่รวดเร็วและรับรู้บริบท

การผสานรวมระบบนิเวศด้านประสิทธิภาพการทำงานที่แข็งแกร่งของ Google Workspace เข้ากับความสามารถของเอเจนต์ขั้นสูงของ Gemini Enterprise จะช่วยให้องค์กรเปลี่ยนแปลงการดำเนินงานผ่านเอเจนต์ AI ที่กำหนดเองและอิงตามข้อมูล ซึ่งจะทำให้เวิร์กโฟลว์ที่ซับซ้อนเป็นแบบอัตโนมัติได้โดยตรงภายในเครื่องมือที่ทีมใช้งานอยู่แล้วทุกวัน

ข้อกำหนดเบื้องต้น

หากต้องการทำตามขั้นตอนทั้งหมดในสภาพแวดล้อมของคุณเอง คุณจะต้องมีสิ่งต่อไปนี้

สิ่งที่คุณจะสร้าง

ใน Codelab นี้ เราจะสร้างโซลูชัน 3 รายการด้วย AI Agent ของ Gemini Enterprise ที่ผสานรวมกับ Google Workspace อย่างใกล้ชิด โดยจะแสดงรูปแบบสถาปัตยกรรมที่ใช้โต้ตอบกับข้อมูล การดำเนินการ และ UI ได้

Agent ที่กำหนดเองแบบไม่ต้องเขียนโค้ด

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลและดำเนินการสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้ โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูลและการดำเนินการ: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search
  • เครื่องมือสร้าง Agent: Gemini Enterprise Agent Designer
  • โฮสต์เอเจนต์: Gemini Enterprise
  • UI: เว็บแอป Gemini Enterprise

90e42539e5959634.png

60e62437ce29a818.png

เอเจนต์ที่กำหนดเองแบบ Pro-code

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลและดำเนินการสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้โดยใช้เครื่องมือและกฎที่กำหนดเอง โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูลและการดำเนินการ: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search, เซิร์ฟเวอร์ Vertex AI Search Model Context Protocol (MCP) ที่ Google จัดการ, ฟังก์ชันเครื่องมือที่กำหนดเองเพื่อส่งข้อความ Google Chat (ผ่าน Google Chat API)
  • เครื่องมือสร้าง Agent: Agent Development Kit (ADK)
  • โฮสต์ของ Agent: Vertex AI Agent Engine
  • UI: เว็บแอป Gemini Enterprise

1647ebff031c42e7.png

a8087d2351e77fb4.png

เอเจนต์เริ่มต้นเป็นส่วนเสริมของ Google Workspace

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้ภายในบริบทของ UI ของแอป Workspace โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูล: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search
  • โฮสต์เอเจนต์: Gemini Enterprise
  • UI: ส่วนเสริม Google Workspace สำหรับ Chat และ Gmail (ขยายไปยังปฏิทิน, ไดรฟ์, เอกสาร, ชีต และสไลด์ได้อย่างง่ายดาย)
  • ส่วนเสริม Google Workspace: Apps Script, Gemini Enterprise และ Vertex AI API, บริบท (ข้อมูลเมตาของผู้ใช้, ข้อความ Gmail ที่เลือก)

c8c63fb3f324fecf.png

d33b8cb50ee251b7.png

สิ่งที่คุณจะได้เรียนรู้

  • จุดผสานรวมระหว่าง Gemini Enterprise กับ Google Workspace ที่เปิดใช้ข้อมูลและการดำเนินการ
  • ตัวเลือกแบบไม่ต้องเขียนโค้ดและแบบเขียนโค้ดเพื่อสร้าง Agent ที่กำหนดเองซึ่งโฮสต์ใน Gemini Enterprise
  • วิธีที่ผู้ใช้เข้าถึงเอเจนต์จากเว็บแอป Gemini Enterprise และแอปพลิเคชัน Google Workspace ได้

2. ตั้งค่า

แนวคิดการตรวจสอบ

แอป Gemini Enterprise

แอป Gemini Enterprise จะแสดงผลการค้นหา การดำเนินการ และเอเจนต์แก่ผู้ใช้ปลายทาง คำว่าแอปอาจใช้แทนคำว่าเครื่องมือในบริบทของ API ได้ แอปต้องเชื่อมต่อกับที่เก็บข้อมูลจึงจะใช้ข้อมูลจากที่เก็บข้อมูลเพื่อแสดงผลการค้นหา คำตอบ หรือการดำเนินการได้

เว็บแอป Gemini Enterprise

เว็บแอป Gemini Enterprise เชื่อมโยงกับแอป Gemini Enterprise โดยทำหน้าที่เป็นศูนย์กลาง AI ที่พนักงานใช้แชทอินเทอร์เฟซเดียวเพื่อค้นหาข้อมูลบริษัทที่แยกกัน ทำงานกับเอเจนต์ AI เฉพาะทางสำหรับเวิร์กโฟลว์ที่ซับซ้อน และสร้างเนื้อหาระดับมืออาชีพที่มีความเป็นส่วนตัวระดับองค์กร

เริ่มต้นและเข้าถึงทรัพยากร

ในส่วนนี้ คุณจะเข้าถึงและกำหนดค่าทรัพยากรต่อไปนี้จากเว็บเบราว์เซอร์ที่ต้องการ

แอป Gemini Enterprise

เปิด Google Cloud Console ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. เลือกโปรเจ็กต์
  2. ในช่องค้นหาของ Google Cloud ให้ค้นหาและเลือก Gemini Enterprise แล้วคลิก + สร้างแอป หากไม่มีใบอนุญาตสำหรับ Gemini Enterprise ระบบจะแจ้งให้คุณเปิดใช้งานใบอนุญาตทดลองใช้ฟรี 30 วัน

  1. ตั้งค่าชื่อแอปเป็น codelab
  2. ระบบจะสร้างรหัสตามชื่อและแสดงไว้ใต้ช่อง ให้คัดลอกรหัส
  3. ตั้งค่าหลายภูมิภาคเป็น global (Global)
  4. คลิกสร้าง

8712ada39377205e.png

  1. ระบบจะสร้างแอปและเปลี่ยนเส้นทางคุณไปยัง Gemini Enterprise > ภาพรวม โดยอัตโนมัติ
  2. ในส่วนรับสิทธิ์เข้าถึงแบบเต็ม ให้คลิกตั้งค่าข้อมูลประจำตัว
  3. ในหน้าจอใหม่ ให้เลือกใช้ข้อมูลประจำตัวของ Google แล้วคลิกยืนยัน Workforce Identity

3209c156eff4ba43.png

  1. ระบบจะบันทึกการกำหนดค่าและเปลี่ยนเส้นทางคุณไปยัง Gemini Enterprise > ภาพรวม โดยอัตโนมัติ
  2. ไปที่การกำหนดค่า
  3. ในแท็บการจัดการฟีเจอร์ ให้เปิดเปิดใช้โปรแกรมออกแบบเอเจนต์ แล้วคลิกบันทึก

f0cd9da419b41cb6.png

เว็บแอป Gemini Enterprise

เปิด Gemini Enterprise จากคอนโซลระบบคลาวด์ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. คลิกแอปชื่อ codelab
  2. คัดลอก URL ที่ปรากฏขึ้นเนื่องจากเราจะใช้ URL นี้เพื่อไปยังเว็บแอป Gemini Enterprise ในขั้นตอนถัดไป

b46ee6176744565d.png

3. Agent ที่กำหนดเองแบบไม่ต้องเขียนโค้ด

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลและดำเนินการสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้ โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูลและการดำเนินการ: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search
  • เครื่องมือสร้าง Agent: Gemini Enterprise Agent Designer
  • โฮสต์เอเจนต์: Gemini Enterprise
  • UI: เว็บแอป Gemini Enterprise

แนวคิดการตรวจสอบ

Gemini

Gemini คือ LLM แบบมัลติโมดัลจาก Google โดยช่วยให้ผู้คนปลดล็อกศักยภาพของตนเองเพื่อเสริมสร้างจินตนาการ ขยายความอยากรู้อยากเห็น และเพิ่มประสิทธิภาพการทำงาน

ที่เก็บข้อมูล Gemini Enterprise

ที่เก็บข้อมูล Gemini Enterprise คือเอนทิตีที่มีข้อมูลที่นำเข้าจากแหล่งข้อมูลจากบุคคลที่หนึ่ง เช่น Google Workspace หรือแอปพลิเคชันของบุคคลที่สาม เช่น Jira หรือ Salesforce ที่เก็บข้อมูลที่มีข้อมูลจากแอปพลิเคชันของบุคคลที่สามเรียกว่าเครื่องมือเชื่อมต่อข้อมูลด้วย

เครื่องมือออกแบบเอเจนต์ Gemini Enterprise

เครื่องมือออกแบบ Agent ของ Gemini Enterprise เป็นแพลตฟอร์มแบบอินเทอร์แอกทีฟที่ไม่ต้องเขียนโค้ดหรือใช้โค้ดเล็กน้อยสำหรับการสร้าง จัดการ และเปิดตัว Agent แบบขั้นตอนเดียวและหลายขั้นตอนใน Gemini Enterprise

ตรวจสอบสถาปัตยกรรมโซลูชัน

e77aafb772502aaf.png

เปิดใช้ API

พื้นที่เก็บข้อมูล Workspace ของ Gemini Enterprise ต้องเปิดใช้ API ดังนี้

  1. ในคอนโซล Google Cloud ให้เปิดใช้ Calendar, Gmail และ People API โดยทำดังนี้

573322606b715a69.png

  1. คลิกเมนู ☰ > API และบริการ > API และบริการที่เปิดใช้ แล้วตรวจสอบว่า Google Calendar API, Gmail API และ People API อยู่ในรายการ

การดำเนินการในปฏิทินและ Gmail ของ Gemini Enterprise Workspace ต้องมีการกำหนดค่าหน้าจอขอความยินยอม

  1. ในคอนโซล Google Cloud ให้คลิก เมนู ☰ > แพลตฟอร์มการตรวจสอบสิทธิ์ของ Google > การสร้างแบรนด์

  1. คลิกเริ่มต้นใช้งาน
  2. ในส่วนข้อมูลแอป ให้ตั้งชื่อแอปเป็น Codelab
  3. ในอีเมลสนับสนุนสำหรับผู้ใช้ ให้เลือกอีเมลสนับสนุนที่ผู้ใช้สามารถติดต่อคุณได้หากมีข้อสงสัยเกี่ยวกับการยินยอม
  4. คลิกถัดไป
  5. ในส่วนผู้ชม ให้เลือกภายใน
  6. คลิกถัดไป
  7. ในส่วนข้อมูลติดต่อ ให้ป้อนอีเมลที่คุณต้องการรับการแจ้งเตือนเกี่ยวกับการเปลี่ยนแปลงในโปรเจ็กต์
  8. คลิกถัดไป
  9. ในส่วนเสร็จสิ้น ให้อ่านนโยบายข้อมูลผู้ใช้ของบริการ Google API และหากยอมรับ ให้เลือกฉันยอมรับบริการ Google API: นโยบายข้อมูลผู้ใช้
  10. คลิกต่อไป แล้วคลิกสร้าง

578c2b38219b2f7b.png

  1. ระบบจะบันทึกการกำหนดค่าและเปลี่ยนเส้นทางคุณไปยัง Google Auth Platform > ภาพรวม โดยอัตโนมัติ
  2. ไปที่การเข้าถึงข้อมูล
  3. คลิกเพิ่มหรือนำขอบเขตออก
  4. คัดลอกขอบเขตต่อไปนี้และวางลงในช่องเพิ่มขอบเขตด้วยตนเอง
https://www.googleapis.com/auth/calendar.readonly
https://www.googleapis.com/auth/calendar.events
https://www.googleapis.com/auth/calendar.calendars
https://www.googleapis.com/auth/gmail.send
https://www.googleapis.com/auth/gmail.readonly
  1. คลิกเพิ่มลงในตาราง แล้วคลิกอัปเดต จากนั้นคลิกบันทึก

874b1dda14e8f379.png

ดูข้อมูลเพิ่มเติมได้ที่คู่มือกำหนดค่าความยินยอม OAuth ฉบับเต็ม

สร้างข้อมูลเข้าสู่ระบบไคลเอ็นต์ OAuth

สร้างไคลเอ็นต์ OAuth ใหม่สำหรับ Gemini Enterprise เพื่อตรวจสอบสิทธิ์ผู้ใช้

  1. ในคอนโซล Google Cloud ให้คลิก เพื่อไปที่เมนู ☰ > แพลตฟอร์มการตรวจสอบสิทธิ์ของ Google > ไคลเอ็นต์

  1. คลิก + สร้างไคลเอ็นต์
  2. ในส่วนประเภทแอปพลิเคชัน ให้เลือกเว็บแอปพลิเคชัน
  3. ตั้งค่าชื่อเป็น codelab
  4. ข้ามต้นทางของ JavaScript ที่ได้รับอนุญาต
  5. ในส่วน URI การเปลี่ยนเส้นทางที่ได้รับอนุญาต ให้คลิกเพิ่ม URI แล้วป้อน https://vertexaisearch.cloud.google.com/oauth-redirect
  6. คลิกสร้าง
  7. กล่องโต้ตอบจะปรากฏขึ้นพร้อมรหัสไคลเอ็นต์และรหัสลับ OAuth ที่สร้างขึ้นใหม่ โปรดบันทึกข้อมูลนี้ไว้ในที่ปลอดภัย

a46e5ebfb851aea5.png

สร้างพื้นที่เก็บข้อมูล

เปิด Gemini Enterprise จากคอนโซลระบบคลาวด์ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. คลิกแอปชื่อ codelab
  2. ในเมนูการนำทาง ให้คลิกที่เก็บข้อมูลที่เชื่อมต่อ
  3. คลิก + ที่เก็บข้อมูลใหม่
  4. ในแหล่งที่มา ให้ค้นหา Google ปฏิทิน แล้วคลิกเลือก
  5. ในส่วนการดำเนินการ ให้ป้อนรหัสไคลเอ็นต์และรหัสลับไคลเอ็นต์ที่บันทึกจากขั้นตอนก่อนหน้า จากนั้นคลิกยืนยันการให้สิทธิ์ แล้วทำตามขั้นตอนเพื่อตรวจสอบสิทธิ์และให้สิทธิ์ไคลเอ็นต์ OAuth
  6. เปิดใช้การดำเนินการสร้างกิจกรรมในปฏิทินและอัปเดตกิจกรรมในปฏิทิน
  7. คลิกต่อไป

a1d76e70edec0cf.png

  1. ในส่วนการกำหนดค่า ให้ตั้งชื่อเครื่องมือเชื่อมต่อข้อมูลเป็น calendar
  2. คลิกสร้าง
  3. ระบบจะเปลี่ยนเส้นทางคุณไปยังที่เก็บข้อมูลที่เชื่อมต่อโดยอัตโนมัติ ซึ่งคุณจะเห็นที่เก็บข้อมูลที่เพิ่มใหม่

สร้างพื้นที่เก็บข้อมูล Google Gmail โดยทำดังนี้

  1. คลิก + ที่เก็บข้อมูลใหม่
  2. ในแหล่งที่มา ให้ค้นหา Google Gmail แล้วคลิกเลือก
  3. ในส่วนการดำเนินการ ให้ป้อนรหัสไคลเอ็นต์และรหัสลับไคลเอ็นต์ที่บันทึกไว้จากขั้นตอนก่อนหน้า แล้วคลิกยืนยันการให้สิทธิ์
  4. เปิดใช้การดำเนินการส่งอีเมล
  5. คลิกต่อไป
  6. ในส่วนการกำหนดค่า ให้ตั้งชื่อเครื่องมือเชื่อมต่อข้อมูลเป็น gmail
  7. คลิกสร้าง
  8. ระบบจะเปลี่ยนเส้นทางคุณไปยังที่เก็บข้อมูลที่เชื่อมต่อโดยอัตโนมัติ ซึ่งคุณจะเห็นที่เก็บข้อมูลที่เพิ่มใหม่

สร้างที่เก็บข้อมูล Google ไดรฟ์

  1. คลิก + ที่เก็บข้อมูลใหม่
  2. ในแหล่งที่มา ให้ค้นหา Google ไดรฟ์ แล้วคลิกเลือก
  3. ในส่วนข้อมูล ให้เลือกทั้งหมด แล้วคลิกต่อไป
  4. ในส่วนการกำหนดค่า ให้ตั้งชื่อเครื่องมือเชื่อมต่อข้อมูลเป็น drive
  5. คลิกสร้าง
  6. ระบบจะเปลี่ยนเส้นทางคุณไปยังที่เก็บข้อมูลที่เชื่อมต่อโดยอัตโนมัติ ซึ่งคุณจะเห็นที่เก็บข้อมูลที่เพิ่มใหม่

สร้างพื้นที่เก็บข้อมูล NotebookLM โดยทำดังนี้

  1. คลิก + ที่เก็บข้อมูลใหม่
  2. ในแหล่งข้อมูล ให้ค้นหา NotebookLM แล้วคลิกเลือก
  3. ในส่วนการกำหนดค่า ให้ตั้งชื่อเครื่องมือเชื่อมต่อข้อมูลเป็น notebooklm
  4. คลิกสร้าง
  5. ระบบจะเปลี่ยนเส้นทางคุณไปยังที่เก็บข้อมูลที่เชื่อมต่อโดยอัตโนมัติ ซึ่งคุณจะเห็นที่เก็บข้อมูลที่เพิ่มใหม่

หลังจากผ่านไป 2-3 นาที สถานะของที่เก็บข้อมูลที่เชื่อมต่อทั้งหมด (ยกเว้น NotebookLM) จะเป็นใช้งานอยู่ หากเห็นข้อผิดพลาด ให้คลิกแหล่งข้อมูลเพื่อดูรายละเอียดข้อผิดพลาด

ceba9eb2480a2696.png

พื้นที่เก็บข้อมูลทดสอบ

เปิด URL ของเว็บแอป Gemini Enterprise ที่เราคัดลอกไว้ก่อนหน้านี้

  1. คลิกเมนู ☰ > แชทใหม่
  2. ที่ส่วนท้ายของช่องข้อความแชทใหม่ ให้คลิกไอคอนตัวเชื่อมต่อ แล้วเปิดใช้ตัวเชื่อมต่อทั้งหมด
  3. ตอนนี้คุณทดลองใช้พรอมต์ที่เกี่ยวข้องกับตัวเชื่อมต่อได้แล้ว เช่น ในแชท ให้พิมพ์ Do I have any meetings today? แล้วกด enter
  4. จากนั้นลองพิมพ์ How many emails did I receive today? แล้วกด enter
  5. สุดท้าย ให้พิมพ์ Give me the title of the last Drive file I created แล้วกด enter

90e42539e5959634.png

สร้างเอเจนต์ที่กำหนดเอง

ในเว็บแอป Gemini Enterprise ให้สร้าง Agent ใหม่โดยใช้ Agent Designer ดังนี้

  1. คลิกเมนู ☰ > + ตัวแทนใหม่
  2. ในแชท ให้พิมพ์ An agent that always sends pirate-themed emails but use normal English otherwise แล้วกด enter

2803c1dedd20433e.png

  1. Agent Designer จะร่าง Agent ตามพรอมต์และเปิดในเครื่องมือแก้ไข
  2. คลิกสร้าง

ลองใช้เอเจนต์ที่กำหนดเอง

  1. ในเว็บแอป Gemini Enterprise ให้แชทกับเอเจนต์ที่สร้างขึ้นใหม่โดยทำดังนี้
  2. คลิกเมนู ☰ > ตัวแทน
  3. เลือกเอเจนต์ในส่วนเอเจนต์ของคุณ
  4. ที่ส่วนท้ายของช่องข้อความแชทใหม่ ให้คลิกไอคอนตัวเชื่อมต่อ แล้วคลิกเปิดใช้การดำเนินการสำหรับอีเมล แล้วทำตามวิธีการให้สิทธิ์ตัวแทน
  5. ในแชท ให้พิมพ์ Send an email to someone@example.com saying I'll see them at Cloud Next, generate some subject and body yourself แล้วกด enter คุณสามารถแทนที่อีเมลตัวอย่างด้วยอีเมลของคุณได้
  6. คลิก ✔️ เพื่อส่งอีเมล

60e62437ce29a818.png

d4fb65d14fdf27da.png

4. Agent ที่กำหนดเองแบบเขียนโค้ด

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลและดำเนินการสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้โดยใช้เครื่องมือและกฎที่กำหนดเอง โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูลและการดำเนินการ: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search, เซิร์ฟเวอร์ Vertex AI Search Model Context Protocol (MCP) ที่ Google จัดการ, ฟังก์ชันเครื่องมือที่กำหนดเองเพื่อส่งข้อความ Google Chat (ผ่าน Google Chat API)
  • เครื่องมือสร้าง Agent: Agent Development Kit (ADK)
  • โฮสต์ของ Agent: Vertex AI Agent Engine
  • UI: เว็บแอป Gemini Enterprise

โดยจะผสานรวมใน Gemini Enterprise โดยใช้ฟีเจอร์ Bring-Your-Own ดังนั้นเราจึงต้องทำตามขั้นตอนการติดตั้งใช้งาน การลงทะเบียน และการกำหนดค่า

แนวคิดการตรวจสอบ

Vertex AI

Vertex AI มีทุกอย่างที่คุณต้องการในการสร้างและใช้ Generative AI ซึ่งรวมถึงโซลูชัน AI, การค้นหาและการสนทนา, โมเดลพื้นฐานกว่า 130 รายการ และแพลตฟอร์ม AI แบบครบวงจร

4670fcf7a826af4d.png

ชุดพัฒนาเอเจนต์ (ADK)

ชุดพัฒนา Agent (ADK) เป็นชุดเครื่องมือและเฟรมเวิร์กเฉพาะที่ออกแบบมาเพื่อลดความซับซ้อนในการสร้างเอเจนต์ AI แบบอัตโนมัติ โดยมีโมดูลที่สร้างไว้ล่วงหน้าสำหรับการให้เหตุผล การจัดการหน่วยความจำ และการผสานรวมเครื่องมือ

Model Context Protocol (MCP)

Model Context Protocol (MCP) เป็นมาตรฐานแบบเปิดที่ออกแบบมาเพื่อเปิดใช้การผสานรวมที่ราบรื่นและปลอดภัยระหว่างแอปพลิเคชัน AI กับแหล่งข้อมูลหรือเครื่องมือต่างๆ ผ่านอินเทอร์เฟซแบบ "พลักแอนด์เพลย์" ที่ใช้ได้ทั่วไป

เครื่องมือฟังก์ชัน

เครื่องมือฟังก์ชันคือกิจวัตรที่กำหนดไว้ล่วงหน้าซึ่งโมเดล AI สามารถเรียกใช้เพื่อดำเนินการที่เฉพาะเจาะจงหรือดึงข้อมูลแบบเรียลไทม์จากระบบภายนอก ซึ่งจะขยายความสามารถของโมเดลให้มากกว่าการสร้างข้อความอย่างง่าย

ตรวจสอบสถาปัตยกรรมโซลูชัน

43df337e0f3d64e8.png

ตรวจสอบซอร์สโค้ด

agent.py

...
MODEL = "gemini-2.5-flash"

# Gemini Enterprise authentication injects a bearer token into the ToolContext state.
# The key pattern is "GE_AUTH_NAME_<random_digits>".
# We dynamically parse this token to authenticate our MCP and API calls.
GE_AUTH_NAME = "enterprise-ai"

VERTEXAI_SEARCH_TIMEOUT = 15.0

def get_project_id():
    """Fetches the consumer project ID from the environment natively."""
    _, project = google.auth.default()
    if project:
        return project
    raise Exception(f"Failed to resolve GCP Project ID from environment.")

def find_serving_config_path():
    """Dynamically finds the default serving config in the engine."""
    project_id = get_project_id()
    engines = discoveryengine_v1.EngineServiceClient().list_engines(
        parent=f"projects/{project_id}/locations/global/collections/default_collection"
    )
    for engine in engines:
        # engine.name natively contains the numeric Project Number
        return f"{engine.name}/servingConfigs/default_serving_config"
    raise Exception(f"No Discovery Engines found in project {project_id}")

def _get_access_token_from_context(tool_context: ToolContext) -> str:
    """Helper method to dynamically parse the intercepted bearer token from the context state."""
    escaped_name = re.escape(GE_AUTH_NAME)
    pattern = re.compile(fr"^{escaped_name}_\d+$")
    # Handle ADK varying state object types (Raw Dict vs ADK State)
    state_dict = tool_context.state.to_dict() if hasattr(tool_context.state, 'to_dict') else tool_context.state
    matching_keys = [k for k in state_dict.keys() if pattern.match(k)]
    if matching_keys:
        return state_dict.get(matching_keys[0])
    raise Exception(f"No bearer token found in ToolContext state matching pattern {pattern.pattern}")

def auth_header_provider(tool_context: ToolContext) -> dict[str, str]:
    token = _get_access_token_from_context(tool_context)
    return {"Authorization": f"Bearer {token}"}

def send_direct_message(email: str, message: str, tool_context: ToolContext) -> dict:
    """Sends a Google Chat Direct Message (DM) to a specific user by email address."""
    chat_client = chat_v1.ChatServiceClient(
        credentials=Credentials(token=_get_access_token_from_context(tool_context))
    )

    # 1. Setup the DM space or find existing one
    person = chat_v1.User(
        name=f"users/{email}",
        type_=chat_v1.User.Type.HUMAN
    )
    membership = chat_v1.Membership(member=person)
    space_req = chat_v1.Space(space_type=chat_v1.Space.SpaceType.DIRECT_MESSAGE)
    setup_request = chat_v1.SetUpSpaceRequest(
        space=space_req,
        memberships=[membership]
    )
    space_response = chat_client.set_up_space(request=setup_request)
    space_name = space_response.name
    
    # 2. Send the message
    msg = chat_v1.Message(text=message)
    message_request = chat_v1.CreateMessageRequest(
        parent=space_name,
        message=msg
    )
    message_response = chat_client.create_message(request=message_request)
    
    return {"status": "success", "message_id": message_response.name, "space": space_name}

vertexai_mcp = McpToolset(
    connection_params=StreamableHTTPConnectionParams(
        url="https://discoveryengine.googleapis.com/mcp",
        timeout=VERTEXAI_SEARCH_TIMEOUT,
        sse_read_timeout=VERTEXAI_SEARCH_TIMEOUT
    ),
    tool_filter=['search'],
    # The auth_header_provider dynamically injects the bearer token from the ToolContext
    # into the MCP call for authentication.
    header_provider=auth_header_provider
)

# Answer nicely the following user queries:
#  - Please find my meetings for today, I need their titles and links
#  - What is the latest Drive file I created?
#  - What is the latest Gmail message I received?
#  - Please send the following message to someone@example.com: Hello, this is a test message.

root_agent = LlmAgent(
    model=MODEL,
    name='enterprise_ai',
    instruction=f"""
        You are a helpful assistant that always uses the Vertex AI MCP search tool to answer the user's message, unless the user asks you to send a message to someone.
        If the user asks you to send a message to someone, use the send_direct_message tool to send the message.
        You MUST unconditionally use the Vertex AI MCP search tool to find answer, even if you believe you already know the answer or believe the Vertex AI MCP search tool does not contain the data.
        The Vertex AI MCP search tool accesses the user's data through datastores including Google Drive, Google Calendar, and Gmail.
        Only use the Vertex AI MCP search tool with servingConfig and query parameters, do not use any other parameters.
        Always use the servingConfig {find_serving_config_path()} while using the Vertex AI MCP search tool.
    """,
    tools=[vertexai_mcp, FunctionTool(send_direct_message)]
)

เปิดใช้ API

โซลูชันนี้ต้องเปิดใช้ API เพิ่มเติมดังนี้

  1. ในคอนโซล Google Cloud ให้เปิดใช้ Vertex AI, Cloud Resource Manager และ Google Chat API โดยทำดังนี้

4f02a36b050bab00.png

  1. คลิกเมนู ☰ > API และบริการ > API และบริการที่เปิดใช้ แล้วตรวจสอบว่า Vertex AI API, Cloud Resource Manager API และ Google Chat API อยู่ในรายการ

โซลูชันนี้ต้องมีสิทธิ์เข้าถึงข้อมูลเพิ่มเติม

  1. ในคอนโซล Google Cloud ให้คลิก เพื่อไปที่เมนู ☰ > แพลตฟอร์มการตรวจสอบสิทธิ์ของ Google > การเข้าถึงข้อมูล

  1. คลิกเพิ่มหรือนำขอบเขตออก
  2. คัดลอกขอบเขตต่อไปนี้และวางลงในช่องเพิ่มขอบเขตด้วยตนเอง
  3. คลิกเพิ่มลงในตาราง แล้วคลิกอัปเดต จากนั้นคลิกบันทึก
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.spaces.create
  1. คลิกเพิ่มลงในตาราง แล้วคลิกอัปเดต จากนั้นคลิกบันทึก

56fbba733139acfe.png

อัปเดตข้อมูลเข้าสู่ระบบไคลเอ็นต์ OAuth

โซลูชันนี้ต้องมี URI การเปลี่ยนเส้นทางที่ได้รับอนุญาตเพิ่มเติม

  1. ในคอนโซล Google Cloud ให้คลิก เพื่อไปที่เมนู ☰ > แพลตฟอร์มการตรวจสอบสิทธิ์ของ Google > ไคลเอ็นต์

  1. คลิกชื่อลูกค้า codelab
  2. ในส่วน URI การเปลี่ยนเส้นทางที่ได้รับอนุญาต ให้คลิก Add URI แล้วป้อน https://vertexaisearch.cloud.google.com/static/oauth/oauth.html
  3. คลิกบันทึก

deed597aa54fec91.png

เปิดใช้ Vertex AI Search MCP

  1. ในเทอร์มินัล ให้เรียกใช้คำสั่งต่อไปนี้
gcloud beta services mcp enable discoveryengine.googleapis.com \
     --project=$(gcloud config get-value project)

กำหนดค่าแอปใน Chat

  1. ในคอนโซล Google Cloud ให้ค้นหา Google Chat API ในช่องค้นหาของ Google Cloud คลิก Google Chat API คลิกจัดการ แล้วคลิกการกำหนดค่า

  1. ตั้งค่าชื่อแอปและคำอธิบายเป็น Gemini Enterprise
  2. ตั้งค่า URL ของอวตารเป็น https://developers.google.com/workspace/add-ons/images/quickstart-app-avatar.png
  3. ยกเลิกการเลือกเปิดใช้ฟีเจอร์แบบอินเทอร์แอกทีฟ แล้วคลิกปิดใช้ในกล่องโต้ตอบแบบโมดัลที่ปรากฏขึ้น
  4. เลือกบันทึกข้อผิดพลาดไปยังการบันทึก
  5. คลิกบันทึก

90cb612e51bce4e6.png

นำ Agent ไปใช้งานใน Vertex AI Agent Engine

  1. ดาวน์โหลดที่เก็บ GitHub นี้

  1. ในเทอร์มินัล ให้เปิดไดเรกทอรี solutions/enterprise-ai-agent แล้วเรียกใช้คำสั่งต่อไปนี้
# 1. Create and activate a new virtual environment
python3 -m venv .venv
source .venv/bin/activate

# 2. Install poetry and project dependencies
pip install poetry
poetry install

# 3. Deploy the agent
adk deploy agent_engine \
  --project=$(gcloud config get-value project) \
  --region=us-central1 \
  --display_name="Enterprise AI" \
  enterprise_ai

eafd2f9c4fbf305.png

  1. เมื่อเห็นบรรทัด Deploying to agent engine... ในบันทึก ให้เปิดเทอร์มินัลใหม่และเรียกใช้คำสั่งต่อไปนี้เพื่อเพิ่มสิทธิ์ที่จำเป็นให้กับ Vertex AI Reasoning Engine Service Agent
# 1. Get the current Project ID
PROJECT_ID=$(gcloud config get-value project)

# 2. Extract the Project Number for that ID
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)')

# 3. Construct the Service Account name
SERVICE_ACCOUNT="service-${PROJECT_NUMBER}@gcp-sa-aiplatform-re.iam.gserviceaccount.com"

# 4. Apply the IAM policy binding
gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member="serviceAccount:$SERVICE_ACCOUNT" \
     --role="roles/discoveryengine.viewer"
  1. รอให้คำสั่ง adk deploy เสร็จสมบูรณ์ จากนั้นคัดลอกชื่อทรัพยากรของเอเจนต์ที่เพิ่งติดตั้งใช้งานจากเอาต์พุตของคำสั่งเป็นสีเขียว

d098fe1347d6581b.png

ลงทะเบียนเอเจนต์ใน Gemini Enterprise

เปิด Gemini Enterprise จากคอนโซลระบบคลาวด์ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. คลิกแอปชื่อ codelab
  2. ในเมนูการนำทาง ให้คลิกเอเจนต์
  3. คลิก + เพิ่มตัวแทน
  4. คลิกเพิ่มสำหรับเอเจนต์ที่กำหนดเองผ่าน Agent Engine ส่วนการให้สิทธิ์จะปรากฏขึ้น
  5. คลิกเพิ่มการให้สิทธิ์
  6. ตั้งค่าชื่อการให้สิทธิ์เป็น enterprise-ai ระบบจะสร้างรหัสตามชื่อและแสดงไว้ใต้ช่อง ให้คัดลอกรหัส
  7. ตั้งค่ารหัสไคลเอ็นต์ให้มีค่าเดียวกับไคลเอ็นต์ OAuth ที่สร้างและอัปเดตในขั้นตอนก่อนหน้า
  8. ตั้งค่ารหัสลับไคลเอ็นต์ให้มีค่าเดียวกับไคลเอ็นต์ OAuth ที่สร้างและอัปเดตในขั้นตอนก่อนหน้า
  9. ตั้งค่า Token URI เป็น https://oauth2.googleapis.com/token
  10. ตั้งค่า Authorization URI เป็นค่าต่อไปนี้หลังจากแทนที่ <CLIENT_ID> ด้วยรหัสไคลเอ็นต์ OAuth ที่สร้างและอัปเดตในขั้นตอนก่อนหน้า
https://accounts.google.com/o/oauth2/v2/auth?client_id=<CLIENT_ID>&redirect_uri=https%3A%2F%2Fvertexaisearch.cloud.google.com%2Fstatic%2Foauth%2Foauth.html&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.calendars%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.events%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.send%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fchat.messages.create%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fchat.spaces.create&include_granted_scopes=true&response_type=code&access_type=offline&prompt=consent
  1. คลิกเสร็จสิ้น แล้วคลิกถัดไป ส่วนการกำหนดค่าจะปรากฏขึ้น
  2. ตั้งค่าชื่อเอเจนต์และคำอธิบายเอเจนต์เป็น Enterprise AI
  3. ตั้งค่าเครื่องมือให้เหตุผลของ Agent Engine เป็นชื่อทรัพยากรเครื่องมือให้เหตุผลที่คัดลอกไว้ในขั้นตอนก่อนหน้า โดยมีรูปแบบดังนี้
projects/<PROJECT_ID>/locations/<LOCATION>/reasoningEngines/<REASONING_ENGINE_ID>
  1. คลิกสร้าง ตอนนี้ตัวแทนที่เพิ่มใหม่จะแสดงอยู่ในส่วนตัวแทน

ลองใช้ Agent

  1. ในเว็บแอป Gemini Enterprise ให้แชทกับเอเจนต์ที่เพิ่งลงทะเบียนโดยทำดังนี้
  2. คลิกเมนู ☰ > ตัวแทน
  3. เลือกตัวแทนในส่วนจากองค์กรของคุณ
  4. ในแชท ให้พิมพ์ Please find my meetings for today, I need their titles and links แล้วกด enter
  5. คลิกให้สิทธิ์ แล้วทำตามขั้นตอนการให้สิทธิ์

ed61cf654cbcd76c.png

  1. เอเจนต์จะตอบกลับด้วยรายการกิจกรรมในปฏิทิน (ขึ้นอยู่กับบัญชีของผู้ใช้)
  2. ในแชท ให้พิมพ์ Please send a Chat message to someone@example.com with the following text: Hello! แล้วกด enter
  3. ตัวแทนจะตอบกลับด้วยข้อความยืนยัน

1647ebff031c42e7.png

a8087d2351e77fb4.png

5. เอเจนต์เริ่มต้นเป็นส่วนเสริมของ Google Workspace

เอเจนต์นี้ช่วยให้ผู้ใช้ค้นหาข้อมูลสำหรับ Workspace ในภาษาที่เป็นธรรมชาติได้ในบริบทของ UI ของแอป Workspace โดยจะอิงตามองค์ประกอบต่อไปนี้

  • โมเดล: Gemini
  • ข้อมูล: ที่เก็บข้อมูล Gemini Enterprise สำหรับ Google Workspace (ปฏิทิน, Gmail, ไดรฟ์, NotebookLM), Google Search
  • โฮสต์เอเจนต์: Gemini Enterprise
  • UI: ส่วนเสริม Google Workspace สำหรับ Chat และ Gmail (ขยายไปยังปฏิทิน, ไดรฟ์, เอกสาร, ชีต และสไลด์ได้อย่างง่ายดาย)
  • ส่วนเสริม Google Workspace: Apps Script, Gemini Enterprise และ Vertex AI API, บริบท (ข้อมูลเมตาของผู้ใช้, ข้อความ Gmail ที่เลือก)

ส่วนเสริม Google Workspace จะเชื่อมต่อกับ Gemini Enterprise โดยใช้ StreamAssist API

ตรวจสอบแนวคิด

ส่วนเสริมของ Google Workspace

ส่วนเสริมของ Google Workspace คือแอปพลิเคชันที่ปรับแต่งแล้วซึ่งขยายแอปพลิเคชัน Google Workspace อย่างน้อย 1 รายการ (Gmail, Chat, ปฏิทิน, เอกสาร, ไดรฟ์, Meet, ชีต และสไลด์)

Apps Script

Apps Script คือแพลตฟอร์ม JavaScript บนระบบคลาวด์ที่ขับเคลื่อนโดย Google ไดรฟ์ ซึ่งช่วยให้คุณผสานรวมและกำหนดงานอัตโนมัติในผลิตภัณฑ์ต่างๆ ของ Google ได้

เฟรมเวิร์กการ์ด Google Workspace

เฟรมเวิร์กการ์ดใน Google Workspace ช่วยให้นักพัฒนาแอปสร้างอินเทอร์เฟซผู้ใช้แบบอินเทอร์แอกทีฟที่สมบูรณ์ได้ ซึ่งช่วยให้สร้างการ์ดที่เป็นระเบียบและดึงดูดสายตาได้ โดยสามารถใส่ข้อความ รูปภาพ ปุ่ม และวิดเจ็ตอื่นๆ การ์ดเหล่านี้ช่วยปรับปรุงประสบการณ์ของผู้ใช้ด้วยการให้ข้อมูลที่มีโครงสร้างและช่วยให้ดำเนินการอย่างรวดเร็วได้โดยตรงภายในแอปพลิเคชัน Workspace

ตรวจสอบสถาปัตยกรรมโซลูชัน

1798c39f7aaed8fc.png

ตรวจสอบซอร์สโค้ด

appsscript.json

...
"addOns": {
    "common": {
      "name": "Enterprise AI",
      "logoUrl": "https://developers.google.com/workspace/add-ons/images/quickstart-app-avatar.png"
    },
    "chat": {},
    "gmail": {
      "contextualTriggers": [
        {
          "unconditional": {},
          "onTriggerFunction": "onAddonEvent"
        }
      ]
    }
  },
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/discoveryengine.assist.readwrite",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly"
  ]
...

Chat.gs

...
// Service that handles Google Chat operations.

// Handle incoming Google Chat message events, actions will be taken via Google Chat API calls
function onMessage(event) {
  if (isInDebugMode()) {
    console.log(`MESSAGE event received (Chat): ${JSON.stringify(event)}`);
  }
  // Extract data from the event.
  const chatEvent = event.chat;
  setChatConfig(chatEvent.messagePayload.space.name);

  // Request AI agent to answer the message
  requestAgent(chatEvent.messagePayload.message);
  // Respond with an empty response to the Google Chat platform to acknowledge execution
  return null; 
}

// --- Utility functions ---

// The Chat direct message (DM) space associated with the user
const SPACE_NAME_PROPERTY = "DM_SPACE_NAME"

// Sets the Chat DM space name for subsequent operations.
function setChatConfig(spaceName) {
  const userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty(SPACE_NAME_PROPERTY, spaceName);
  console.log(`Space is set to ${spaceName}`);
}

// Retrieved the Chat DM space name to sent messages to.
function getConfiguredChat() {
  const userProperties = PropertiesService.getUserProperties();
  return userProperties.getProperty(SPACE_NAME_PROPERTY);
}

// Finds the Chat DM space name between the Chat app and the given user.
function findChatAppDm(userName) {
  return Chat.Spaces.findDirectMessage(
    { 'name': userName },
    {'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}`}
  ).name;
}

// Creates a Chat message in the configured space.
function createMessage(message) {
  const spaceName = getConfiguredChat();
  console.log(`Creating message in space ${spaceName}...`);
  return Chat.Spaces.Messages.create(
    message,
    spaceName,
    {},
    {'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}`}
  ).name;
}

Sidebar.gs

...
// Service that handles Gmail operations.

// Triggered when the user opens the Gmail Add-on or selects an email.
function onAddonEvent(event) {
  // If this was triggered by a button click, handle it
  if (event.parameters && event.parameters.action === 'send') {
    return handleSendMessage(event);
  }

  // Otherwise, just render the default initial sidebar
  return createSidebarCard();
}

// Creates the standard Gmail sidebar card consisting of a text input and send button.
// Optionally includes an answer section if a response was generated.
function createSidebarCard(optionalAnswerSection) {
  const card = CardService.newCardBuilder();
  const actionSection = CardService.newCardSection();

  // Create text input for the user's message
  const messageInput = CardService.newTextInput()
    .setFieldName("message")
    .setTitle("Message")
    .setMultiline(true);

  // Create action for sending the message
  const sendAction = CardService.newAction()
    .setFunctionName('onAddonEvent')
    .setParameters({ 'action': 'send' });

  const sendButton = CardService.newTextButton()
    .setText("Send message")
    .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
    .setOnClickAction(sendAction);

  actionSection.addWidget(messageInput);
  actionSection.addWidget(CardService.newButtonSet().addButton(sendButton));

  card.addSection(actionSection);

  // Attach the response at the bottom if we have one
  if (optionalAnswerSection) {
    card.addSection(optionalAnswerSection);
  }

  return card.build();
}

// Handles clicks from the Send message button.
function handleSendMessage(event) {
  const commonEventObject = event.commonEventObject || {};
  const formInputs = commonEventObject.formInputs || {};
  const messageInput = formInputs.message;

  let userMessage = "";
  if (messageInput && messageInput.stringInputs && messageInput.stringInputs.value.length > 0) {
    userMessage = messageInput.stringInputs.value[0];
  }

  if (!userMessage || userMessage.trim().length === 0) {
    return CardService.newActionResponseBuilder()
      .setNotification(CardService.newNotification().setText("Please enter a message."))
      .build();
  }

  let finalQueryText = `USER MESSAGE TO ANSWER: ${userMessage}`;

  // If we have an email selected in Gmail, append its content as context
  if (event.gmail && event.gmail.messageId) {
    try {
      GmailApp.setCurrentMessageAccessToken(event.gmail.accessToken);
      const message = GmailApp.getMessageById(event.gmail.messageId);

      const subject = message.getSubject();
      const bodyText = message.getPlainBody() || message.getBody();

      finalQueryText += `\n\nEMAIL THE USER HAS OPENED ON SCREEN:\nSubject: ${subject}\nBody:\n---\n${bodyText}\n---`;
    } catch (e) {
      console.error("Could not fetch Gmail context: " + e);
      // Invalidate the token explicitly so the next prompt requests the missing scopes
      ScriptApp.invalidateAuth();

      CardService.newAuthorizationException()
        .setResourceDisplayName("Enterprise AI")
        .setAuthorizationUrl(ScriptApp.getAuthorizationUrl())
        .throwException();
    }
  }

  try {
    const responseText = queryAgent({ text: finalQueryText, forceNewSession: true });

    // We leverage the 'showdown' library to parse the LLM's Markdown output into HTML
    // We also substitute markdown listings with arrows and adjust newlines for clearer rendering in the sidebar
    let displayedText = substituteListingsFromMarkdown(responseText);
    displayedText = new showdown.Converter().makeHtml(displayedText).replace(/\n/g, '\n\n');

    const textParagraph = CardService.newTextParagraph();
    textParagraph.setText(displayedText);

    const answerSection = CardService.newCardSection()
      .addWidget(textParagraph);

    const updatedCard = createSidebarCard(answerSection);

    return CardService.newActionResponseBuilder()
      .setNavigation(CardService.newNavigation().updateCard(updatedCard))
      .build();

  } catch (err) {
    return CardService.newActionResponseBuilder()
      .setNotification(CardService.newNotification().setText("Error fetching response: " + err.message))
      .build();
  }
}
...

AgentHandler.gs

...
// Service that handles Gemini Enterprise AI Agent operations.

// Submits a query to the AI agent and returns the response string synchronously
function queryAgent(input) {
  const isNewSession = input.forceNewSession || !PropertiesService.getUserProperties().getProperty(AGENT_SESSION_NAME);
  const sessionName = input.forceNewSession ? createAgentSession() : getOrCreateAgentSession();

  let systemPrompt = "SYSTEM PROMPT START Do not respond with tables but use bullet points instead.";
  if (input.forceNewSession) {
    systemPrompt += " Do not ask the user follow-up questions or converse with them as history is not kept in this interface.";
  }
  systemPrompt += " SYSTEM PROMPT END\n\n";

  const queryText = isNewSession ? systemPrompt + input.text : input.text;

  const requestPayload = {
    "session": sessionName,
    "userMetadata": { "timeZone": Session.getScriptTimeZone() },
    "query": { "text": queryText },
    "toolsSpec": { "vertexAiSearchSpec": { "dataStoreSpecs": getAgentDataStores().map(ds => { dataStore: ds }) } },
    "agentsSpec": { "agentSpecs": [{ "agentId": getAgentId() }] }
  };

  const responseContentText = UrlFetchApp.fetch(
    `https://${getLocation()}-discoveryengine.googleapis.com/v1alpha/${getReasoningEngine()}/assistants/default_assistant:streamAssist?alt=sse`,
    {
      method: 'post',
      headers: { 'Authorization': `Bearer ${ScriptApp.getOAuthToken()}` },
      contentType: 'application/json',
      payload: JSON.stringify(requestPayload),
      muteHttpExceptions: true
    }
  ).getContentText();

  if (isInDebugMode()) {
    console.log(`Response: ${responseContentText}`);
  }

  const events = responseContentText.split('\n').map(s => s.replace(/^data:\s*/, '')).filter(s => s.trim().length > 0);
  console.log(`Received ${events.length} agent events.`);

  let answerText = "";
  for (const eventJson of events) {
    if (isInDebugMode()) {
      console.log("Event: " + eventJson);
    }
    const event = JSON.parse(eventJson);

    // Ignore internal events
    if (!event.answer) {
      console.log(`Ignored: internal event`);
      continue;
    }

    // Handle text replies
    const replies = event.answer.replies || [];
    for (const reply of replies) {
      const content = reply.groundedContent.content;
      if (content) {
        if (isInDebugMode()) {
          console.log(`Processing content: ${JSON.stringify(content)}`);
        }
        if (content.thought) {
          console.log(`Ignored: thought event`);
          continue;
        }
        answerText += content.text;
      }
    }

    if (event.answer.state === "SUCCEEDED") {
      console.log(`Answer text: ${answerText}`);
      return answerText;
    } else if (event.answer.state !== "IN_PROGRESS") {
      throw new Error("Something went wrong, check the Apps Script logs for more info.");
    }
  }
  return answerText;
}

// Gets the list of data stores configured for the agent to include in the request.
function getAgentDataStores() {
  const responseContentText = UrlFetchApp.fetch(
    `https://${getLocation()}-discoveryengine.googleapis.com/v1/${getReasoningEngine().split('/').slice(0, 6).join('/')}/dataStores`,
    {
      method: 'get',
      // Use the add on service account credentials for data store listing access
      headers: { 'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}` },
      contentType: 'application/json',
      muteHttpExceptions: true
    }
  ).getContentText();
  if (isInDebugMode()) {
    console.log(`Response: ${responseContentText}`);
  }
  const dataStores = JSON.parse(responseContentText).dataStores.map(ds => ds.name);
  if (isInDebugMode()) {
    console.log(`Data stores: ${dataStores}`);
  }
  return dataStores;
}
...

เริ่มต้นใช้งานบัญชีบริการ

ในคอนโซล Google Cloud ให้ทำตามขั้นตอนต่อไปนี้

  1. คลิกเมนู ☰ > IAM และผู้ดูแลระบบ > บัญชีบริการ > + สร้างบัญชีบริการ

  1. ตั้งชื่อบัญชีบริการเป็น ge-add-on

d44d6aae29e2464c.png

  1. คลิกสร้างและต่อไป
  2. เพิ่มบทบาทผู้มีสิทธิ์ดู Discovery Engine ในสิทธิ์

f1374efa4f326ef5.png

  1. คลิกต่อไป แล้วคลิกเสร็จสิ้น ระบบจะเปลี่ยนเส้นทางคุณไปยังหน้าบัญชีบริการ และคุณจะเห็นบัญชีบริการที่สร้างขึ้น

b9496085f1404c5c.png

  1. เลือกบัญชีบริการที่สร้างใหม่ แล้วเลือกแท็บคีย์
  2. คลิกเพิ่มคีย์ แล้วคลิกสร้างคีย์ใหม่
  3. เลือก JSON แล้วคลิกสร้าง

f4280f5533a08821.png

  1. กล่องโต้ตอบจะปิดลง และระบบจะดาวน์โหลดคู่คีย์สาธารณะ/ส่วนตัวที่สร้างขึ้นใหม่ลงในสภาพแวดล้อมในเครื่องโดยอัตโนมัติเป็นไฟล์ JSON

สร้างและกำหนดค่าโปรเจ็กต์ Apps Script

  1. คลิกปุ่มต่อไปนี้เพื่อเปิดโปรเจ็กต์ Apps Script ของส่วนเสริม Enterprise AI

  1. คลิกภาพรวม > ทำสำเนา
  2. ในโปรเจ็กต์ Apps Script ให้คลิกการตั้งค่าโปรเจ็กต์ > แก้ไขพร็อพเพอร์ตี้สคริปต์ > เพิ่มพร็อพเพอร์ตี้สคริปต์เพื่อเพิ่มพร็อพเพอร์ตี้สคริปต์
  3. ตั้งค่า REASONING_ENGINE_RESOURCE_NAME เป็นชื่อทรัพยากรแอปพลิเคชัน Gemini Enterprise โดยมีรูปแบบดังนี้
# 1. Replace PROJECT_ID with the Google Cloud project ID.
# 2. Replace GE_APP_ID with the codelab app ID found in Google Cloud console > Gemini Enterprise > Apps.

projects/<PROJECT_ID>/locations/global/collections/default_collection/engines/<GE_APP_ID>
  1. ตั้งค่า APP_SERVICE_ACCOUNT_KEY เป็นคีย์ JSON จากไฟล์บัญชีบริการที่ดาวน์โหลดในขั้นตอนก่อนหน้า
  2. คลิกบันทึกพร็อพเพอร์ตี้ของสคริปต์

ติดตั้งใช้งานใน Gmail และ Chat

ในโปรเจ็กต์ Apps Script ให้ทำตามขั้นตอนต่อไปนี้

  1. คลิกติดตั้งใช้งาน > ทดสอบการติดตั้งใช้งาน แล้วคลิกติดตั้ง ซึ่งตอนนี้พร้อมให้ใช้งานใน Gmail แล้ว
  2. คลิกคัดลอกในส่วนรหัสการทำให้ใช้งานได้ของส่วนหัว

2ed2df972ad92715.png

ในคอนโซล Google Cloud ให้ทำตามขั้นตอนต่อไปนี้

  1. ค้นหา Google Chat API ในช่องค้นหาของ Google Cloud คลิก Google Chat API คลิกจัดการ แล้วคลิกการกำหนดค่า

  1. เลือกเปิดใช้ฟีเจอร์แบบอินเทอร์แอกทีฟ
  2. ยกเลิกการเลือกเข้าร่วมพื้นที่ทำงานและการสนทนากลุ่ม
  3. เลือก Apps Script ในส่วนการตั้งค่าการเชื่อมต่อ
  4. ตั้งค่า Deployment ID เป็น Head Deployment ID ที่คัดลอกไว้ในขั้นตอนก่อนหน้า
  5. ในส่วนระดับการเข้าถึง ให้เลือกทำให้แอป Chat นี้พร้อมใช้งานสำหรับบุคคลและกลุ่มที่เฉพาะเจาะจงในโดเมน Workspace ของคุณ แล้วป้อนอีเมล
  6. คลิกบันทึก

3b7d461c423f7c51.png

ลองใช้ส่วนเสริม

เปิด Google Chat ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. เปิดพื้นที่ข้อความส่วนตัวด้วยแอป Chat Gemini Enterprise

3da8690d19baf2d0.png

  1. คลิกกำหนดค่า แล้วทำตามขั้นตอนการตรวจสอบสิทธิ์
  2. พิมพ์ What are my meetings for today? แล้วกด enter แอปแชทของ Gemini Enterprise ควรตอบกลับด้วยผลลัพธ์

c8c63fb3f324fecf.png

เปิด Gmail ในแท็บใหม่ แล้วทำตามขั้นตอนต่อไปนี้

  1. ส่งอีเมลถึงตัวเองโดยตั้งค่าเรื่องเป็น We need to talk และตั้งค่าเนื้อหาเป็น Are you available today between 8 and 9 AM?
  2. เปิดข้อความอีเมลที่ได้รับใหม่
  3. เปิดส่วนเสริม Enterprise AI ในแถบด้านข้าง
  4. ตั้งค่าข้อความเป็น Am I?
  5. คลิกส่งข้อความ
  6. คำตอบจะแสดงหลังจากปุ่ม

d33b8cb50ee251b7.png

6. ล้างข้อมูล

ลบโปรเจ็กต์ Google Cloud

เราขอแนะนำให้คุณลบโปรเจ็กต์ Google Cloud เพื่อหลีกเลี่ยงการเรียกเก็บเงินจากบัญชี Google Cloud สำหรับทรัพยากรที่ใช้ในโค้ดแล็บนี้

ในคอนโซล Google Cloud ให้ทำตามขั้นตอนต่อไปนี้

  1. คลิกเมนู ☰ > IAM และผู้ดูแลระบบ > การตั้งค่า

  1. คลิกปิดเครื่อง
  2. ป้อนรหัสโปรเจ็กต์
  3. คลิกปิดเครื่องต่อไป

3b9492d97f771b2c.png

7. ขอแสดงความยินดี

ยินดีด้วย คุณได้สร้างโซลูชันที่ใช้ประโยชน์จากการผสานรวม Gemini Enterprise และ Google Workspace เข้าด้วยกันเพื่อพนักงาน

ขั้นตอนต่อไปคืออะไร

เราจะแสดงเฉพาะกรณีการใช้งานที่พบบ่อยที่สุดใน Codelab นี้ แต่ก็ยังมีขอบเขตการขยายอีกมากมายที่คุณอาจต้องการพิจารณาในโซลูชันของคุณ เช่น

  • ใช้เครื่องมือสำหรับนักพัฒนาแอปที่ทำงานด้วยระบบ AI เช่น Gemini CLI และ Antigravity
  • ผสานรวมกับเฟรมเวิร์กและเครื่องมือของเอเจนต์อื่นๆ เช่น MCP ที่กำหนดเอง การเรียกใช้ฟังก์ชันที่กำหนดเอง และ UI แบบ Generative
  • ผสานรวมกับโมเดล AI อื่นๆ รวมถึงโมเดลที่กำหนดเองซึ่งโฮสต์อยู่ในแพลตฟอร์มเฉพาะ เช่น Vertex AI
  • ผสานรวมกับเอเจนต์อื่นๆ ที่โฮสต์ในแพลตฟอร์มเฉพาะ เช่น Dialogflow หรือโดยบุคคลที่สามผ่าน Cloud Marketplace
  • เผยแพร่เอเจนต์ใน Cloud Marketplace เพื่อเพิ่มศักยภาพให้กับทีม องค์กร หรือผู้ใช้ทั่วไป

ดูข้อมูลเพิ่มเติม

นักพัฒนาซอฟต์แวร์สามารถเข้าถึงแหล่งข้อมูลมากมาย เช่น วิดีโอบน YouTube, เว็บไซต์เอกสารประกอบ, ตัวอย่างโค้ด และบทแนะนำ