How to redirect, queue, stop or question an agent while it works, and how tools and extensions can feed it context. Each entry says when the input lands, what happens to running tools, and whether you can see it afterwards. Columns show each harness's main surface first, then its other surfaces.
| You want to | piterminal | piRPC and SDK |
|---|---|---|
| Change direction mid-turn | TUI: type and press Enter while the agent is working Lands before the next model call; lets running tools finish; kept in the transcript. Calls prompt(text,{streamingBehavior:"steer"}); extension commands run immediately instead. Waits until the current response and its tool calls finish; pending items show as "Steering: ...". steeringMode setting is one-at-a-time by default. During compaction, input is held in a local queue and sent afterwards. Extension pi.sendUserMessage(content, {deliverAs}) Timing depends on the situation; lets running tools finish; kept in the transcript. Goes through prompt(): starts a run when idle; while streaming, deliverAs steer or followUp is required. Template expansion is off by default. | RPC steer command, or prompt with streamingBehavior:"steer"; SDK session.steer() Lands before the next model call; lets running tools finish; kept in the transcript. Injected after the current assistant turn has finished ALL its tool calls, before the next LLM call; remaining tools are not skipped. One per completed turn by default; set_steering_mode "all" delivers all at once. prompt sent while streaming with no streamingBehavior is rejected. No idle guard: sent while idle it is injected at the start of the next run. Input handlers and skill/template expansion apply; extension commands are rejected. Extension pi.sendUserMessage(content, {deliverAs}) Timing depends on the situation; lets running tools finish; kept in the transcript. Goes through prompt(): starts a run when idle; while streaming, deliverAs steer or followUp is required. Template expansion is off by default. |
| Queue a follow-up | TUI: Alt+Enter (Ctrl+Q on Windows/WSL), app.message.followUp Waits until the turn ends; lets running tools finish; kept in the transcript. While streaming it queues a follow-up; while idle it behaves like a normal Enter submit. followUpMode setting is one-at-a-time by default. TUI: Alt+Up (Alt+Q on Windows/WSL), app.message.dequeue Takes effect immediately; lets running tools finish; shown on screen only. Clears both queues and puts all queued text back in the editor, where it can be edited or reordered and resent. Does not abort. | RPC follow_up command, or prompt with streamingBehavior:"followUp"; SDK session.followUp() Waits until the turn ends; lets running tools finish; kept in the transcript. Delivered only when the agent would otherwise stop (no more tool calls or steering); another turn then runs. Sent while idle it does not start a run; it waits for the end of the next run. One per completion by default; set_follow_up_mode "all" delivers all at once. |
| Stop it | TUI: Escape (app.interrupt) Takes effect immediately; may stop running tools; skips remaining tool calls; kept in the transcript. While streaming it clears the queues, puts their text back in the editor, then calls session.abort(). Tools receive the AbortSignal (built-in bash kills its process tree); custom tools are interrupted only if they honour it. Sequential mode skips tools after the current one; in parallel mode (default) calls not yet started are skipped and running calls get the signal. If no run is active but a user bash is running, Esc aborts the bash instead. | RPC abort; SDK session.abort() Takes effect immediately; may stop running tools; skips remaining tool calls; kept in the transcript. Fires the run's AbortSignal and waits for idle; also cancels retry, compaction and branch summary. Tools receive the AbortSignal (built-in bash kills its process tree); custom tools are interrupted only if they honour it. Sequential mode skips tools after the current one; in parallel mode (default) calls not yet started are skipped and running calls get the signal. Partial assistant message is kept with stopReason "aborted"; agent_settled reports aborted:true. Does NOT clear the queues; send clear_queue first. RPC clear_queue; SDK session.clearQueue() Takes effect immediately; lets running tools finish; shown on screen only. Removes all queued steering and follow-up messages and returns their text; emits queue_update. |
| Ask a side question | Not supported | Not supported |
| Feed it context (hooks, extensions, APIs) | TUI: !cmd (in context) / !!cmd (excluded from context) Timing depends on the situation; lets running tools finish; kept in the transcript. Handled before the streaming check, so it works mid-run. Output is held until the run ends, then reaches the model on the next prompt. !! is stored but excluded from model context. Extension pi.sendMessage(customMsg, {deliverAs:"steer"|"followUp"}) while streaming Lands before the next model call; lets running tools finish; kept in the transcript. Custom message goes into the agent's steer queue (default) or follow-up queue; followUp waits until the agent would stop. Reaches the model as a user-role message; `display` controls rendering. Extension pi.sendMessage(..., {triggerTurn:false}) while streaming Lands at a safe point; lets running tools finish; kept in the transcript. Appended at turn_end after the turn's tool results, so it never lands between a tool call and its result. Does not trigger a turn by itself. Extension pi.sendMessage(..., {triggerTurn:true}) while idle Takes effect immediately; lets running tools finish; kept in the transcript. Starts a new run with the custom message as its starting message; before_agent_start sees messageType "custom". Without triggerTurn, an idle message is only appended. Extension pi.sendMessage(..., {deliverAs:"nextTurn"}) Timing depends on the situation; lets running tools finish; kept in the transcript. Held until the next run starts, then injected next to that run's starting message. Extension before_agent_start handler returning message or system prompt changes Arrives when its event fires; lets running tools finish; kept in the transcript. Fires once per run before the first request; the returned custom message is added after the starting message. Returning systemPrompt replaces the prompt for that run only. Extension context / context_with_system handler Lands before the next model call; lets running tools finish; hidden from you. Runs before every LLM call on a structuredClone of the messages; the change applies to that request only and is not written to the session. Allowed values have no "request" persistence; "turn" is the closest. Extension turn_end handler returning entries and/or continue:true Arrives when its event fires; lets running tools finish; kept in the transcript. Draft entries (custom, custom_message, context_edit, compaction) are committed after the turn's tool results. continue:true guarantees exactly one more provider request; rejected if there is no runnable context. Extension agent_before_settle handler returning entries and/or continue:true Arrives when its event fires; lets running tools finish; kept in the transcript. Last point an extension can act before the run settles: add entries and ask for one continuation. Ignored if an abort happened during the boundary; queued messages also cause a continuation. Extension input handler (transform/handled) Takes effect immediately; lets running tools finish; kept in the transcript. Can rewrite or consume any prompt, steer or follow-up before it is queued (streamingBehavior is exposed). "handled" consumes the input; RPC reports disposition "handled". | RPC bash command (with excludeFromContext); SDK executeBash/recordBashResult Timing depends on the situation; lets running tools finish; kept in the transcript. Runs immediately; output is stored as a bashExecution message and becomes a user-role message on the next prompt. While streaming, the message is held until the run ends. excludeFromContext keeps it out of model context; stop it with abort_bash. Extension pi.sendMessage(customMsg, {deliverAs:"steer"|"followUp"}) while streaming Lands before the next model call; lets running tools finish; kept in the transcript. Custom message goes into the agent's steer queue (default) or follow-up queue; followUp waits until the agent would stop. Reaches the model as a user-role message; `display` controls rendering. Extension pi.sendMessage(..., {triggerTurn:false}) while streaming Lands at a safe point; lets running tools finish; kept in the transcript. Appended at turn_end after the turn's tool results, so it never lands between a tool call and its result. Does not trigger a turn by itself. Extension pi.sendMessage(..., {triggerTurn:true}) while idle Takes effect immediately; lets running tools finish; kept in the transcript. Starts a new run with the custom message as its starting message; before_agent_start sees messageType "custom". Without triggerTurn, an idle message is only appended. Extension pi.sendMessage(..., {deliverAs:"nextTurn"}) Timing depends on the situation; lets running tools finish; kept in the transcript. Held until the next run starts, then injected next to that run's starting message. Extension before_agent_start handler returning message or system prompt changes Arrives when its event fires; lets running tools finish; kept in the transcript. Fires once per run before the first request; the returned custom message is added after the starting message. Returning systemPrompt replaces the prompt for that run only. Extension context / context_with_system handler Lands before the next model call; lets running tools finish; hidden from you. Runs before every LLM call on a structuredClone of the messages; the change applies to that request only and is not written to the session. Allowed values have no "request" persistence; "turn" is the closest. Extension turn_end handler returning entries and/or continue:true Arrives when its event fires; lets running tools finish; kept in the transcript. Draft entries (custom, custom_message, context_edit, compaction) are committed after the turn's tool results. continue:true guarantees exactly one more provider request; rejected if there is no runnable context. Extension agent_before_settle handler returning entries and/or continue:true Arrives when its event fires; lets running tools finish; kept in the transcript. Last point an extension can act before the run settles: add entries and ask for one continuation. Ignored if an abort happened during the boundary; queued messages also cause a continuation. Extension input handler (transform/handled) Takes effect immediately; lets running tools finish; kept in the transcript. Can rewrite or consume any prompt, steer or follow-up before it is queued (streamingBehavior is exposed). "handled" consumes the input; RPC reports disposition "handled". |
Sources
pi, terminal
- pi source: packages/coding-agent/docs/usage.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/modes/interactive/interactive-mode.ts, Source code, checked 2026-10-15
- pi source: packages/coding-agent/docs/keybindings.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/docs/settings.md, Documentation, checked 2026-10-15
- pi source: packages/agent/src/agent-loop.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/docs/how-pi-works.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/core/agent-session.ts, Source code, checked 2026-10-15
- pi source: packages/coding-agent/src/core/messages.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/src/core/extensions/types.ts, Source code, checked 2026-10-15
- pi source: packages/coding-agent/docs/extensions.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/core/extensions/runner.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/docs/rpc-commands.md, Documentation, checked 2026-10-15
pi, RPC and SDK
- pi source: packages/coding-agent/docs/rpc-commands.md, Documentation, checked 2026-10-15
- pi source: packages/agent/src/agent-loop.ts, Source code, checked 2026-10-14
- pi source: packages/agent/README.md, Documentation, checked 2026-10-14
- pi source: packages/agent/src/agent.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/src/core/agent-session.ts, Source code, checked 2026-10-15
- pi source: packages/coding-agent/docs/sdk.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/core/tools/bash.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/docs/json.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/core/messages.ts, Source code, checked 2026-10-14
- pi source: packages/coding-agent/src/core/extensions/types.ts, Source code, checked 2026-10-15
- pi source: packages/coding-agent/docs/extensions.md, Documentation, checked 2026-10-15
- pi source: packages/coding-agent/src/core/extensions/runner.ts, Source code, checked 2026-10-14