KRIT.JUNSREE PERSONAL WEBSITE
MEDIUM

Hermes Agent Full Setup — สร้าง Self-Improving AI Agent ใน 10 นาที

Nitin Gavhane สอน setup Hermes Agent ครบภายใน 10 นาที — Python 3.10, Groq API key ฟรี, agent ตัวแรกที่ค้นหาข้อมูล เขียน summary แล้วให้คะแนนตัวเอง พร้อมส่วนที่ tutorial ส่วนใหญ่ข้าม (verbose mode สำหรับ debug loop) การเพิ่ม tool (WebSearch + CodeExecutor + FileWriter) และ LocalMemory สำหรับ carry context ข้าม session — ปิดท้ายด้วยประเด็นสำคัญที่สุด: วิธีเขียน goal ที่เจาะจงพอ

By krit.junsree@gmail.com ◆ Jul 28, 2026 ◆ 9 MIN READ Beginner
Source image for Hermes Agent Full Setup — สร้าง Self-Improving AI Agent ใน 10 นาที
ที่มารูปภาพ: nitingavhane.medium.com

☰ ON THIS PAGE

Nitin Gavhane สอน setup Hermes Agent ครบขั้นตอนใน 10 นาที ตั้งแต่ Python venv, Groq API key, agent ตัวแรกที่ตรวจงานตัวเองแล้วแก้ใหม่ ไปจนถึงการเพิ่ม tool และ memory — พร้อมประเด็นสำคัญที่สุดที่หลาย tutorial ข้ามไป

ทำไมต้อง Hermes

ผมต้องการ agent ที่ทำ research, เขียน code, ตรวจ output ของตัวเองแล้ว retry เมื่อผลลัพธ์ยังไม่ดีพอ — ไม่ใช่ chatbot แต่เป็น agent จริง ๆ ที่ทำงานให้จบในขณะที่เราไปทำอย่างอื่น

Hermes ทำสิ่งนั้นได้ Label “self-improving” อาจจะเว่อไปหน่อย จริง ๆ มันแค่ให้คะแนน output ของตัวเองเทียบกับ goal ที่เราตั้งไว้ ถ้าคะแนนต่ำเกิน มันจะลองใหม่ ไอเดียเรียบง่าย แต่ทำงานได้ดีกว่าที่คิด

Setup

ต้องการ Python 3.10 ขึ้นไป และ Groq API key (free tier ก็เพียงพอกับทุกอย่างในบทความนี้)

bash
python -m venv hermes-env
source hermes-env/bin/activate
pip install hermes-agent groq python-dotenv

สร้างไฟล์ .env:

text
GROQ_API_KEY=your_key_here

เท่านี้ environment ก็พร้อมใช้งาน

Agent ตัวแรก

python
from hermes import Agent
from dotenv import load_dotenv

load_dotenv()

agent = Agent(
    model="mixtral-8x7b-32768",
    goal="Research the latest news about AI agents and summarize in 3 bullet points",
    max_iterations=5
)

result = agent.run()
print(result)

Agent จะ search → อ่าน → เขียน summary → แล้วถามตัวเองว่า output ตรงกับ goal ไหม ถ้าตรงก็หยุด ถ้าไม่ตรงก็ลองใหม่จนถึง 5 ครั้ง (หรือตามที่กำหนด)

ไม่ได้หวือหวาอะไร แค่ทำงานให้เสร็จ

ส่วนที่ tutorial ส่วนใหญ่ข้าม

เพิ่ม verbose=True แล้วจะเห็น reasoning ของ agent ระหว่างที่มันทำงาน:

text
agent = Agent(
    model="mixtral-8x7b-32768",
    goal="Write a Python function to scrape product prices from a URL",
    max_iterations=5,
    verbose=True,
    success_threshold=0.85
)

เราจะเห็นว่ามัน produce อะไร ให้คะแนนตัวเองเท่าไหร่ และรอบต่อไปจะเปลี่ยนอะไรบ้าง ครั้งแรกที่ผมดู agent ปฏิเสธ output ของตัวเองแล้วเริ่มใหม่ ผมนั่งอ่าน log อยู่พักหนึ่ง — ไม่ใช่เพราะเป็น moment มหัศจรรย์อะไร แต่รู้สึกแค่ว่า “อ๋อ มันทำจริง ๆ ด้วย”

Verbose mode ยังเป็นวิธี debug เมื่อ agent ติด loop ปกติสาเหตุคือ goal คลุมเครือเกินไป หรือ model produce weak answer ซ้ำ ๆ จน critic แยกไม่ออกว่าเวอร์ชันไหนดีกว่า ทั้งสองปัญหามีทางแก้

เพิ่ม Tool

Agent เปล่า ๆ ทำได้แค่คิด แต่ถ้าให้ tool มัน act ได้:

python
from hermes.tools import WebSearch, CodeExecutor, FileWriter

agent = Agent(
    model="mixtral-8x7b-32768",
    goal="Find the top 5 Python libraries for web scraping, write a comparison table, and save it to comparison.md",
    tools=[WebSearch(), CodeExecutor(), FileWriter()],
    max_iterations=8
)

WebSearch ดึงข้อมูล current จาก web · CodeExecutor รัน และ test code ก่อน include ใน output · FileWriter save ผลลัพธ์ลง disk เมื่อมีครบสามอย่าง agent จะ search + verify + write + drop finished file ในโฟลเดอร์ให้โดยที่เราไม่ต้องแตะ

ไม่ได้ถูกใน first pass เสมอไป แต่ปกติใกล้พอที่จะแก้ได้ ซึ่งเร็วกว่าเริ่มใหม่ตั้งแต่ต้น

Memory

ปกติ agent จะเริ่มใหม่ทุก run ถ้าต้องการให้ carry context ข้าม session:

python
from hermes.memory import LocalMemory

agent = Agent(
    model="mixtral-8x7b-32768",
    goal="Continue building the project tracker we started yesterday",
    memory=LocalMemory(path="./agent_memory"),
    max_iterations=10
)

Save ทุกอย่างลง local โดยไม่ต้องมี external database สำหรับ experiment ส่วนตัวก็เพียงพอมากแล้ว

สิ่งเดียวที่สำคัญจริง ๆ

วิธีเขียน goal คือสิ่งที่ตัดสินเกือบทุกอย่าง

“Write something about machine learning” จะได้ paragraph หนึ่งย่อหน้ากลาง ๆ ที่ใช้อะไรไม่ได้

“Write a 200-word explanation of gradient descent for a developer with no math background, one Python code example, no jargon” จะได้อะไรที่ใช้ได้จริงหรือ share ต่อได้

Agent ให้คะแนนตัวเองเทียบกับ goal เมื่อ goal คลุมเครือ answer ปานกลางก็ได้คะแนนดี และ loop ก็จบเร็ว agent จึงไม่มีโอกาส improve เพราะมัน “คิดว่าเสร็จแล้ว” การเจาะจงเพิ่มอีก 30 วินาทีเปลี่ยน result ทั้งหมด

สรุป

5 step · 1 ไฟล์ .env · 10 นาทีถ้าพิมพ์ช้าหน่อย

ทุกวันนี้ผมใช้อะไรที่ build บน setup แบบนี้อยู่เกือบทุกวัน ไม่ใช่เพราะมัน replace การคิด แต่เพราะบาง task ไม่ต้องคิดมาก แล้วก็ดีที่มีเครื่องมือคอย handle เรื่องพวกนั้นให้


ที่มา: Hermes Agent Full Setup by Nitin Gavhane — เผยแพร่ 23 พ.ค. 2026