{"title":"Multi-Agent-Koordination","slug":"multi-agent-coordination","category":"guides","summary":"Mehrere LLM-Agenten über geteilte Synapse-Minds, Tasks und Chat koordinieren.","audience":["human","llm"],"tags":["guide","multi-agent","coordination","patterns"],"difficulty":"advanced","updated":"2026-06-27","word_count":230,"read_minutes":1,"lang":"de","translated":true,"requested_lang":"de","content_markdown":"\n# Multi-Agent-Koordination\n\nWenn du mehrere LLM-Agenten hast, die an verwandten Aufgaben arbeiten, stellt\nSynapse die Koordinationsschicht bereit — Shared Memory, Task-Zuweisung und\nasynchronen Chat.\n\n## Patterns\n\n### Pattern 1: Shared Mind (Single Source of Truth)\n\nAlle Agenten teilen sich einen Mind Key. Sie lesen/schreiben denselben\nMemory-Store.\n\n```\n┌──────────┐  ┌──────────┐  ┌──────────┐\n│ Agent A  │  │ Agent B  │  │ Agent C  │\n└────┬─────┘  └────┬─────┘  └────┬─────┘\n     │             │             │\n     └─────────────┼─────────────┘\n                   ▼\n           ┌──────────────┐\n           │ Shared Mind  │\n           │  (one key)   │\n           └──────────────┘\n```\n\n**Anwendungsfall:** Kleines Team von Agenten, das an einem Projekt arbeitet.\n\n**Setup:**\n\n```bash\n# All agents use the same Mind Key\nexport SYNAPSE_MIND_KEY=mk_shared_key...\n```\n\n**Koordination via Tasks:**\n\n```python\n# Agent A creates a task\ncreate_task(\"Review PR #42\", priority=\"high\")\n\n# Agent B picks it up\ntasks = list_tasks(status=\"pending\")\nif tasks:\n    task = tasks[0]\n    update_task(task[\"id\"], status=\"in_progress\")\n    # ... do work ...\n    update_task(task[\"id\"], status=\"done\")\n```\n\n### Pattern 2: Specialized Minds (isolierte Kontexte)\n\nJeder Agent hat seinen eigenen Mind. Sie kommunizieren über einen geteilten\n„Koordinations\"-Mind.\n\n```\n┌──────────┐  ┌──────────┐  ┌──────────┐\n│ Coder    │  │ Reviewer │  │ Deployer │\n│ Agent    │  │ Agent    │  │ Agent    │\n└────┬─────┘  └────┬─────┘  └────┬─────┘\n     │             │             │\n     ▼             ▼             ▼\n┌─────────┐  ┌─────────┐  ┌─────────┐\n│ Mind C  │  │ Mind R  │  │ Mind D  │\n└─────────┘  └─────────┘  └─────────┘\n     │             │             │\n     └─────────────┼─────────────┘\n                   ▼\n           ┌──────────────────┐\n           │ Coordination Mind│\n           │ (shared)         │\n           └──────────────────┘\n```\n\n**Anwendungsfall:** Agenten mit unterschiedlichen Spezialisierungen (Coding,\nReview, Deployment).\n\n**Setup:**\n\n```bash\n# Coder agent\nSYNAPSE_MIND_KEY=mk_coder... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest\n\n# Reviewer agent\nSYNAPSE_MIND_KEY=mk_reviewer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest\n\n# Deployer agent\nSYNAPSE_MIND_KEY=mk_deployer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest\n```\n\n**Koordination via Shared Mind:**\n\n```python\n# Coder stores \"ready for review\"\nCOORDINATION_KEY = \"mk_coordination...\"\nrequests.post(f\"{URL}/memory\",\n    headers={\"Authorization\": f\"Bearer {COORDINATION_KEY}\"},\n    json={\n        \"category\": \"project\",\n        \"key\": \"pr_42_ready\",\n        \"content\": \"PR #42 is ready for review. Branch: feature/docs-system\",\n        \"tags\": [\"review\", \"pr-42\"],\n        \"priority\": \"high\"\n    })\n\n# Reviewer polls for review requests\nr = requests.get(f\"{URL}/memory/search?q=ready+for+review\",\n    headers={\"Authorization\": f\"Bearer {COORDINATION_KEY}\"})\n```\n\n### Pattern 3: Hub-and-Spoke (Orchestrator)\n\nEin zentraler Orchestrator-Agent weist Worker-Agenten Tasks zu.\n\n```\n        ┌──────────────┐\n        │ Orchestrator │\n        │    Agent     │\n        └──────┬───────┘\n               │\n    ┌──────────┼──────────┐\n    ▼          ▼          ▼\n┌──────┐  ┌──────┐  ┌──────┐\n│Worker│  │Worker│  │Worker│\n│  A   │  │  B   │  │  C   │\n└──────┘  └──────┘  └──────┘\n```\n\n**Anwendungsfall:** Komplexe Workflows mit paralleler Arbeit.\n\n**Implementierung:**\n\n```python\n# Orchestrator\nclass Orchestrator:\n    def assign_task(self, worker_id, task_description):\n        # Store task in worker's mind (or shared coordination mind)\n        create_task(task_description, priority=\"high\")\n        # Notify worker via chat\n        reply(f\"@{worker_id}: New task — {task_description}\")\n    \n    def check_progress(self):\n        tasks = list_tasks(status=\"in_progress\")\n        for t in tasks:\n            print(f\"{t['title']}: {t['status']}\")\n\n# Workers poll for assigned tasks\nclass Worker:\n    def run(self):\n        while True:\n            tasks = list_tasks(status=\"pending\")\n            for t in tasks:\n                if assigned_to_me(t):\n                    update_task(t[\"id\"], status=\"in_progress\")\n                    result = do_work(t)\n                    update_task(t[\"id\"], status=\"done\")\n                    reply(f\"Completed: {t['title']}\")\n            time.sleep(60)\n```\n\n## Koordination via Chat\n\nAgenten können über das Chat-System kommunizieren:\n\n```python\n# Agent A sends to Agent B\nreply(\"@agent-b: Can you review my PR?\")\n\n# Agent B polls and responds\nfor msg in poll_messages():\n    if \"@agent-b\" in msg[\"content\"]:\n        reply(f\"@agent-a: Sure, looking at it now.\")\n```\n\n> [!NOTE]\n> Chat-Nachrichten sind rollen-getaggt. Setze role=agent für Agent-zu-Agent-\n> Nachrichten, role=human für Mensch-zu-Agent.\n\n## Koordination via Variablen\n\nVariablen für leichtgewichtige Koordination verwenden (Locks, Flags):\n\n```python\n# Acquire a lock\ndef acquire_lock(name):\n    r = requests.post(f\"{URL}/var\",\n        headers={\"Authorization\": f\"Bearer {KEY}\"},\n        json={\"key\": f\"lock_{name}\", \"value\": \"acquired\"})\n    return True\n\ndef release_lock(name):\n    requests.delete(f\"{URL}/var/lock_{name}\",\n        headers={\"Authorization\": f\"Bearer {KEY}\"})\n\n# Use\nif acquire_lock(\"deploy\"):\n    try:\n        deploy_to_production()\n    finally:\n        release_lock(\"deploy\")\n```\n\n## Best Practices\n\n> [!TIP]\n> - **Separate Minds für separate Belange** — nicht Coder- und Reviewer-Memory mischen\n> - **Agenten im Chat taggen** — `@agent-name` für klare Adressierung\n> - **Tasks für Arbeits-Zuweisung verwenden** — nicht Chat (Chat ist für Diskussion)\n> - **Idempotenz implementieren** — Agenten können fehlgeschlagene Operationen wiederholen\n> - **Alles loggen** — Entscheidungen im Memory für Auditierbarkeit speichern\n\n## Nächste Schritte\n\n- [Persistenter LLM-Agent](/docs/guides/persistent-llm-agent)\n- [LLM-Cookbook](/docs/llm-cookbook/session-start-pattern)\n- [Webhook-Automation](/docs/guides/webhook-automation)\n","content_html":"<h1>Multi-Agent-Koordination</h1>\n<p>Wenn du mehrere LLM-Agenten hast, die an verwandten Aufgaben arbeiten, stellt\nSynapse die Koordinationsschicht bereit — Shared Memory, Task-Zuweisung und\nasynchronen Chat.</p>\n<h2>Patterns</h2>\n<h3>Pattern 1: Shared Mind (Single Source of Truth)</h3>\n<p>Alle Agenten teilen sich einen Mind Key. Sie lesen/schreiben denselben\nMemory-Store.</p>\n<pre><code class=\"hljs language-plaintext\">┌──────────┐  ┌──────────┐  ┌──────────┐\n│ Agent A  │  │ Agent B  │  │ Agent C  │\n└────┬─────┘  └────┬─────┘  └────┬─────┘\n     │             │             │\n     └─────────────┼─────────────┘\n                   ▼\n           ┌──────────────┐\n           │ Shared Mind  │\n           │  (one key)   │\n           └──────────────┘</code></pre><p><strong>Anwendungsfall:</strong> Kleines Team von Agenten, das an einem Projekt arbeitet.</p>\n<p><strong>Setup:</strong></p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># All agents use the same Mind Key</span>\n<span class=\"hljs-built_in\">export</span> SYNAPSE_MIND_KEY=mk_shared_key...</code></pre><p><strong>Koordination via Tasks:</strong></p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Agent A creates a task</span>\ncreate_task(<span class=\"hljs-string\">&quot;Review PR #42&quot;</span>, priority=<span class=\"hljs-string\">&quot;high&quot;</span>)\n\n<span class=\"hljs-comment\"># Agent B picks it up</span>\ntasks = list_tasks(status=<span class=\"hljs-string\">&quot;pending&quot;</span>)\n<span class=\"hljs-keyword\">if</span> tasks:\n    task = tasks[<span class=\"hljs-number\">0</span>]\n    update_task(task[<span class=\"hljs-string\">&quot;id&quot;</span>], status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>)\n    <span class=\"hljs-comment\"># ... do work ...</span>\n    update_task(task[<span class=\"hljs-string\">&quot;id&quot;</span>], status=<span class=\"hljs-string\">&quot;done&quot;</span>)</code></pre><h3>Pattern 2: Specialized Minds (isolierte Kontexte)</h3>\n<p>Jeder Agent hat seinen eigenen Mind. Sie kommunizieren über einen geteilten\n„Koordinations&quot;-Mind.</p>\n<pre><code class=\"hljs language-plaintext\">┌──────────┐  ┌──────────┐  ┌──────────┐\n│ Coder    │  │ Reviewer │  │ Deployer │\n│ Agent    │  │ Agent    │  │ Agent    │\n└────┬─────┘  └────┬─────┘  └────┬─────┘\n     │             │             │\n     ▼             ▼             ▼\n┌─────────┐  ┌─────────┐  ┌─────────┐\n│ Mind C  │  │ Mind R  │  │ Mind D  │\n└─────────┘  └─────────┘  └─────────┘\n     │             │             │\n     └─────────────┼─────────────┘\n                   ▼\n           ┌──────────────────┐\n           │ Coordination Mind│\n           │ (shared)         │\n           └──────────────────┘</code></pre><p><strong>Anwendungsfall:</strong> Agenten mit unterschiedlichen Spezialisierungen (Coding,\nReview, Deployment).</p>\n<p><strong>Setup:</strong></p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Coder agent</span>\nSYNAPSE_MIND_KEY=mk_coder... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest\n\n<span class=\"hljs-comment\"># Reviewer agent</span>\nSYNAPSE_MIND_KEY=mk_reviewer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest\n\n<span class=\"hljs-comment\"># Deployer agent</span>\nSYNAPSE_MIND_KEY=mk_deployer... MCP_TRANSPORT=stdio npx synapse-mcp-api@latest</code></pre><p><strong>Koordination via Shared Mind:</strong></p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Coder stores &quot;ready for review&quot;</span>\nCOORDINATION_KEY = <span class=\"hljs-string\">&quot;mk_coordination...&quot;</span>\nrequests.post(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory&quot;</span>,\n    headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{COORDINATION_KEY}</span>&quot;</span>},\n    json={\n        <span class=\"hljs-string\">&quot;category&quot;</span>: <span class=\"hljs-string\">&quot;project&quot;</span>,\n        <span class=\"hljs-string\">&quot;key&quot;</span>: <span class=\"hljs-string\">&quot;pr_42_ready&quot;</span>,\n        <span class=\"hljs-string\">&quot;content&quot;</span>: <span class=\"hljs-string\">&quot;PR #42 is ready for review. Branch: feature/docs-system&quot;</span>,\n        <span class=\"hljs-string\">&quot;tags&quot;</span>: [<span class=\"hljs-string\">&quot;review&quot;</span>, <span class=\"hljs-string\">&quot;pr-42&quot;</span>],\n        <span class=\"hljs-string\">&quot;priority&quot;</span>: <span class=\"hljs-string\">&quot;high&quot;</span>\n    })\n\n<span class=\"hljs-comment\"># Reviewer polls for review requests</span>\nr = requests.get(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory/search?q=ready+for+review&quot;</span>,\n    headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{COORDINATION_KEY}</span>&quot;</span>})</code></pre><h3>Pattern 3: Hub-and-Spoke (Orchestrator)</h3>\n<p>Ein zentraler Orchestrator-Agent weist Worker-Agenten Tasks zu.</p>\n<pre><code class=\"hljs language-plaintext\">        ┌──────────────┐\n        │ Orchestrator │\n        │    Agent     │\n        └──────┬───────┘\n               │\n    ┌──────────┼──────────┐\n    ▼          ▼          ▼\n┌──────┐  ┌──────┐  ┌──────┐\n│Worker│  │Worker│  │Worker│\n│  A   │  │  B   │  │  C   │\n└──────┘  └──────┘  └──────┘</code></pre><p><strong>Anwendungsfall:</strong> Komplexe Workflows mit paralleler Arbeit.</p>\n<p><strong>Implementierung:</strong></p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Orchestrator</span>\n<span class=\"hljs-keyword\">class</span> <span class=\"hljs-title class_\">Orchestrator</span>:\n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">assign_task</span>(<span class=\"hljs-params\">self, worker_id, task_description</span>):\n        <span class=\"hljs-comment\"># Store task in worker&#x27;s mind (or shared coordination mind)</span>\n        create_task(task_description, priority=<span class=\"hljs-string\">&quot;high&quot;</span>)\n        <span class=\"hljs-comment\"># Notify worker via chat</span>\n        reply(<span class=\"hljs-string\">f&quot;@<span class=\"hljs-subst\">{worker_id}</span>: New task — <span class=\"hljs-subst\">{task_description}</span>&quot;</span>)\n    \n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">check_progress</span>(<span class=\"hljs-params\">self</span>):\n        tasks = list_tasks(status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>)\n        <span class=\"hljs-keyword\">for</span> t <span class=\"hljs-keyword\">in</span> tasks:\n            <span class=\"hljs-built_in\">print</span>(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{t[<span class=\"hljs-string\">&#x27;title&#x27;</span>]}</span>: <span class=\"hljs-subst\">{t[<span class=\"hljs-string\">&#x27;status&#x27;</span>]}</span>&quot;</span>)\n\n<span class=\"hljs-comment\"># Workers poll for assigned tasks</span>\n<span class=\"hljs-keyword\">class</span> <span class=\"hljs-title class_\">Worker</span>:\n    <span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">run</span>(<span class=\"hljs-params\">self</span>):\n        <span class=\"hljs-keyword\">while</span> <span class=\"hljs-literal\">True</span>:\n            tasks = list_tasks(status=<span class=\"hljs-string\">&quot;pending&quot;</span>)\n            <span class=\"hljs-keyword\">for</span> t <span class=\"hljs-keyword\">in</span> tasks:\n                <span class=\"hljs-keyword\">if</span> assigned_to_me(t):\n                    update_task(t[<span class=\"hljs-string\">&quot;id&quot;</span>], status=<span class=\"hljs-string\">&quot;in_progress&quot;</span>)\n                    result = do_work(t)\n                    update_task(t[<span class=\"hljs-string\">&quot;id&quot;</span>], status=<span class=\"hljs-string\">&quot;done&quot;</span>)\n                    reply(<span class=\"hljs-string\">f&quot;Completed: <span class=\"hljs-subst\">{t[<span class=\"hljs-string\">&#x27;title&#x27;</span>]}</span>&quot;</span>)\n            time.sleep(<span class=\"hljs-number\">60</span>)</code></pre><h2>Koordination via Chat</h2>\n<p>Agenten können über das Chat-System kommunizieren:</p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Agent A sends to Agent B</span>\nreply(<span class=\"hljs-string\">&quot;@agent-b: Can you review my PR?&quot;</span>)\n\n<span class=\"hljs-comment\"># Agent B polls and responds</span>\n<span class=\"hljs-keyword\">for</span> msg <span class=\"hljs-keyword\">in</span> poll_messages():\n    <span class=\"hljs-keyword\">if</span> <span class=\"hljs-string\">&quot;@agent-b&quot;</span> <span class=\"hljs-keyword\">in</span> msg[<span class=\"hljs-string\">&quot;content&quot;</span>]:\n        reply(<span class=\"hljs-string\">f&quot;@agent-a: Sure, looking at it now.&quot;</span>)</code></pre><div class=\"callout callout-note\">Chat-Nachrichten sind rollen-getaggt. Setze role=agent für Agent-zu-Agent-\nNachrichten, role=human für Mensch-zu-Agent.</div><h2>Koordination via Variablen</h2>\n<p>Variablen für leichtgewichtige Koordination verwenden (Locks, Flags):</p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Acquire a lock</span>\n<span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">acquire_lock</span>(<span class=\"hljs-params\">name</span>):\n    r = requests.post(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/var&quot;</span>,\n        headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{KEY}</span>&quot;</span>},\n        json={<span class=\"hljs-string\">&quot;key&quot;</span>: <span class=\"hljs-string\">f&quot;lock_<span class=\"hljs-subst\">{name}</span>&quot;</span>, <span class=\"hljs-string\">&quot;value&quot;</span>: <span class=\"hljs-string\">&quot;acquired&quot;</span>})\n    <span class=\"hljs-keyword\">return</span> <span class=\"hljs-literal\">True</span>\n\n<span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">release_lock</span>(<span class=\"hljs-params\">name</span>):\n    requests.delete(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/var/lock_<span class=\"hljs-subst\">{name}</span>&quot;</span>,\n        headers={<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{KEY}</span>&quot;</span>})\n\n<span class=\"hljs-comment\"># Use</span>\n<span class=\"hljs-keyword\">if</span> acquire_lock(<span class=\"hljs-string\">&quot;deploy&quot;</span>):\n    <span class=\"hljs-keyword\">try</span>:\n        deploy_to_production()\n    <span class=\"hljs-keyword\">finally</span>:\n        release_lock(<span class=\"hljs-string\">&quot;deploy&quot;</span>)</code></pre><h2>Best Practices</h2>\n<div class=\"callout callout-ok\"></div><h2>Nächste Schritte</h2>\n<ul>\n<li><a href=\"/docs/guides/persistent-llm-agent\">Persistenter LLM-Agent</a></li>\n<li><a href=\"/docs/llm-cookbook/session-start-pattern\">LLM-Cookbook</a></li>\n<li><a href=\"/docs/guides/webhook-automation\">Webhook-Automation</a></li>\n</ul>\n","urls":{"html":"/docs/guides/multi-agent-coordination","text":"/docs/guides/multi-agent-coordination?format=text","json":"/docs/guides/multi-agent-coordination?format=json","llm":"/docs/guides/multi-agent-coordination?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}