As Step Hook • AI Agent SDK

as_step_hook: Adapt a plain “on_step“ callback into an “after_model“ middleware hook.

as_step_hook

Function

</div>

This function is defined in the middleware module.

Adapt a plain `on_step callback into an after_model` middleware hook.

`HooksConfig(on_step=...) advertises "called once per agent step". An agent step is one model call, so the callback is routed onto the existing after_model middleware slot: it is invoked with the :class:ModelResponse` for the step and its return value is ignored (the response passes through unchanged, so an observer can never corrupt the run).

Diagram

Allow

Deny

Event Trigger

Hook: as_step_hook

Decision

Process

Block

Signature

python
def as_step_hook(callback: Callable[[Any], Any]) -> AfterModelFn

Parameters

ParamField Callable

No description available.

Returns

ResponseField AfterModelFn

The result of the operation.

Source

View on GitHub

praisonaiagents/hooks/middleware.py at line 339


Related Documentation