nat.middleware.hitl#
Human-in-the-Loop (HITL) middleware package.
Submodules#
Attributes#
Classes#
Represents a system-human interaction with a response. |
|
Human-in-the-Loop middleware. |
|
Configuration for Human-in-the-Loop (HITL) middleware. |
Package Contents#
- HumanPrompt#
- class InteractionResponse(/, **data: Any)#
Bases:
InteractionBaseRepresents a system-human interaction with a response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- content: HumanResponse = None#
- class HITLMiddleware(
- config: nat.middleware.hitl.hitl_middleware_config.HITLMiddlewareConfig,
- builder: nat.builder.builder.Builder,
Bases:
nat.middleware.dynamic.dynamic_function_middleware.DynamicFunctionMiddlewareHuman-in-the-Loop middleware.
Intercepts function calls to present human prompts before and/or after execution. Subclasses must implement
_on_pre_invoke_responseand_on_post_invoke_responseto control what happens with the prompt response at each phase.Initialize the HITL middleware.
- Args:
config: HITL middleware configuration. builder: Workflow builder used for function discovery.
- abstractmethod _on_pre_invoke_response(
- response: nat.data_models.interactive.InteractionResponse,
- context: nat.middleware.middleware.InvocationContext,
- Async:
Handle the pre-invoke prompt response and return an invocation decision.
- Args:
response: The human prompt response collected before the function is called. context: Invocation context containing the function arguments.
- Returns:
Noneto proceed unchanged, anInvocationContextwith updatedmodified_argsormodified_kwargsto alter inputs, or anInvocationContextwithactionset toInvocationAction.SKIPto bypass the function call entirely.
- abstractmethod _on_post_invoke_response(
- response: nat.data_models.interactive.InteractionResponse,
- context: nat.middleware.middleware.InvocationContext,
- Async:
Handle the post-invoke prompt response and return an invocation decision.
- Args:
response: The human prompt response collected after the function returns. context: Invocation context with
outputset to the function result for a single call or chunk.- Returns:
Noneto return the output as-is, or anInvocationContextwithoutputupdated to replace the function’s return value. For streaming calls, setoutputtoNoneto suppress the chunk entirely.
- async pre_invoke( ) nat.middleware.middleware.InvocationContext | None#
Present a human prompt before the function is called.
A no-op when
pre_invoke_promptis not configured.- Args:
context: Invocation context (output is None at this phase).
- Returns:
The result of
_on_pre_invoke_response.
- async post_invoke( ) nat.middleware.middleware.InvocationContext | None#
Present a human prompt after the function returns.
A no-op when
post_invoke_promptis not configured.- Args:
context: Invocation context with the function output populated.
- Returns:
The result of
_on_post_invoke_response.
- class HITLMiddlewareConfig#
Bases:
nat.middleware.dynamic.dynamic_middleware_config.DynamicMiddlewareConfigConfiguration for Human-in-the-Loop (HITL) middleware.
Inherits component and function targeting from DynamicMiddlewareConfig.