pub async fn kernel_agent_loop(
pid: Pid,
cancel: CancellationToken,
inbox: Receiver<KernelMessage>,
a2a: Arc<A2ARouter>,
cron: Arc<CronService>,
process_table: Arc<ProcessTable>,
tool_registry: Option<Arc<ToolRegistry>>,
chain: Option<Arc<ChainManager>>,
gate: Option<Arc<dyn GateBackend>>,
) -> i32Expand description
Run the built-in kernel agent work loop.
The agent:
- Receives messages from its A2ARouter inbox
- Processes built-in commands dispatched as JSON
{"cmd": "..."}payloads - Sends responses back via A2ARouter
- Tracks resource usage (messages_sent, tool_calls, cpu_time_ms)
- Supports suspend/resume via
{"cmd":"suspend"}/{"cmd":"resume"} - Enforces gate checks before exec/cron commands (when gate is provided)
- Exits when the cancellation token is triggered
Returns an exit code (0 = normal shutdown).