Interface AgencyCallbacks

Event callbacks registered on BaseAgentConfig.on. Each returns void. An agency runs every one inside a try/catch, whichever part of a run fires it (the agency, its strategy, a tool approval or a HITL check): a callback that throws, or an async one whose promise rejects, is written through the host's logger as agency_callback_threw (in an agency with a pool or a panel, with every key the agency can send masked in its message), and never fails the call, changes what it returns or leaves a rejection unhandled. An agency reads each one from the on object when the run fires it, and none when it is built, so a callback set, replaced or deleted there after agency() returns is the one that runs, and a getter there that throws is written as a callback that throws is, at its event.

interface AgencyCallbacks {
    agentStart?: ((e) => void);
    agentEnd?: ((e) => void);
    handoff?: ((e) => void);
    toolCall?: ((e) => void);
    error?: ((e) => void);
    emergentForge?: ((e) => void);
    guardrailResult?: ((e) => void);
    limitReached?: ((e) => void);
    approvalRequested?: ((e) => void);
    approvalDecided?: ((e) => void);
    guardrailHitlOverride?: ((e) => void);
}

Properties

agentStart?: ((e) => void)

Called immediately before an agent starts.

Type declaration

    • (e): void
    • Parameters

      • e: AgentStartEvent

      Returns void

agentEnd?: ((e) => void)

Called after an agent produces its final output.

Type declaration

    • (e): void
    • Parameters

      • e: AgentEndEvent

      Returns void

handoff?: ((e) => void)

Called when control is handed off between agents.

Type declaration

    • (e): void
    • Parameters

      • e: HandoffEvent

      Returns void

toolCall?: ((e) => void)

Called when an agent invokes a tool.

Type declaration

    • (e): void
    • Parameters

      • e: ToolCallEvent

      Returns void

error?: ((e) => void)

Called when an unhandled error occurs inside an agent.

Type declaration

    • (e): void
    • Parameters

      • e: {
            agent: string;
            error: Error;
            timestamp: number;
        }
        • agent: string
        • error: Error
        • timestamp: number

      Returns void

emergentForge?: ((e) => void)

Called when the emergent subsystem forges a new agent.

Type declaration

    • (e): void
    • Parameters

      • e: ForgeEvent

      Returns void

guardrailResult?: ((e) => void)

Called after a guardrail evaluates an input or output.

Type declaration

    • (e): void
    • Parameters

      • e: GuardrailEvent

      Returns void

limitReached?: ((e) => void)

Called when a resource limit is reached.

Type declaration

    • (e): void
    • Parameters

      • e: LimitEvent

      Returns void

approvalRequested?: ((e) => void)

Called when an approval request is raised.

Type declaration

approvalDecided?: ((e) => void)

Called after an approval decision is resolved.

Type declaration

guardrailHitlOverride?: ((e) => void)

Called when the post-approval check overrides an HITL approval: a tool call, an agent run or the final output was approved, and a built-in check matched and vetoed it.

Type declaration

    • (e): void
    • Parameters

      • e: GuardrailHitlOverrideEvent

      Returns void