| name | agentic-stack-orchestrator |
| description | Orchestrate AI agent infrastructure using Modal.com as the execution layer, managing persistent state, and integrating with Cline/OpenCode/Hermes. |
Agentic Stack Orchestrator: Infrastructure & Execution
ทักษะนี้รวบรวมแนวทางการจัดการโครงสร้างพื้นฐานสำหรับ AI Agents ขั้นสูง โดยเน้นการใช้ Modal.com เป็น "Execution Layer" ที่ปลอดภัยและประหยัด ร่วมกับการใช้ระบบ Orchestration อย่าง Cline/OpenCode และการจัดการความจำระยะยาวแบบ Hermes Agent
触发条件 (Triggers)
- เมื่อต้องการตั้งค่า Backend ให้กับ AI Agent (Claude Code, Cline, OpenCode)
- เมื่อต้องการรันโค้ดที่ AI เขียนในสภาพแวดล้อมที่แยกส่วน (Sandboxed Execution)
- เมื่อต้องการจัดการไฟล์ให้คงอยู่ข้าม Session (Persistence)
- เมื่อต้องการประหยัดค่าใช้จ่ายในการรัน Agent 24/7
ชั้นของสถาปัตยกรรม (Stack Layers)
1. Orchestration Layer (The Brain)
- Tools: Cline SDK, OpenCode SDK, Agent SDK
- หน้าที่: จัดการ Session, วางแผน (Plan Mode), และขออนุมัติการใช้เครื่องมือ (Tool Approval)
2. Execution Layer (The Hands)
- Tools: Modal.com Sandboxes, E2B, GKE Agent Sandbox
- หน้าที่: รันโค้ด Python/Node.js ใน gVisor Isolation, คืนค่า stdout/stderr กลับไปยังสมอง
3. Persistence & Memory (The Knowledge)
- Tools: Modal Volumes, Notion Workers, Hermes auto-sync
- หน้าที่: เก็บไฟล์งานและบันทึกบทเรียน (Playbooks) ไม่ให้หายไปเมื่อ Sandbox ปิดตัวลง
ขั้นตอนการติดตั้งและตั้งค่า (Workflow)
Step 1: เตรียมสภาพแวดล้อมบน Modal.com
- ติดตั้ง Modal CLI:
pip install modal
- ตั้งค่า Token:
modal token set
- สร้าง Volume สำหรับเก็บงาน:
modal volume create agent-workspace
Step 2: การตั้งค่าภาพจำลอง (Image Template)
สร้างไฟล์ backend.py เพื่อกำหนดสภาพแวดล้อม:
import modal
image = modal.Image.debian_slim().pip_install("pandas", "requests", "anyhow")
app = modal.App.lookup("agent-backend", create_if_missing=True)
Step 3: การเชื่อมต่อกับ Agent (Integration)
- Hermes Pattern: ตั้งค่า
config.yaml ให้ใช้ backend: modal และ container_persistent: true
- Cline/OpenCode Pattern: ใช้ Modal CLI เป็นเครื่องมือรันคำสั่ง:
modal run execute.py --code "..."
การจัดการต้นทุน (Cost Optimization)
- Scale-to-Zero: ระบบจะหยุดคิดเงินทันทีที่ Agent หยุดทำงาน (วินาทีละ $0.00004)
- Starter Credits: ใช้ประโยชน์จากเครดิตฟรี $30/เดือน ซึ่งเพียงพอสำหรับการรัน Agent ทั่วไป 2-4 ชั่วโมงต่อวัน
- Caching: ใช้
modal.Image.run_commands() เพื่อทำ Layer Caching ช่วยลดเวลา Cold Start
กฎความปลอดภัย (Safety & Guardrails)
- gVisor: มั่นใจได้ว่าโค้ดที่ AI เจนจะไม่หลุดออกมาทำลายเครื่องจริง
- Egress Policy: จำกัดการเข้าถึงอินเทอร์เน็ตของ Sandbox หากไม่จำเป็น
- Auto-sync: ตรวจสอบไฟล์ที่ Agent แก้ไขก่อนดึงกลับมาที่ Host เสมอ
คำสั่งแนะนำ (Quick Commands)
agent-stack status: ตรวจสอบสถานะการเชื่อมต่อกับ Modal
agent-stack clean: ล้างไฟล์ขยะใน Volume ของ Agent
agent-stack deploy: อัปเดต Image ล่าสุดขึ้นไปยัง Cloud