You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE] Consolidate cancel and endTurn into a unified cancel field #3501
The hook system currently has two separate mechanisms for halting the agent loop early — cancel (on BeforeInvocationEvent, BeforeModelCallEvent, BeforeToolCallEvent, BeforeToolsEvent) and endTurn (on AfterToolsEvent) — that differ only in when they fire:
cancel prevents the next operation from starting (model call or tool execution).
endTurn halts the loop after tools finish, before the next model call.
From the hook author's perspective these are the same intent ("stop the loop and return a result") attached to different lifecycle points with different field names. This creates confusion:
Python uses cancel_tool for BeforeToolCallEvent while TypeScript uses cancel — same concept, different name.
Hook authors need to learn which field to set depending on which event they're in.
Proposed Solution
Standardize on cancel as the single field name across all hookable events in the agent loop:
// TypeScript — on every lifecycle event inside the loop
cancel: boolean|string=false// true → stop with default message// string → stop with that string as the final assistant content
# Python — same semanticscancel: bool|str=False
At a high level:
Keep cancel on BeforeInvocationEvent, BeforeModelCallEvent, BeforeToolCallEvent, BeforeToolsEvent (already correct).
Replace endTurn on AfterToolsEvent with cancel.
Rename cancel_tool on Python's BeforeToolCallEvent to cancel.
All produce the same AgentResult shape: stopReason: 'endTurn' with the supplied (or default) message.
Use Case
Hook authors writing guardrails that block unsafe tool calls or model prompts without memorizing per-event field names.
Plugins that implement budget caps, timeout policies, or human-in-the-loop gates — one pattern works everywhere.
Cross-SDK parity: contributors porting a plugin between Python and TypeScript use the same concept and field name.
Simplifies documentation: one section on "cancelling from a hook" instead of explaining cancel vs endTurn vs cancel_tool
changed the title [-][FEATURE] Consolidate cancel and endTurn into a unified loop-halting primitive[/-][+][FEATURE] Consolidate cancel and endTurn into a unified cancel field[/+]on Jul 27, 2026
Activity
[-][FEATURE] Consolidate cancel and endTurn into a unified loop-halting primitive[/-][+][FEATURE] Consolidate cancel and endTurn into a unified cancel field[/+]stop_event_loop#3503Unshure commentedon Jul 28, 2026
Draft proposal to enable this: #3506