feat(agent): allow blocked tool calls to terminate (#7715)

Closes #5998
This commit is contained in:
muyiyr 2026-08-06 23:14:48 +08:00 • committed by GitHub
parent 1532c99943
commit 1eb988cfe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 194 additions and 7 deletions

View file

@ -762,7 +762,8 @@ Behavior guarantees:
- Mutations to `event.input` affect the actual tool execution
- Later `tool_call` handlers see mutations made by earlier handlers
- No re-validation is performed after your mutation
- Return values from `tool_call` only control blocking via `{ block: true, reason?: string }`
- Return values from `tool_call` control blocking via `{ block: true, reason?: string, terminate?: boolean }`
- `terminate` only applies to a blocked call; the agent stops early only when every finalized result in the batch is terminating
```typescript
import { isToolCallEventType } from "@earendil-works/pi-coding-agent";
@ -778,7 +779,7 @@ pi.on("tool_call", async (event, ctx) => {
event.input.command = `source ~/.profile\n${event.input.command}`;
if (event.input.command.includes("rm -rf")) {
return { block: true, reason: "Dangerous command" };
return { block: true, reason: "Dangerous command", terminate: true };
}
}