Summary
The Python SDK currently runs callbacks for all After* hook events (AfterInvocationEvent, AfterToolCallEvent, AfterModelCallEvent, AfterNodeCallEvent, AfterMultiAgentInvocationEvent) in reverse registration order via the should_reverse_callbacks property. This follows stack-based cleanup semantics (last registered = first to run during teardown), but in practice it creates confusing behavior for users who expect hooks to execute in the order they were registered.
The TypeScript SDK addressed this in sdk-typescript#1005 by introducing explicit ordering rather than implicit reversal. For Python 2.0 (breaking change window), the proposal is to remove the reverse ordering and run all hook callbacks — including After* events — in registration order, aligning with the TypeScript SDK's approach and reducing user confusion around hook execution semantics.
Affected code
sdk-python/src/strands/hooks/registry.py — get_callbacks_for() checks event.should_reverse_callbacks and yields in reversed order when True
sdk-python/src/strands/hooks/events.py — Five event classes override should_reverse_callbacks to return True:
AfterInvocationEvent
AfterToolCallEvent
AfterModelCallEvent
AfterNodeCallEvent
AfterMultiAgentInvocationEvent
Summary
The Python SDK currently runs callbacks for all
After*hook events (AfterInvocationEvent,AfterToolCallEvent,AfterModelCallEvent,AfterNodeCallEvent,AfterMultiAgentInvocationEvent) in reverse registration order via theshould_reverse_callbacksproperty. This follows stack-based cleanup semantics (last registered = first to run during teardown), but in practice it creates confusing behavior for users who expect hooks to execute in the order they were registered.The TypeScript SDK addressed this in sdk-typescript#1005 by introducing explicit ordering rather than implicit reversal. For Python 2.0 (breaking change window), the proposal is to remove the reverse ordering and run all hook callbacks — including
After*events — in registration order, aligning with the TypeScript SDK's approach and reducing user confusion around hook execution semantics.Affected code
sdk-python/src/strands/hooks/registry.py—get_callbacks_for()checksevent.should_reverse_callbacksand yields in reversed order when Truesdk-python/src/strands/hooks/events.py— Five event classes overrideshould_reverse_callbacksto returnTrue:AfterInvocationEventAfterToolCallEventAfterModelCallEventAfterNodeCallEventAfterMultiAgentInvocationEvent