Aspect-Oriented Programming for AI Agents: Hookflows as an Event Bus Aspect-oriented programming (AOP) principles for AI agents by using "hookflows" as an event bus to handle cross-cutting concerns like notifications. Instead of having each agent explicitly call a Telegram notification function, the author created a governance hookflow that intercepts every agent dispatch, validates required metadata, and sends notifications as a deterministic side effect without consuming additional tokens. This approach solves common problems in multi-agent systems, including token cost compounding, unreliable agent discretion, and degraded composability. I was debugging a notification problem in my 53-agent home assistant when I stumbled onto something unexpectedly powerful. I needed every agent dispatch to notify me via Telegram — but I didn't want to burn tokens on a separate telegram send message call. The agents were already being validated by a governance hookflow. Why not piggyback the notification onto the validation step? One tool call. Validation and notification. Zero additional tokens consumed by the agent. Then it hit me: I'd accidentally reinvented aspect-oriented programming — but for AI agents instead of Java classes. Aspect-oriented programming emerged in the late 1990s to solve a specific problem: cross-cutting concerns. Logging, security checks, transaction management — these behaviors cut across every module in your application, but they don't belong in any single module's core logic. The AOP solution: define these concerns once, then weave them into your code at specific join points method calls, property access using advice before, after, around . The original code never knows it's being augmented. Now apply that mental model to AI agents: The agent doesn't know. It just calls a tool. The governance layer intercepts, validates, and fires side effects. This is textbook AOP — applied to a fundamentally new domain. Here's the actual hookflow running in my platform. It requires every agent dispatch to include a notification tag, validates it, and then sends the notification as a side effect: name: Require task or write agent originator notify description: Blocks task/write agent calls unless they contain a valid originator notify tag. On success, sends the parsed message to the originator via Telegram Bot API. on: hooks: types: preToolUse tools: task, write agent blocking: true env: TOOL NAME: ${{ event.tool.name }} TASK PROMPT JSON: ${{ toJSON event.tool.args.prompt }} WRITE AGENT MESSAGE JSON: ${{ toJSON event.tool.args.message }} steps: - name: Validate and send originator notification run: | Determine which tool arg contains the text $text = if $env:TOOL NAME -eq 'write agent' { $env:WRITE AGENT MESSAGE JSON | ConvertFrom-Json } else { $env:TASK PROMPT JSON | ConvertFrom-Json } Parse the XML tag from tool arguments $pattern = '