{"title":"Multi-Agent Coordination","slug":"multi-agent-coordination","category":"guides","summary":"Coordinate multiple LLM agents using shared Synapse minds, tasks, and chat.","audience":["human","llm"],"tags":["guide","multi-agent","coordination","patterns"],"difficulty":"advanced","updated":"2026-06-27","word_count":246,"read_minutes":1,"lang":"en","translated":true,"requested_lang":"en","content_markdown":"\n# Multi-Agent Coordination\n\nWhen you have multiple LLM agents working on related tasks, Synapse provides\nthe coordination layer — shared memory, task assignment, and async chat.\n\n## Patterns\n\n### Pattern 1: Shared Mind (Single Source of Truth)\n\nAll agents share one Mind Key. They read/write the same memory 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**Use case:** Small team of agents working on one project.\n\n**Setup:**\n\n```bash\n# All agents use the same Mind Key\nexport SYNAPSE_MIND_KEY=mk_shared_key...\n```\n\n**Coordination 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 (Isolated Contexts)\n\nEach agent has its own mind. They communicate via a shared \"coordination\" 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**Use case:** Agents with different specialties (coding, review, 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**Coordination 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\nA central orchestrator agent assigns tasks to worker agents.\n\n```\n        ┌──────────────┐\n        │ Orchestrator │\n        │    Agent     │\n        └──────┬───────┘\n               │\n    ┌──────────┼──────────┐\n    ▼          ▼          ▼\n┌──────┐  ┌──────┐  ┌──────┐\n│Worker│  │Worker│  │Worker│\n│  A   │  │  B   │  │  C   │\n└──────┘  └──────┘  └──────┘\n```\n\n**Use case:** Complex workflows with parallel work.\n\n**Implementation:**\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## Coordination via Chat\n\nAgents can communicate via the chat system:\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 messages are role-tagged. Set role=agent for agent-to-agent messages,\n> role=human for human-to-agent.\n\n## Coordination via Variables\n\nUse variables for lightweight coordination (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> - **Use separate minds for separate concerns** — don't mix coder and reviewer memory\n> - **Tag agents in chat** — `@agent-name` for clear addressing\n> - **Use tasks for work assignment** — not chat (chat is for discussion)\n> - **Implement idempotency** — agents may retry failed operations\n> - **Log everything** — store decisions in memory for auditability\n\n## Next Steps\n\n- [Persistent 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 Coordination</h1>\n<p>When you have multiple LLM agents working on related tasks, Synapse provides\nthe coordination layer — shared memory, task assignment, and async chat.</p>\n<h2>Patterns</h2>\n<h3>Pattern 1: Shared Mind (Single Source of Truth)</h3>\n<p>All agents share one Mind Key. They read/write the same memory 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>Use case:</strong> Small team of agents working on one project.</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>Coordination 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 (Isolated Contexts)</h3>\n<p>Each agent has its own mind. They communicate via a shared &quot;coordination&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>Use case:</strong> Agents with different specialties (coding, review, 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>Coordination 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>A central orchestrator agent assigns tasks to worker agents.</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>Use case:</strong> Complex workflows with parallel work.</p>\n<p><strong>Implementation:</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>Coordination via Chat</h2>\n<p>Agents can communicate via the chat system:</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 messages are role-tagged. Set role=agent for agent-to-agent messages,\nrole=human for human-to-agent.</div><h2>Coordination via Variables</h2>\n<p>Use variables for lightweight coordination (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>Next Steps</h2>\n<ul>\n<li><a href=\"/docs/guides/persistent-llm-agent\">Persistent 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"]}