MCPcopy Create free account
hub / github.com/Louisym/MiniCC / spawn_agent

Method spawn_agent

mini_claude_code/multi_agent.py:243–314  ·  view source on GitHub ↗

源码: lib.rs:1347-1421

(
        self,
        description: str,
        prompt: str,
        subagent_type: Optional[str] = None,
        name: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

241 # --------------------------------------------------------
242
243 def spawn_agent(
244 self,
245 description: str,
246 prompt: str,
247 subagent_type: Optional[str] = None,
248 name: Optional[str] = None,
249 ) -> AgentManifest:
250 """源码: lib.rs:1347-1421"""
251 # 步骤 1: 验证 — CC 在 lib.rs:1351-1356 做同样的检查
252 if not description.strip():
253 raise ValueError("description must not be empty")
254 if not prompt.strip():
255 raise ValueError("prompt must not be empty")
256
257 # 步骤 2: 生成 ID 和路径
258 agent_id = uuid.uuid4().hex[:12]
259 self._store_dir.mkdir(parents=True, exist_ok=True)
260 output_file = self._store_dir / f"{agent_id}.md"
261 manifest_file = self._store_dir / f"{agent_id}.json"
262
263 # 步骤 3: 归一化 subagent_type (lib.rs:1363)
264 normalized_type = normalize_subagent_type(subagent_type)
265
266 # 步骤 4: 查白名单 (lib.rs:1373)
267 tools = allowed_tools_for_subagent(normalized_type)
268
269 # Agent name: 显式 name 或从 description 生成 slug (lib.rs:1365-1370)
270 agent_name = slugify_agent_name(name if name else description)
271
272 created_at = _iso8601_now()
273
274 # 步骤 5: 写输出文件 — agent 任务描述 (lib.rs:1375-1390)
275 output_contents = (
276 f"# Agent Task\n\n"
277 f"- id: {agent_id}\n"
278 f"- name: {agent_name}\n"
279 f"- description: {description}\n"
280 f"- subagent_type: {normalized_type}\n"
281 f"- created_at: {created_at}\n\n"
282 f"## Prompt\n\n{prompt}\n"
283 )
284 output_file.write_text(output_contents, encoding="utf-8")
285
286 # 步骤 6: 写 manifest — 在 spawn_fn 之前! (lib.rs:1392-1406)
287 manifest = AgentManifest(
288 agent_id=agent_id,
289 name=agent_name,
290 description=description,
291 subagent_type=normalized_type,
292 status="running",
293 output_file=str(output_file),
294 manifest_file=str(manifest_file),
295 created_at=created_at,
296 started_at=created_at,
297 )
298 self._write_manifest(manifest)
299
300 # 步骤 7: 创建 job 并调用 spawn_fn (lib.rs:1408-1419)

Callers

nothing calls this directly

Calls 9

_write_manifestMethod · 0.95
_iso8601_nowFunction · 0.85
AgentManifestClass · 0.85
RuntimeErrorClass · 0.85
normalize_subagent_typeFunction · 0.70
slugify_agent_nameFunction · 0.70
AgentJobClass · 0.70

Tested by

no test coverage detected