Fire Hook • AI Agent SDK

fire_hook: Emit a lifecycle event to every hook registered for it.

fire_hook

Function

</div>

This function is defined in the registry module.

Emit a lifecycle event to every hook registered for it.

The emitting counterpart to :func:add_hook. Runtime components call this at a real state transition (a kanban task created, a background job finishing) so plugins subscribed to that :class:HookEvent actually hear about it.

Best-effort by contract: an unknown event id, a malformed payload or a raising subscriber is logged and swallowed — emitting an observability event must never break the operation that produced it.

Diagram

Allow

Deny

Event Trigger

Hook: fire_hook

Decision

Process

Block

Signature

python
def fire_hook(event: Union[str, HookEvent], data: Optional[Dict]) -> List

Parameters

ParamField Union[str, HookEvent]

`HookEvent`, its canonical value, or its member name.

ParamField Optional[Dict]

Payload; recognised keys populate the event’s input dataclass and the remainder is carried through in `extra`.

Returns

ResponseField List

The hook execution results, or `[]` when there are no subscribers or the emission was scheduled on a already-running event loop.

Uses

  • resolve_hook_event
  • logger.debug
  • get_default_registry
  • reg.get_hooks
  • HookRunner
  • asyncio.get_running_loop
  • loop.is_running
  • loop.create_task
  • runner.execute
  • _PENDING_HOOK_TASKS.add

Source

View on GitHub

praisonaiagents/hooks/registry.py at line 580


Related Documentation