Skip to content
Français

defineHarnessHook

import { defineHarnessHook } from "@elie-laloum/outpost";

Define control code that runs at one point of the built-in harness loop: session-start, before-model, after-model, before-tool, after-tool or stop. Unlike observers, a hook can add instructions, deny or rewrite a tool call, replace its result or refuse to stop; an exception from a hook fails the turn.

Complete example and detailed rules.

  • optionsRequired
    HarnessHookOptions<Phase>
    Loop phase, optional name and control function of the hook.
  • options.onRequired
    Phase
    Loop point where the hook runs.
  • options.nameOptional
    string | undefined
    Name for diagnostics, default the phase name.
  • options.runRequired
    (input: HarnessHookInput<Phase>) => HarnessHookResult<Phase> | Promise<HarnessHookResult<Phase>>
    Control function for this phase. Hooks of a phase run in declaration order; an exception fails the turn, and an invalid decision fails it with code configuration.

HarnessHook<Phase>

export declare function defineHarnessHook<Phase extends HarnessHookPhase>(
  options: HarnessHookOptions<Phase>,
): HarnessHook<Phase>;