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

Function spawn

src/server/agent_server.py:1297–1327  ·  view source on GitHub ↗
(session_id: str, cwd: str, perm_mode: str | None)

Source from the content-addressed store, hash-verified

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

Callers 4

execFileNoThrowFunction · 0.50
startMethod · 0.50
launchClawcodexCommandFunction · 0.50
_serve_stdioFunction · 0.50

Calls 5

AgentHandleClass · 0.90
_AgentSessionClass · 0.85
_build_runtimeFunction · 0.85
emit_initMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected