跳到正文
DEV Community· Anindya Mukherjee·· 4 小時前AI 評分53

多個 AI 智能體開始互相爭論時會發生甚麼?

What Happens When Your AI Agents Start Arguing With Each Other?

AI 導讀

缺乏協調規則的多智能體系統容易重複搜尋、互相改寫並陷入循環;文中例子用了 27 次 API 呼叫、花費 $3,摘要品質仍不及免費版 ChatGPT。作者提出以任務認領、完成結果唯讀,以及把異議另建修訂任務作為交接契約,避免重複工作和互相覆寫。若任務不需要不同提示詞、工具或信任邊界,多數情況可用單一、提示詞設計良好的智能體處理。

正文

Your two AI agents had one job: research a topic and write a summary. Simple, right?

One agent Googled the company. The other agent also Googled the company. Then the first agent decided the summary was wrong and rewrote it. The second agent disagreed and rewrote it back. Twenty-seven API calls later, you had a $3 bill and a summary worse than what ChatGPT gives you for free.

Welcome to multi-agent coordination — the feature nobody warns you about when they show you that slick demo.

The Problem Nobody Talks About

Here's the dirty secret of multi-agent systems: two agents working together are often worse than one agent working alone.

Not because the individual agents are bad. Because nobody told them how to not step on each other's toes.

Think of it like a group project in college. Five smart people, zero coordination, one Google Doc with seventeen conflicting edits at 11:59 PM. Sound familiar?

Multi-agent AI systems fail the exact same way. Agent A fetches data. Agent B fetches the same data (because nobody told it Agent A already did). Agent A formats a response. Agent B reformats it differently. They loop, they duplicate, they contradict — and your token bill climbs while quality drops.

Why "Just Add Another Agent" Is a Trap

The pitch is seductive: "Need research AND writing? Add a researcher agent and a writer agent!"

But here's what actually happens without coordination:

# What you expected
researcher_result = researcher.run("Find Q3 revenue for Acme Corp")
writer_result = writer.run(f"Summarize this: {researcher_result}")

# What actually happens
researcher_result = researcher.run("Find Q3 revenue for Acme Corp")
# Writer ignores researcher_result, runs its own search
# Researcher sees writer's draft, decides it's wrong, re-researches
# Loop until max_iterations or your wallet gives up

The fix isn't removing agents. It's adding something dumber than AI: a contract.

Contracts Beat Intelligence

The counterintuitive truth: the best multi-agent systems aren't the ones with the smartest agents. They're the ones with the strictest handoff rules.

Here's a minimal coordination contract that stops 80% of multi-agent chaos:

class AgentContract:
    def __init__(self):
        self.completed_tasks = {}
        self.ownership = {}

    def claim_task(self, agent_id: str, task: str) -> bool:
        """Only one agent can own a task. No duplicates."""
        if task in self.ownership:
            return False  # Already claimed
        self.ownership[task] = agent_id
        return True

    def submit_result(self, agent_id: str, task: str, result: str):
        """Once submitted, it's done. No rewrites by other agents."""
        if self.ownership.get(task) != agent_id:
            raise ValueError(f"{agent_id} doesn't own '{task}'")
        self.completed_tasks[task] = result
        return True

    def get_result(self, task: str) -> str:
        """Read-only access to completed work."""
        return self.completed_tasks.get(task, None)

No machine learning. No embeddings. No vector databases. Just a dictionary that says "this task belongs to this agent, and once it's done, it's done."

The Three Rules That Fix Multi-Agent Chaos

After watching dozens of multi-agent setups spiral, here's what actually works:

Rule 1: Claim before you work. Every agent must call claim_task() before starting. If someone else claimed it, you skip it. Zero duplication.

Rule 2: One writer, many readers. The agent that claims a task is the only one that writes the result. Everyone else gets read-only access via get_result(). No conflicting edits.

Rule 3: Disagree forward, never backward. If Agent B thinks Agent A's result is wrong, it doesn't rewrite it. It creates a new task — "revision_of_research" — claims it, and writes its improved version. The audit trail stays clean, and you can actually debug what happened.

contract = AgentContract()

# Researcher claims and completes research
contract.claim_task("researcher", "find_q3_revenue")
data = researcher.run("Find Q3 revenue for Acme Corp")
contract.submit_result("researcher", "find_q3_revenue", data)

# Writer reads research (read-only), claims writing
research = contract.get_result("find_q3_revenue")
contract.claim_task("writer", "write_summary")
summary = writer.run(f"Summarize: {research}")
contract.submit_result("writer", "write_summary", summary)

# If writer disagrees with research, it files a NEW task
contract.claim_task("writer", "research_revision_request")
contract.submit_result("writer", "research_revision_request",
    "Q3 revenue figure seems outdated — please re-check")

The Uncomfortable Truth

Most teams don't need multi-agent systems at all. A single well-prompted agent with good tools beats two agents arguing in a loop every single time for 90% of use cases.

Multi-agent coordination is worth it when — and only when — you genuinely have tasks that benefit from different system prompts, different tool sets, or different trust boundaries. If your "researcher" and "writer" could be the same agent with two different function calls, you don't have a multi-agent problem. You have a single agent with a task list.

The agents aren't the hard part. The coordination is. And the best coordination looks a lot less like AI and a lot more like boring software engineering.


Have you shipped a multi-agent system that actually stayed coordinated in production? What handoff pattern saved you? Drop your setup in the comments — I'm especially curious about the agent count and whether contracts or message queues worked better for you.

來源:DEV Community · dev.to