pi
pi
The pi worker exposes the Pi coding-agent API as iii functions. One pi::run
call executes one headless Pi turn — the same in-process agent loop Pi runs in
the terminal, with the same tools (read, bash, edit, write) — in a chosen
working directory, and returns the final result, token usage, and cost. Every
event Pi emits is published untouched on pi::on-raw-event; a translated
AgentEvent view is published on pi::on-agent-event, which is what the iii
console and the acp worker render. Observe either with args { session_id }
(iii.observe({ function_id: 'pi::on-agent-event', args: { session_id }, capture: ['output'] }, target);
the target receives each frame at payload.output);
frames are live only (not stored or replayed), ordered by (epoch, seq).
Pi runs the loop in-process (no CLI subprocess), so it needs model credentials
in the worker environment (e.g. ANTHROPIC_API_KEY) or an existing Pi login.
When a turn needs a capability beyond Pi itself, add another iii worker to the
bus instead of bolting anything onto this one.