MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / make_spawn_agent

Function make_spawn_agent

src/server/agent_server.py:1288–1329  ·  view source on GitHub ↗

Build a :data:`SpawnAgent` bound to ``config``. The returned coroutine matches the ``DirectConnectServer.spawn_agent`` contract: ``(session_id, cwd, permission_mode) -> AgentHandle``.

(config: AgentServerConfig | None = None)

Source from the content-addressed store, hash-verified

1286
1287
1288def make_spawn_agent(config: AgentServerConfig | None = None):
1289 """Build a :data:`SpawnAgent` bound to ``config``.
1290
1291 The returned coroutine matches the ``DirectConnectServer.spawn_agent``
1292 contract: ``(session_id, cwd, permission_mode) -> AgentHandle``.
1293 """
1294
1295 cfg = config or AgentServerConfig()
1296
1297 async def spawn(session_id: str, cwd: str, perm_mode: str | None) -> AgentHandle:
1298 loop = asyncio.get_running_loop()
1299 out_queue: asyncio.Queue[dict | None] = asyncio.Queue()
1300 sess = _AgentSession(
1301 session_id=session_id,
1302 cwd=cwd,
1303 config=cfg,
1304 loop=loop,
1305 out_queue=out_queue,
1306 )
1307 # Build the provider/registry/tool_context off the event loop — these
1308 # touch config/filesystem and must not block the WS pump.
1309 await loop.run_in_executor(None, lambda: _build_runtime(sess, perm_mode))
1310 # Wire the permission handler now that tool_context exists.
1311 if sess.tool_context is not None and sess.init_error is None:
1312 sess.tool_context.permission_handler = sess.permission_handler
1313 sess.start()
1314 sess.emit_init()
1315
1316 async def messages_from_agent() -> AsyncIterator[dict]:
1317 while True:
1318 item = await out_queue.get()
1319 if item is None:
1320 return
1321 yield item
1322
1323 return AgentHandle(
1324 send_to_agent=sess.send_to_agent,
1325 messages_from_agent=messages_from_agent,
1326 shutdown=sess.shutdown,
1327 )
1328
1329 return spawn
1330
1331
1332# ─── runtime construction (mirrors entrypoints/headless.py) ───────────────────

Callers 13

_serve_stdioFunction · 0.90
_serveFunction · 0.90
_running_serverFunction · 0.90
test_control_knowledgeFunction · 0.90
test_control_wikiFunction · 0.90
test_control_insightsFunction · 0.90
test_control_planFunction · 0.90

Calls 1

AgentServerConfigClass · 0.85