Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["7225"],{88019(e,n,s){s.r(n),s.d(n,{metadata:()=>t,default:()=>h,frontMatter:()=>d,contentTitle:()=>l,toc:()=>c,assets:()=>a});var t=JSON.parse('{"id":"integrations/sub-agents","title":"Sub-Agents (Multi-Agent Mode)","description":"Mercury isn\'t just a chatbot \u2014 it\'s an orchestrator. It can spawn parallel AI agents to handle tasks concurrently while continuing the conversation. This is sub-agent mode, and it changes how Mercury works fundamentally.","source":"@site/docs/integrations/sub-agents.mdx","sourceDirName":"integrations","slug":"/integrations/sub-agents","permalink":"/docs/integrations/sub-agents","draft":false,"unlisted":false,"editUrl":"https://github.com/cosmicstack-labs/mercury-agent/tree/main/website/docs/integrations/sub-agents.mdx","tags":[],"version":"current","frontMatter":{"id":"sub-agents","title":"Sub-Agents (Multi-Agent Mode)"},"sidebar":"docsSidebar","previous":{"title":"Coding Workspace (IDE Mode)","permalink":"/docs/integrations/coding-workspace"},"next":{"title":"Built-in Tools","permalink":"/docs/reference/built-in-tools"}}'),i=s(74848),r=s(28453);let d={id:"sub-agents",title:"Sub-Agents (Multi-Agent Mode)"},l,a={},c=[{value:"Why Sub-Agents Matter",id:"why-sub-agents-matter",level:2},{value:"How It Works",id:"how-it-works",level:2},{value:"Commands",id:"commands",level:2},{value:"Delegation Tools",id:"delegation-tools",level:2},{value:"Architecture",id:"architecture",level:2},{value:"When Mercury Uses Sub-Agents",id:"when-mercury-uses-sub-agents",level:2},{value:"What Happens While Agents Work",id:"what-happens-while-agents-work",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Programming Mode",id:"programming-mode",level:2},{value:"Programming Mode + Sub-Agents",id:"programming-mode--sub-agents",level:2}];function o(e){let n={admonition:"admonition",code:"code",h2:"h2",li:"li",mdxAdmonitionTitle:"mdxAdmonitionTitle",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["Mercury isn't just a chatbot \u2014 it's an ",(0,i.jsx)(n.strong,{children:"orchestrator"}),". It can spawn parallel AI agents to handle tasks concurrently while continuing the conversation. This is sub-agent mode, and it changes how Mercury works fundamentally."]}),"\n",(0,i.jsx)(n.h2,{id:"why-sub-agents-matter",children:"Why Sub-Agents Matter"}),"\n",(0,i.jsx)(n.p,{children:'Traditional AI agents are single-threaded: one context window, one task at a time. If you ask Mercury to "research this topic, write the code, and review the result," it does them sequentially \u2014 each step blocks the next.'}),"\n",(0,i.jsx)(n.p,{children:"Sub-agents break this bottleneck:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"Parallel execution"})," \u2014 Multiple tasks run simultaneously across isolated context windows"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"LLM-driven delegation"})," \u2014 Mercury itself decides when to delegate based on task complexity"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"Non-blocking"})," \u2014 You can keep chatting with Mercury while sub-agents work in the background"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"File locks"})," \u2014 Reader-writer locks prevent concurrent write conflicts between agents"]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"Resource-aware"})," \u2014 Max concurrent agents is auto-detected from your system's CPU and RAM"]}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"how-it-works",children:"How It Works"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:'You: "Build a REST API for users and write integration tests"\n\nMercury decides to delegate:\n \u{1F916} Multi-agent mode activated.\n **Agent a1** is now working on: "Build REST API endpoints for users"\n **Agent a2** is now working on: "Write integration tests for user endpoints"\n Active agents: 2/4\n\n You can continue chatting while the agents work.\n Use /agents to check status.\n\nMercury: I\'ve delegated both tasks to parallel agents. Agent a1 is building the API\n and agent a2 is writing tests. They\'ll work independently.\n\n (you continue chatting normally)\n\n \u{1F504} Agent a1: Using: read_file, create_file\n \u{1F504} Agent a2: Using: list_dir, read_file\n\n \u2705 **Agent a1** completed (12.3s): "REST API built with 5 endpoints"\n \u2705 **Agent a2** completed (18.7s): "12 integration tests passing"\n\n Both agents are done. Want me to review the results together?\n'})}),"\n",(0,i.jsx)(n.h2,{id:"commands",children:"Commands"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Command"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents"})}),(0,i.jsx)(n.td,{children:"List all sub-agents (running and completed)"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents stop <id|all>"})}),(0,i.jsx)(n.td,{children:"Stop a sub-agent or all sub-agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents pause <id>"})}),(0,i.jsx)(n.td,{children:"Pause a running sub-agent"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents resume <id>"})}),(0,i.jsx)(n.td,{children:"Resume a paused sub-agent"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents config"})}),(0,i.jsx)(n.td,{children:"Show sub-agent resource allocation (max concurrent, mode)"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/agents set max <n>"})}),(0,i.jsx)(n.td,{children:"Set max concurrent sub-agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code agent <task>"})}),(0,i.jsx)(n.td,{children:"Delegate a coding task to a sub-agent immediately"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/bg: <task>"})}),(0,i.jsx)(n.td,{children:"Run a natural-language sub-agent task in background"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/bg current"})}),(0,i.jsx)(n.td,{children:"Move current in-flight task to a background sub-agent"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/bg list"})}),(0,i.jsx)(n.td,{children:"List shell + sub-agent background tasks"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/halt"})}),(0,i.jsx)(n.td,{children:"Emergency: stop every chat's task and halt all sub-agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/stop"})}),(0,i.jsx)(n.td,{children:"Stop this chat's task and the sub-agents it started. When nothing else is running, also release file locks and clear the task board"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/reset"})}),(0,i.jsx)(n.td,{children:"Full reset: stop all + clear conversation context (requires confirmation)"})]})]})]}),"\n",(0,i.jsxs)(n.admonition,{type:"tip",children:[(0,i.jsxs)(n.mdxAdmonitionTitle,{children:[(0,i.jsx)(n.code,{children:"/halt"})," vs ",(0,i.jsx)(n.code,{children:"/stop"})," vs ",(0,i.jsx)(n.code,{children:"/reset"})]}),(0,i.jsxs)(n.p,{children:["Chats run at the same time, so ",(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"/stop"})})," stops only the chat you type it in: its task and the sub-agents it started. When nothing else is running, it also releases file locks and clears the task board. ",(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"/halt"})})," stops every chat's task and all agents, but keeps file locks. ",(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.code,{children:"/reset"})})," clears the conversation context as well (requires confirmation)."]})]}),"\n",(0,i.jsxs)(n.p,{children:["Slash commands like ",(0,i.jsx)(n.code,{children:"/agents"}),", ",(0,i.jsx)(n.code,{children:"/halt"}),", ",(0,i.jsx)(n.code,{children:"/stop"}),", ",(0,i.jsx)(n.code,{children:"/spotify"}),", and ",(0,i.jsx)(n.code,{children:"/code"})," work ",(0,i.jsx)(n.strong,{children:"even while the main agent is busy"})," \u2014 they're processed immediately on a fast path."]}),"\n",(0,i.jsx)(n.h2,{id:"delegation-tools",children:"Delegation Tools"}),"\n",(0,i.jsx)(n.p,{children:"Mercury uses these tools to manage sub-agents:"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Tool"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"delegate_task"})}),(0,i.jsx)(n.td,{children:"Spawn a sub-agent with a task description and optional context"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"list_agents"})}),(0,i.jsx)(n.td,{children:"Show all running and completed sub-agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"stop_agent"})}),(0,i.jsx)(n.td,{children:"Halt a specific running sub-agent by ID"})]})]})]}),"\n",(0,i.jsxs)(n.p,{children:["When Mercury decides a task is complex enough to benefit from parallel execution, it calls ",(0,i.jsx)(n.code,{children:"delegate_task"}),". You'll see a response like:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:"\u{1F916} Multi-agent mode activated.\n\n**Agent a1** is now working on: \"Analyze the codebase structure for...\"\nActive agents: 1/4\n\nYou can continue chatting while the agent works. I'll notify you when it's done.\nUse /agents to check status.\n"})}),"\n",(0,i.jsx)(n.h2,{id:"architecture",children:"Architecture"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:'User message \u2192 Main Agent (orchestrator)\n \u251C\u2500 delegate_task("research X") \u2192 Sub-Agent a1 (isolated context)\n \u251C\u2500 delegate_task("implement Y") \u2192 Sub-Agent a2 (isolated context)\n \u2514\u2500 continues conversation \u2192 responds to user\n \u2502\n a1: "\u{1F504} Using: read_file"\n a1: "\u{1F504} Using: edit_file"\n a2: "\u{1F504} Using: list_dir"\n a1: "\u2705 completed (8.2s)"\n a2: "\u{1F504} Using: create_file"\n a2: "\u2705 completed (15.1s)"\n'})}),"\n",(0,i.jsx)(n.p,{children:"Each sub-agent:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["Has its ",(0,i.jsx)(n.strong,{children:"own context window"})," \u2014 the main agent's conversation doesn't pollute it"]}),"\n",(0,i.jsxs)(n.li,{children:["Runs an independent ",(0,i.jsx)(n.strong,{children:"10-step agentic loop"})," with the same tool access"]}),"\n",(0,i.jsxs)(n.li,{children:["Uses the ",(0,i.jsx)(n.strong,{children:"same permission system"})," \u2014 but with auto-approve for the task's scope"]}),"\n",(0,i.jsxs)(n.li,{children:["Reports progress via the ",(0,i.jsx)(n.strong,{children:"notification channel"})," (CLI or Telegram)"]}),"\n",(0,i.jsxs)(n.li,{children:["Respects ",(0,i.jsx)(n.strong,{children:"file locks"})," \u2014 if a1 is writing a file, a2 waits for the lock"]}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"when-mercury-uses-sub-agents",children:"When Mercury Uses Sub-Agents"}),"\n",(0,i.jsx)(n.p,{children:"Mercury decides to delegate when:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["A task is ",(0,i.jsx)(n.strong,{children:"naturally parallelizable"}),' (e.g., "research X while I code Y")']}),"\n",(0,i.jsxs)(n.li,{children:["The task benefits from an ",(0,i.jsx)(n.strong,{children:"isolated context window"})," (no pollution from the main conversation)"]}),"\n",(0,i.jsxs)(n.li,{children:["A task is ",(0,i.jsx)(n.strong,{children:"complex enough"})," to warrant dedicated focus"]}),"\n",(0,i.jsxs)(n.li,{children:["Multiple ",(0,i.jsx)(n.strong,{children:"independent investigations"})," would save time"]}),"\n"]}),"\n",(0,i.jsx)(n.p,{children:'You can also ask Mercury explicitly: "Use two agents for this" or "Delegate this task."'}),"\n",(0,i.jsx)(n.h2,{id:"what-happens-while-agents-work",children:"What Happens While Agents Work"}),"\n",(0,i.jsx)(n.p,{children:"You can keep chatting normally. Mercury processes your messages as they come in. Sub-agent progress and completion appear as notification messages in your channel:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:'\u{1F504} Agent a1: Starting task...\n\u{1F504} Agent a1: Using: read_file, edit_file\n\u{1F504} Agent a2: Using: fetch_url, create_file\n\u2705 Agent a1 completed (8.2s): "Analyzed the codebase..."\n\u{1F504} Agent a2: Using: run_command\n\u2705 Agent a2 completed (14.5s): "Tests passing..."\n'})}),"\n",(0,i.jsxs)(n.p,{children:["If you send ",(0,i.jsx)(n.code,{children:"/agents"}),", you'll see the full status:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:"**Sub-Agents:**\n\n\u{1F504} a1: Build REST API endpoints \u2014 running (Using: read_file)\n\u23F3 a2: Write integration tests \u2014 pending\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Background-tracked agent tasks also appear in ",(0,i.jsx)(n.code,{children:"/bg list"})," so shell jobs and delegated coding work share one progress surface."]}),"\n",(0,i.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,i.jsxs)(n.p,{children:["Sub-agents are configured in ",(0,i.jsx)(n.code,{children:"~/.mercury/mercury.yaml"}),":"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-yaml",children:'subagents:\n enabled: true\n maxConcurrent: auto # auto-detected from CPU/RAM, or set manually (e.g., 4)\n mode: auto # "auto" (LLM decides) or "manual" (user controls)\n'})}),"\n",(0,i.jsx)(n.p,{children:"Environment variable overrides:"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Variable"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"SUBAGENTS_ENABLED"})}),(0,i.jsx)(n.td,{children:"Enable/disable sub-agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"SUBAGENTS_MAX_CONCURRENT"})}),(0,i.jsx)(n.td,{children:"Max number of concurrent agents"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"SUBAGENTS_MODE"})}),(0,i.jsxs)(n.td,{children:[(0,i.jsx)(n.code,{children:"auto"})," or ",(0,i.jsx)(n.code,{children:"manual"})]})]})]})]}),"\n",(0,i.jsx)(n.h2,{id:"programming-mode",children:"Programming Mode"}),"\n",(0,i.jsx)(n.p,{children:"Sub-agents pair well with Mercury's programming mode for code tasks:"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Command"}),(0,i.jsx)(n.th,{children:"Mode"}),(0,i.jsx)(n.th,{children:"Behavior"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code plan"})}),(0,i.jsx)(n.td,{children:"Plan"}),(0,i.jsx)(n.td,{children:"Analyze without writing code"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code execute"})}),(0,i.jsx)(n.td,{children:"Execute"}),(0,i.jsx)(n.td,{children:"Implement step by step"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code off"})}),(0,i.jsx)(n.td,{children:"Off"}),(0,i.jsx)(n.td,{children:"Normal conversation"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code toggle"})}),(0,i.jsx)(n.td,{children:"\u2014"}),(0,i.jsx)(n.td,{children:"Cycle through modes"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"/code status"})}),(0,i.jsx)(n.td,{children:"\u2014"}),(0,i.jsx)(n.td,{children:"Show current mode"})]})]})]}),"\n",(0,i.jsx)(n.h2,{id:"programming-mode--sub-agents",children:"Programming Mode + Sub-Agents"}),"\n",(0,i.jsxs)(n.p,{children:["When ",(0,i.jsx)(n.code,{children:"/code plan"})," is active, Mercury will analyze a task and present a plan. If the plan involves parallel work, Mercury can delegate parts to sub-agents during ",(0,i.jsx)(n.code,{children:"/code execute"}),". The ",(0,i.jsx)(n.code,{children:"ask_user"})," tool lets Mercury present choices at decision points \u2014 on CLI this is an arrow-key menu, on Telegram it's inline buttons."]})]})}function h(e={}){let{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(o,{...e})}):o(e)}},28453(e,n,s){s.d(n,{R:()=>d,x:()=>l});var t=s(96540);let i={},r=t.createContext(i);function d(e){let n=t.useContext(r);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]);