[FEATURE] Framework-level enforced hook priority that cannot be overridden
Problem Statement
There is no mechanism to enforce hook execution order at the framework level. Even with a priority API, users could potentially override or circumvent security-critical hook ordering. Security hooks need guaranteed execution order that cannot be bypassed.
Proposed Solution
Provide a mechanism for "system" or "framework" level hooks with enforced priority:
- Reserved priority levels that user hooks cannot access
- A separate registration path for framework-enforced hooks
- Configuration to lock certain priority ranges
Use Case
For enterprise and compliance use cases:
- Security scanning hooks must always run first—users should not be able to register hooks that run before them
- Audit logging hooks must always run last—users should not be able to suppress or run after them
- Compliance checks must have deterministic, tamper-proof execution order
Alternatives Solutions
Without framework enforcement, we must rely on documentation and trust, which is insufficient for security-critical scenarios.
Additional Context
No response
Have to think about this more but I still want to mention that hooks are guaranteed to execute in definition/insertion order. So if you have the following let's say:
from strands import Agent
from strands.plugins import Plugin, hook
from strands.hooks import BeforeToolCallEvent
class MyPlugin(Plugin):
name = "my-plugin"
@hook
def op1(self, event: BeforeToolCallEvent) -> None:
print("op1")
@hook
def op2(self, event: BeforeToolCallEvent) -> None:
print("op2")
agent = Agent(plugins=[MyPlugin()])
op1 will run before op2. We do need to document this under https://strandsagents.com/docs/user-guide/concepts/agents/hooks/.