MCPcopy
hub / github.com/HKUDS/DeepCode / spawn

Method spawn

nanobot/nanobot/agent/subagent.py:55–90  ·  view source on GitHub ↗

Spawn a subagent to execute a task in the background. Args: task: The task description for the subagent. label: Optional human-readable label for the task. origin_channel: The channel to announce results to. origin_chat_id: The chat I

(
        self,
        task: str,
        label: str | None = None,
        origin_channel: str = "cli",
        origin_chat_id: str = "direct",
    )

Source from the content-addressed store, hash-verified

53 self._running_tasks: dict[str, asyncio.Task[None]] = {}
54
55 async def spawn(
56 self,
57 task: str,
58 label: str | None = None,
59 origin_channel: str = "cli",
60 origin_chat_id: str = "direct",
61 ) -> str:
62 """
63 Spawn a subagent to execute a task in the background.
64
65 Args:
66 task: The task description for the subagent.
67 label: Optional human-readable label for the task.
68 origin_channel: The channel to announce results to.
69 origin_chat_id: The chat ID to announce results to.
70
71 Returns:
72 Status message indicating the subagent was started.
73 """
74 task_id = str(uuid.uuid4())[:8]
75 display_label = label or task[:30] + ("..." if len(task) > 30 else "")
76
77 origin = {
78 "channel": origin_channel,
79 "chat_id": origin_chat_id,
80 }
81
82 # Create background task
83 bg_task = asyncio.create_task(self._run_subagent(task_id, task, display_label, origin))
84 self._running_tasks[task_id] = bg_task
85
86 # Cleanup when done
87 bg_task.add_done_callback(lambda _: self._running_tasks.pop(task_id, None))
88
89 logger.info(f"Spawned subagent [{task_id}]: {display_label}")
90 return f"Subagent [{display_label}] started (id: {task_id}). I'll notify you when it completes."
91
92 async def _run_subagent(
93 self,

Callers 1

executeMethod · 0.80

Calls 2

_run_subagentMethod · 0.95
create_taskMethod · 0.80

Tested by

no test coverage detected