feat(agent): put tool execution behind a ToolHost interface (brain/hand split, step 1)

Closed
CO
6h ago
+433-5

Fixes #4360.

Step 1 of separating senpi's brain (the agent loop) from its hands (tool execution), as Q ordered on 2026-10-26: one clean boundary, fusable in one process (the default) and runnable apart later.

  • ToolHost / ToolHostCall (types.ts) and AgentLoopConfig.toolHost (optional).
  • executePreparedToolCall calls toolHost.execute(...) instead of tool.execute(...). The sequential batch, the parallel batch and runToolCall (RunToolCallOptions.toolHost) all pass the host, so no path bypasses it.
  • localToolHost (exported) is the default: it runs tool.execute in-process, so behaviour is byte-identical for every existing caller.
  • The loop keeps name resolution, argument preparation, schema validation, beforeToolCall/afterToolCall, events and abort handling.

Tests: test/tool-host-seam.test.ts, 7 tests. RED: they failed to load, since localToolHost and ToolHost did not exist. GREEN covers:

  • the host receiving the prepared, validated call in both sequential and parallel mode, with its result becoming the tool result message and partial updates reaching tool_execution_update;
  • afterToolCall seeing the host's result;
  • unknown and schema-invalid calls never reaching the host;
  • a throwing host becoming an isError result;
  • runToolCall going through the host;
  • the default being unchanged.

Local: build-all OK; packages/agent 1285 passed / 1 skipped; tsc, oxlint and oxfmt clean; the pre-commit check (incl. the lint ratchet) passed.
Not here: registry publication, an out-of-process hand, the relay hand (later steps of the design).