Skip to main content

Lab 2 — กลไกประสานงาน: กระดานกลาง กราฟงาน และการประมูลงาน

Lab walkthrough · EP15 Multi-Agent Systems: When and How Agents Work Together

หมายเหตุวิธีใช้หน้านี้

หน้านี้คือ notebook เฉลยของ lab นี้ทีละ cell พร้อม output จากการรันจริงตอนอัดคลิป ไว้อ่านทวนก่อนหรือหลังลงมือ cell ที่มี ✏️ TODO แสดงโค้ดแบบใน starter notebook ส่วนเฉลยเต็มอยู่ในกล่อง ดูเฉลย ลองเขียนเองก่อนค่อยเปิด

▶ วิดีโอ · ✏️ Starter ใน Colab · ✅ เฉลยใน Colab · กลับไปหน้า EP15 Multi-Agent Systems: When and How Agents Work Together

model ตอบไม่เหมือนเดิมทุกครั้ง output ที่คุณรันเองจึงอาจต่างจากหน้านี้

Lab 1 ทุกอย่างผ่าน supervisor ตัวเดียว Lab นี้ลองกลไกประสานงานอีกสามแบบจากคลิปทฤษฎี (§24.3)

สิ่งที่จะได้ทำ

  1. Blackboard กระดานกลางที่ค่ามั่นใจกว่าชนะเมื่อเขียนทับกัน และแจ้งเตือนผู้ที่สนใจ (Listing 24.1)
  2. Task DAG แตกงานเป็นกราฟ งานที่พร้อมรันพร้อมกันด้วย asyncio แล้วจับเวลาเทียบกับทีละงาน (Listing 24.2)
  3. กันงานซ้ำ เช็กกระดานก่อนเริ่ม ใช้ผลเดิมซ้ำ (§24.8.2)
  4. Contract Net ประกาศงาน ให้ผู้รับงานยื่นข้อเสนอ แล้วเลือกผู้ชนะ (§24.3.5) — และดูว่าข้อเสนอเชื่อได้แค่ไหน

ข้อมูล paper เป็นข้อมูลจำลองเพื่อการสอน (เลข arXiv ชื่อ ผู้เขียน และปีเป็นของจริง บทสรุปบรรทัดเดียวเขียนขึ้นสำหรับ lab) ส่วน output ของ model มาจากการรันจริง

อ้างอิง: Haggai Roitman, The Hitchhiker’s Guide to Agentic AI, §24.3, §24.5.2, §24.8.2 — CC BY-SA 4.0

0. เตรียมเครื่องก่อนเริ่ม

สิ่งที่ต้องมี รายละเอียด
Python 3.10 ขึ้นไป หรือใช้ Google Colab ซึ่งมีให้แล้ว
OpenRouter API key สมัครที่ openrouter.ai → Keys → Create Key แล้วเติมเครดิต (lab นี้ใช้ไม่ถึงครึ่งเซ็นต์ดอลลาร์)
Packages openai, python-dotenv (ติดตั้งใน cell ถัดไป)

ใส่ API key

  • Colab: ไอคอน 🔑 Secrets → ชื่อ OPENROUTER_API_KEY → เปิด Notebook access
  • เครื่องตัวเอง: สร้างไฟล์ .env ในโฟลเดอร์เดียวกับ notebook แล้วใส่บรรทัด OPENROUTER_API_KEY=sk-or-...

⚠️ อย่าใส่ key ลงในโค้ดโดยตรง และอย่าแชร์ไฟล์ .env

%pip install -q "openai>=1.50" python-dotenv
import asyncio, json, os, time
from collections import Counter
from dataclasses import dataclass, field
from openai import AsyncOpenAI
def load_key():
    try:  # Google Colab Secrets
        from google.colab import userdata
        return userdata.get("OPENROUTER_API_KEY")
    except ImportError:
        pass
    from dotenv import load_dotenv
    load_dotenv()
    return os.environ["OPENROUTER_API_KEY"]

PAPERS = {  # teaching data: real arXiv ids, titles, authors and years; one-line summaries written for this lab
    "2310.08560": {"title": "MemGPT: Towards LLMs as Operating Systems", "authors": "Packer et al.", "year": 2023,
                   "summary": "the LLM pages facts between a small main context and a large external store, like an operating system's virtual memory"},
    "2304.03442": {"title": "Generative Agents: Interactive Simulacra of Human Behavior", "authors": "Park et al.", "year": 2023,
                   "summary": "agents keep a memory stream of observations, score memories by recency, importance and relevance, and write reflections"},
    "2303.11366": {"title": "Reflexion: Language Agents with Verbal Reinforcement Learning", "authors": "Shinn et al.", "year": 2023,
                   "summary": "after a failed try the agent writes a short lesson to its memory and uses it on the next try"},
    "2504.19413": {"title": "Mem0: Building Production-Ready AI Agents with Scalable Long-Term Memory", "authors": "Chhikara et al.", "year": 2025,
                   "summary": "an LLM extracts facts from each conversation and decides to add, update or delete them in a long-term store"},
    "2502.12110": {"title": "A-MEM: Agentic Memory for LLM Agents", "authors": "Xu et al.", "year": 2025,
                   "summary": "each memory is a linked note with keywords and tags, and new notes update links to old ones"},
}

Model: google/gemma-4-26b-a4b-it ล็อก provider เป็น Makora — วิธีตั้งค่า key และเหตุผลที่เลือก model อยู่ใน Lab 1

MODEL = "google/gemma-4-26b-a4b-it"
EXTRA = {"reasoning": {"enabled": False},
         "provider": {"order": ["makora"], "allow_fallbacks": False}}
client = AsyncOpenAI(base_url="https://openrouter.ai/api/v1", api_key=load_key(), max_retries=5)
TOKENS = Counter()
async def llm(agent, system, user, schema=None):
    kw = {}
    if schema:
        kw["response_format"] = {"type": "json_schema", "json_schema": {"name": "out", "strict": True, "schema": schema}}
    r = await client.chat.completions.create(model=MODEL, temperature=0, extra_body=EXTRA, **kw,
            messages=[{"role": "system", "content": system}, {"role": "user", "content": user}])
    TOKENS[agent] += r.usage.total_tokens
    text = r.choices[0].message.content
    return json.loads(text) if schema else text

1. Blackboard

ย่อจาก Listing 24.1: ทุกค่าบนกระดานจำว่า ใครเขียน และ มั่นใจแค่ไหน

  • เขียนทับช่องเดิม → ค่าที่ มั่นใจกว่าชนะ (ค่าเดิมมั่นใจกว่า = ไม่เขียนทับ)
  • subscribe(key, callback) → แจ้งเตือนผู้ที่สนใจช่องนั้นเมื่อค่าเปลี่ยน
@dataclass
class Entry:
    value: object
    author: str
    confidence: float

# ✏️ TODO 1 (▶ วิดีโอ 1:52): ไม่เขียนทับ ถ้าค่าเดิมมั่นใจกว่าค่าใหม่

class Blackboard:
    def __init__(self):
        self.data, self.subscribers = {}, {}

    def write(self, key, value, author, confidence=1.0):
        old = self.data.get(key)
        if ___:
            print(f"  ✗ {author} → {key}: kept {old.author}'s value ({old.confidence} > {confidence})")
            return False
        self.data[key] = Entry(value, author, confidence)
        for callback in self.subscribers.get(key, []):
            callback(key, value, author)
        return True

    def read(self, key):
        entry = self.data.get(key)
        return entry.value if entry else None

    def subscribe(self, key, callback):
        self.subscribers.setdefault(key, []).append(callback)
@dataclass
class Entry:
    value: object
    author: str
    confidence: float

class Blackboard:
    def __init__(self):
        self.data, self.subscribers = {}, {}

    def write(self, key, value, author, confidence=1.0):
        old = self.data.get(key)
        if old and old.confidence > confidence:
            print(f"  ✗ {author} → {key}: kept {old.author}'s value ({old.confidence} > {confidence})")
            return False
        self.data[key] = Entry(value, author, confidence)
        for callback in self.subscribers.get(key, []):
            callback(key, value, author)
        return True

    def read(self, key):
        entry = self.data.get(key)
        return entry.value if entry else None

    def subscribe(self, key, callback):
        self.subscribers.setdefault(key, []).append(callback)
bb = Blackboard()
bb.subscribe("best_intro_paper", lambda k, v, who: print(f"  🔔 writer sees {k} = {v!r} (from {who})"))

bb.write("best_intro_paper", "2310.08560", author="researcher", confidence=0.9)
bb.write("best_intro_paper", "2302.04761", author="quick-reader", confidence=0.4)
bb.write("best_intro_paper", "2304.03442", author="reviewer", confidence=0.95)
print("on the board:", bb.read("best_intro_paper"), "by", bb.data["best_intro_paper"].author)
  🔔 writer sees best_intro_paper = '2310.08560' (from researcher)
  ✗ quick-reader → best_intro_paper: kept researcher's value (0.9 > 0.4)
  🔔 writer sees best_intro_paper = '2304.03442' (from reviewer)
on the board: 2304.03442 by reviewer

2. Task DAG: งานที่พร้อมรันพร้อมกัน

read:2310.08560 ─┐
read:2304.03442 ─┤
read:2303.11366 ─┼─→ compare ─→ abstract
read:2504.19413 ─┤
read:2502.12110 ─┘

งานอ่านห้างานไม่ต้องรอกัน · compare ต้องรอทั้งห้า · abstract ต้องรอ compare (Listing 24.2) ผลของทุกงานเขียนลง กระดานกลาง — งานถัดไปอ่านจากกระดาน

@dataclass
class Task:
    id: str
    agent: str
    prompt: str
    deps: list = field(default_factory=list)
    status: str = "pending"   # pending | running | done

def make_dag():
    reads = [Task(f"read:{pid}", "reader", f"In one sentence, what does this paper do?\n{json.dumps(p)}")
             for pid, p in PAPERS.items()]
    compare = Task("compare", "analyst", "Compare these five approaches to agent memory in 3 bullets.",
                   deps=[t.id for t in reads])
    abstract = Task("abstract", "writer", "Write a 2-sentence abstract from this comparison.", deps=["compare"])
    return {t.id: t for t in reads + [compare, abstract]}
async def run_task(t, dag, bb):
    t.status = "running"
    inputs = "\n".join(f"{d}: {bb.read(d)}" for d in t.deps)
    prompt = t.prompt + (f"\n\nInputs:\n{inputs}" if inputs else "")
    t0 = time.perf_counter()
    result = await llm(t.agent, f"You are the {t.agent} of a research team.", prompt)
    bb.write(t.id, result, author=t.agent)
    t.status = "done"
    print(f"  ✓ {t.id:<16} {time.perf_counter() - t0:4.1f} s")
# ✏️ TODO 2 (▶ วิดีโอ 4:16): งานพร้อมเมื่อยังรออยู่ และงานที่ต้องรอก่อนเสร็จหมดแล้ว
def ready(dag):
    return [t for t in dag.values()
            if t.status == "pending" and ___]
def ready(dag):
    return [t for t in dag.values()
            if t.status == "pending" and all(dag[d].status == "done" for d in t.deps)]
# ✏️ TODO 3 (▶ วิดีโอ 4:29): รันงานที่พร้อมทั้งชุดพร้อมกัน แล้วรอจนเสร็จทั้งหมด
async def run_one_by_one(dag, bb):
    for t in dag.values():
        await run_task(t, dag, bb)

async def run_in_parallel(dag, bb):
    while any(t.status != "done" for t in dag.values()):
        batch = ready(dag)
        print("  ready:", [t.id for t in batch])
        await ___
async def run_one_by_one(dag, bb):
    for t in dag.values():
        await run_task(t, dag, bb)

async def run_in_parallel(dag, bb):
    while any(t.status != "done" for t in dag.values()):
        batch = ready(dag)
        print("  ready:", [t.id for t in batch])
        await asyncio.gather(*[run_task(t, dag, bb) for t in batch])
t0 = time.perf_counter()
await run_one_by_one(make_dag(), Blackboard())
one_by_one = time.perf_counter() - t0
print(f"one by one: {one_by_one:.1f} s")
  ✓ read:2310.08560   1.7 s
  ✓ read:2304.03442   1.1 s
  ✓ read:2303.11366   1.1 s
  ✓ read:2504.19413   0.7 s
  ✓ read:2502.12110   1.0 s
  ✓ compare           1.2 s
  ✓ abstract          1.1 s
one by one: 7.9 s
bb = Blackboard()
t0 = time.perf_counter()
await run_in_parallel(make_dag(), bb)
parallel = time.perf_counter() - t0
print(f"parallel: {parallel:.1f} s   (one by one: {one_by_one:.1f} s)")
print("\n" + bb.read("abstract"))
  ready: ['read:2310.08560', 'read:2304.03442', 'read:2303.11366', 'read:2504.19413', 'read:2502.12110']
  ✓ read:2310.08560   0.8 s
  ✓ read:2303.11366   1.1 s
  ✓ read:2502.12110   1.2 s
  ✓ read:2504.19413   1.2 s
  ✓ read:2304.03442   1.3 s
  ready: ['compare']
  ✓ compare           1.6 s
  ready: ['abstract']
  ✓ abstract          0.8 s
parallel: 3.8 s   (one by one: 7.9 s)

This comparative analysis examines five distinct approaches to agent memory, categorizing them by their architectural focus, cognitive mechanisms, and primary operational objectives. The findings reveal a diverse landscape ranging from system-level memory management and structured knowledge mapping to iterative self-critique and dynamic fact extraction.

3. กันงานซ้ำด้วยกระดาน

ตำรา §24.8.2: ก่อนเริ่มงาน เช็กกระดานว่ามีผลอยู่แล้วหรือยัง — ถ้ามี ใช้ผลเดิม (result caching)

async def run_task_cached(t, dag, bb):
    if bb.read(t.id) is not None:
        t.status = "done"
        print(f"  ♻ {t.id:<16} already on the board, by {bb.data[t.id].author}")
        return
    await run_task(t, dag, bb)
before = sum(TOKENS.values())
dag = make_dag()
dag["abstract"].prompt = "Write a 1-sentence abstract for first-year students from this comparison."
bb.data.pop("abstract")
while any(t.status != "done" for t in dag.values()):
    await asyncio.gather(*[run_task_cached(t, dag, bb) for t in ready(dag)])
print(f"tokens this run: {sum(TOKENS.values()) - before:,}")
print("\n" + bb.read("abstract"))
  ♻ read:2310.08560  already on the board, by reader
  ♻ read:2304.03442  already on the board, by reader
  ♻ read:2303.11366  already on the board, by reader
  ♻ read:2504.19413  already on the board, by reader
  ♻ read:2502.12110  already on the board, by reader
  ♻ compare          already on the board, by analyst
  ✓ abstract          0.9 s
tokens this run: 339

This comparison examines five distinct approaches to AI agent memory, ranging from system-level management and structured knowledge mapping to cognitive mechanisms like self-critique and social simulation, to determine how each optimizes for efficiency, scalability, or task accuracy.

4. Contract Net: ประมูลงาน

ผู้รับงานสามตัว แต่ละตัวมีความสามารถใน ทะเบียน (registry):

ผู้รับงาน เห็นข้อมูลอะไร เขียนภาษา token ต่อ paper
quick-reader ชื่อเรื่อง + บทสรุป English 300
thai-writer ชื่อเรื่อง + บทสรุป Thai, English 800
deep-reader ทั้งหมด รวมผู้เขียนและปี English 2000

สี่ขั้นของ Contract Net (§24.3.5): ① ประกาศงาน ② ยื่นข้อเสนอ ③ ให้งานกับข้อเสนอที่ดีที่สุด ④ ทำงานและรายงานผล ข้อเสนอ: model ตอบเองว่า ทำได้ไหม · มั่นใจแค่ไหน · ทำอย่างไร ส่วนต้นทุนคำนวณจากทะเบียน

REGISTRY = {
    "quick-reader": {"sees": ["title", "summary"], "writes": ["English"], "tokens_per_paper": 300},
    "thai-writer":  {"sees": ["title", "summary"], "writes": ["Thai", "English"], "tokens_per_paper": 800},
    "deep-reader":  {"sees": ["title", "authors", "year", "summary"], "writes": ["English"], "tokens_per_paper": 2000},
}
BID = {"type": "object", "properties": {"can_do": {"type": "boolean"}, "confidence": {"type": "number"},
                                        "plan": {"type": "string"}},
       "required": ["can_do", "confidence", "plan"], "additionalProperties": False}
async def bid(name, task):
    me = REGISTRY[name]
    b = await llm(name, f"You are the contractor '{name}'. The manager will hand you the paper records, "
                  f"but you see only these fields: {', '.join(me['sees'])}. "
                  f"You write only in: {', '.join(me['writes'])}. A manager announces a task. Bid honestly: "
                  "can you do it with exactly these abilities? Give your confidence (0-1) and a one-line plan.",
                  f"Task announcement: {task['text']}", BID)
    b["cost"] = me["tokens_per_paper"] * task["papers"]
    return name, b
async def auction(task, check_registry=False):
    bids = dict(await asyncio.gather(*[bid(name, task) for name in REGISTRY]))
    for name, b in bids.items():
        print(f"  {name:<13} can_do={b['can_do']!s:<5} conf={b['confidence']:.2f} cost={b['cost']:>5}  {b['plan'][:60]}")
    ok = {n: b for n, b in bids.items() if b["can_do"]}
    # ✏️ TODO 4 (▶ วิดีโอ 7:37): เก็บเฉพาะผู้รับงานที่ทะเบียนบอกว่าเห็นข้อมูลที่งานต้องใช้ และเขียนภาษาที่งานต้องการได้
    if check_registry:
        ok = {n: b for n, b in ok.items()
              if ___ and ___}
    # ✏️ TODO 5 (▶ วิดีโอ 7:49): ให้งานกับข้อเสนอที่ความมั่นใจต่อต้นทุนสูงที่สุด
    winner = max(ok, key=___) if ok else None
    print("  🏆", winner)
    return winner
async def auction(task, check_registry=False):
    bids = dict(await asyncio.gather(*[bid(name, task) for name in REGISTRY]))
    for name, b in bids.items():
        print(f"  {name:<13} can_do={b['can_do']!s:<5} conf={b['confidence']:.2f} cost={b['cost']:>5}  {b['plan'][:60]}")
    ok = {n: b for n, b in bids.items() if b["can_do"]}
    if check_registry:
        ok = {n: b for n, b in ok.items()
              if set(task["needs"]) <= set(REGISTRY[n]["sees"]) and task["language"] in REGISTRY[n]["writes"]}
    winner = max(ok, key=lambda n: ok[n]["confidence"] / ok[n]["cost"]) if ok else None
    print("  🏆", winner)
    return winner
TASKS = [
    {"text": "Summarize 3 papers on agent memory in Thai for first-year students.",
     "papers": 3, "needs": ["title", "summary"], "language": "Thai"},
    {"text": "Give a one-line English summary of each of 3 papers on agent memory.",
     "papers": 3, "needs": ["title", "summary"], "language": "English"},
    {"text": "Make a reference list with the authors and year of 3 papers on agent memory.",
     "papers": 3, "needs": ["title", "authors", "year"], "language": "English"},
]
for task in TASKS:
    print("📣", task["text"])
    await auction(task)
📣 Summarize 3 papers on agent memory in Thai for first-year students.
  quick-reader  can_do=False conf=0.10 cost=  900  I cannot perform this task because I can only write in Engli
  thai-writer   can_do=True  conf=1.00 cost= 2400  Translate key concepts into simple Thai and structure the su
  deep-reader   can_do=False conf=0.10 cost= 6000  I can summarize the papers in English, but I cannot perform 
  🏆 thai-writer
📣 Give a one-line English summary of each of 3 papers on agent memory.
  quick-reader  can_do=True  conf=1.00 cost=  900  I will read the summaries of the three papers and provide a 
  thai-writer   can_do=True  conf=1.00 cost= 2400  I will read the provided titles and summaries to extract and
  deep-reader   can_do=True  conf=1.00 cost= 6000  I will read the summaries of the three provided papers and r
  🏆 quick-reader
📣 Make a reference list with the authors and year of 3 papers on agent memory.
  quick-reader  can_do=True  conf=1.00 cost=  900  I will search for three prominent papers on agent memory and
  thai-writer   can_do=True  conf=1.00 cost= 2400  I will search for three influential papers on agent memory a
  deep-reader   can_do=True  conf=1.00 cost= 6000  I will search my internal database for three papers regardin
  🏆 quick-reader
winners = {}
for task in TASKS:
    print("📣", task["text"])
    winners[task["text"]] = await auction(task, check_registry=True)
📣 Summarize 3 papers on agent memory in Thai for first-year students.
  quick-reader  can_do=False conf=0.10 cost=  900  I can summarize the papers in English, but I cannot perform 
  thai-writer   can_do=True  conf=1.00 cost= 2400  Read the English papers, extract core concepts of agent memo
  deep-reader   can_do=False conf=0.10 cost= 6000  I can summarize the papers in English based on the provided 
  🏆 thai-writer
📣 Give a one-line English summary of each of 3 papers on agent memory.
  quick-reader  can_do=True  conf=1.00 cost=  900  I will read the title and summary of each paper and provide 
  thai-writer   can_do=True  conf=1.00 cost= 2400  I will read the title and summary of each paper and synthesi
  deep-reader   can_do=True  conf=1.00 cost= 6000  I will read the summaries of the three provided papers and r
  🏆 quick-reader
📣 Make a reference list with the authors and year of 3 papers on agent memory.
  quick-reader  can_do=True  conf=1.00 cost=  900  I will search for three prominent papers regarding agent mem
  thai-writer   can_do=True  conf=1.00 cost= 2400  I will search for three influential papers on agent memory a
  deep-reader   can_do=True  conf=1.00 cost= 6000  I will search my internal database for three papers regardin
  🏆 deep-reader
task = TASKS[0]
name = winners[task["text"]]
papers = [{f: p[f] for f in REGISTRY[name]["sees"]} for p in list(PAPERS.values())[:3]]
report = await llm(name, f"You are '{name}'. Do the task. Use only the paper data given.",
                   f"{task['text']}\n\nPapers:\n{json.dumps(papers, ensure_ascii=False)}")
print(f"report from {name}:\n{report}")
report from thai-writer:
สรุปเรื่อง "หน่วยความจำของเอเจนต์ (Agent Memory)" จากงานวิจัย 3 ฉบับ สำหรับนักศึกษาปี 1 แบบเข้าใจง่ายครับ:

**1. MemGPT: การทำให้ LLM ทำงานเหมือนระบบปฏิบัติการ**
งานวิจัยนี้เปรียบเทียบการทำงานของโมเดลภาษา (LLM) กับระบบปฏิบัติการในคอมพิวเตอร์ โดยให้โมเดลจัดการ "สลับข้อมูล" ระหว่างหน่วยความจำหลักที่มีขนาดเล็ก (Main Context) กับหน่วยความจำภายนอกที่มีขนาดใหญ่ (External Store) คล้ายกับการทำงานของ Virtual Memory ในคอมพิวเตอร์ เพื่อให้โมเดลสามารถจดจำข้อมูลจำนวนมหาศาลได้

**2. Generative Agents: การจำลองพฤติกรรมมนุษย์ผ่านหน่วยความจำ**
งานวิจัยนี้เน้นการสร้างเอเจนต์ที่มีพฤติกรรมเหมือนมนุษย์ โดยเอเจนต์จะเก็บ "กระแสความจำ" (Memory Stream) จากสิ่งที่สังเกตเห็น จากนั้นจะทำการให้คะแนนความจำเหล่านั้นโดยดูจาก ความใหม่ (Recency), ความสำคัญ (Importance) และความเกี่ยวข้อง (Relevance) รวมถึงมีการเขียน "การสะท้อนความคิด" (Reflections) เพื่อสรุปสิ่งที่เรียนรู้

**3. Reflexion: การเรียนรู้ผ่านการสะท้อนความผิดพลาด**
งานวิจัยนี้เสนอวิธีการให้เอเจนต์เรียนรู้จากความผิดพลาด โดยเมื่อเอเจนต์ทำงานล้มเหลว มันจะเขียน "บทเรียนสั้นๆ" (Short Lesson) ลงในหน่วยความจำของตัวเอง เพื่อนำบทเรียนนั้นกลับมาใช้ปรับปรุงการทำงานในครั้งต่อไป (คล้ายกับการเรียนรู้แบบ Verbal Reinforcement Learning)

สรุป

กลไก ในโค้ด ได้อะไร ระวังอะไร
Blackboard (§24.3.1) Blackboard.write / subscribe ไม่ต้องส่งข้อความหากัน, กฎความมั่นใจแก้ความขัดแย้ง ความมั่นใจที่ model บอกเองเชื่อได้ไม่หมด
Task DAG (§24.3.3) ready + asyncio.gather งานที่ไม่ต้องรอกันรันพร้อมกัน เวลาลดลง งานที่ต้องรอกันไม่เร็วขึ้น
กันงานซ้ำ (§24.8.2) สถานะ running (lock) + เช็กกระดานก่อนเริ่ม ไม่เสีย token กับงานที่มีผลแล้ว ต้องรู้ว่าเมื่อไรผลเก่าใช้ไม่ได้แล้ว
Contract Net (§24.3.5) bid → auction → ทำงาน งานไปหาตัวที่เหมาะและถูกที่สุด ข้อเสนอที่ model ประเมินตัวเอง → ตรวจกับทะเบียน

แบบฝึกหัด

  1. ให้ bid ขอให้ model ประเมิน token เอง แทนการคิดจากทะเบียน แล้วดูว่าผู้ชนะเปลี่ยนไหม
  2. เพิ่มงาน glossary ที่ต้องรอแค่งานอ่าน (ไม่รอ compare) — มันรันในรอบไหน
  3. ให้ subscriber ของช่อง compare เรียก writer เขียน abstract เองเมื่อค่าเปลี่ยน (stigmergy: ประสานงานผ่านสิ่งแวดล้อม)

ถัดไป — Lab 3: agent ตัวเดียว เทียบกับการโหวตและการ debate บนคำถามที่รู้คำตอบ แล้วให้ red team หาจุดผิด