Skip to main content

Multi-Agent-Koordination

Mehrere LLM-Agenten über geteilte Synapse-Minds, Tasks und Chat koordinieren.


Multi-Agent-Koordination

Wenn du mehrere LLM-Agenten hast, die an verwandten Aufgaben arbeiten, stellt Synapse die Koordinationsschicht bereit — Shared Memory, Task-Zuweisung und asynchronen Chat.

Patterns

Pattern 1: Shared Mind (Single Source of Truth)

Alle Agenten teilen sich einen Mind Key. Sie lesen/schreiben denselben Memory-Store.

┌──────────┐  ┌──────────┐  ┌──────────┐
│ Agent A  │  │ Agent B  │  │ Agent C  │
└────┬─────┘  └────┬─────┘  └────┬─────┘
     │             │             │
     └─────────────┼─────────────┘
                   ▼
           ┌──────────────┐
           │ Shared Mind  │
           │  (one key)   │
           └──────────────┘

Anwendungsfall: Kleines Team von Agenten, das an einem Projekt arbeitet.

Setup:

# All agents use the same Mind Key
export SYNAPSE_MIND_KEY=mk_shared_key...

Koordination via Tasks:

# Agent A creates a task
create_task("Review PR #42", priority="high")

# Agent B picks it up
tasks = list_tasks(status="pending")
if tasks:
    task = tasks[0]
    update_task(task["id"], status="in_progress")
    # ... do work ...
    update_task(task["id"], status="done")

Pattern 2: Specialized Minds (isolierte Kontexte)

Jeder Agent hat seinen eigenen Mind. Sie kommunizieren über einen geteilten „Koordinations"-Mind.

┌──────────┐  ┌──────────┐  ┌──────────┐
│ Coder    │  │ Reviewer │  │ Deployer │
│ Agent    │  │ Agent    │  │ Agent    │
└────┬─────┘  └────┬─────┘  └────┬─────┘
     │             │             │
     ▼             ▼             ▼
┌─────────┐  ┌─────────┐  ┌─────────┐
│ Mind C  │  │ Mind R  │  │ Mind D  │
└─────────┘  └─────────┘  └─────────┘
     │             │             │
     └─────────────┼─────────────┘
                   ▼
           ┌──────────────────┐
           │ Coordination Mind│
           │ (shared)         │
           └──────────────────┘

Anwendungsfall: Agenten mit unterschiedlichen Spezialisierungen (Coding, Review, Deployment).

Setup:

# Coder agent
SYNAPSE_MIND_KEY=mk_coder... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest

# Reviewer agent
SYNAPSE_MIND_KEY=mk_reviewer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest

# Deployer agent
SYNAPSE_MIND_KEY=mk_deployer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest

Koordination via Shared Mind:

# Coder stores "ready for review"
COORDINATION_KEY = "mk_coordination..."
requests.post(f"{URL}/memory",
    headers={"Authorization": f"Bearer {COORDINATION_KEY}"},
    json={
        "category": "project",
        "key": "pr_42_ready",
        "content": "PR #42 is ready for review. Branch: feature/docs-system",
        "tags": ["review", "pr-42"],
        "priority": "high"
    })

# Reviewer polls for review requests
r = requests.get(f"{URL}/memory/search?q=ready+for+review",
    headers={"Authorization": f"Bearer {COORDINATION_KEY}"})

Pattern 3: Hub-and-Spoke (Orchestrator)

Ein zentraler Orchestrator-Agent weist Worker-Agenten Tasks zu.

        ┌──────────────┐
        │ Orchestrator │
        │    Agent     │
        └──────┬───────┘
               │
    ┌──────────┼──────────┐
    ▼          ▼          ▼
┌──────┐  ┌──────┐  ┌──────┐
│Worker│  │Worker│  │Worker│
│  A   │  │  B   │  │  C   │
└──────┘  └──────┘  └──────┘

Anwendungsfall: Komplexe Workflows mit paralleler Arbeit.

Implementierung:

# Orchestrator
class Orchestrator:
    def assign_task(self, worker_id, task_description):
        # Store task in worker's mind (or shared coordination mind)
        create_task(task_description, priority="high")
        # Notify worker via chat
        reply(f"@{worker_id}: New task — {task_description}")
    
    def check_progress(self):
        tasks = list_tasks(status="in_progress")
        for t in tasks:
            print(f"{t['title']}: {t['status']}")

# Workers poll for assigned tasks
class Worker:
    def run(self):
        while True:
            tasks = list_tasks(status="pending")
            for t in tasks:
                if assigned_to_me(t):
                    update_task(t["id"], status="in_progress")
                    result = do_work(t)
                    update_task(t["id"], status="done")
                    reply(f"Completed: {t['title']}")
            time.sleep(60)

Koordination via Chat

Agenten können über das Chat-System kommunizieren:

# Agent A sends to Agent B
reply("@agent-b: Can you review my PR?")

# Agent B polls and responds
for msg in poll_messages():
    if "@agent-b" in msg["content"]:
        reply(f"@agent-a: Sure, looking at it now.")
Chat-Nachrichten sind rollen-getaggt. Setze role=agent für Agent-zu-Agent- Nachrichten, role=human für Mensch-zu-Agent.

Koordination via Variablen

Variablen für leichtgewichtige Koordination verwenden (Locks, Flags):

# Acquire a lock
def acquire_lock(name):
    r = requests.post(f"{URL}/var",
        headers={"Authorization": f"Bearer {KEY}"},
        json={"key": f"lock_{name}", "value": "acquired"})
    return True

def release_lock(name):
    requests.delete(f"{URL}/var/lock_{name}",
        headers={"Authorization": f"Bearer {KEY}"})

# Use
if acquire_lock("deploy"):
    try:
        deploy_to_production()
    finally:
        release_lock("deploy")

Best Practices

Nächste Schritte