Skip to content

HookRegistry

This docs was updated at: 2026-03-21

com.paragon.harness.HookRegistry  ยท  Class


Ordered registry of AgentHook instances executed around agent lifecycle events.

Hooks are invoked in registration order for before events and in reverse order for after events (stack semantics).

Hook failures are caught and logged but do not interrupt agent execution, ensuring that harness infrastructure never breaks agent functionality.

Example:

HookRegistry hooks = HookRegistry.create()
    .add(new LoggingHook())
    .add(new CostTrackingHook())
    .add(new RateLimitingHook(100));
// Wire into agent via Harness builder or directly:
Agent agent = Agent.builder()
    .hookRegistry(hooks)
    .build();

See Also

  • AgentHook

Since: 1.0

Methods

create

public static @NonNull HookRegistry create()

Creates an empty registry.


of

public static @NonNull HookRegistry of(@NonNull AgentHook... hooks)

Creates a registry pre-populated with the given hooks.


add

public @NonNull HookRegistry add(@NonNull AgentHook hook)

Adds a hook to the registry.

Parameters

Name Description
hook the hook to add

Returns

this registry (for chaining)


size

public int size()

Returns the number of registered hooks.


isEmpty

public boolean isEmpty()

Returns true if no hooks are registered.


fireBeforeRun

public void fireBeforeRun(@NonNull AgenticContext context)

Dispatches AgentHook.beforeRun to all hooks in order.


fireAfterRun

public void fireAfterRun(@NonNull AgentResult result, @NonNull AgenticContext context)

Dispatches AgentHook.afterRun to all hooks in reverse order.


fireBeforeToolCall

public void fireBeforeToolCall(@NonNull FunctionToolCall call, @NonNull AgenticContext context)

Dispatches AgentHook.beforeToolCall to all hooks in order.


fireAfterToolCall

public void fireAfterToolCall(
      @NonNull FunctionToolCall call,
      @NonNull ToolExecution execution,
      @NonNull AgenticContext context)

Dispatches AgentHook.afterToolCall to all hooks in reverse order.