▾
import { createHumanInTheLoopMiddleware, createHumanInTheLoopToolMiddleware, getHumanInTheLoopPayload } from "@arcgis/ai-components/agent-utils/middlewares/humanInTheLoop.js";Type definitions
HumanInTheLoopInterruptRequest
- Since
- ArcGIS Maps SDK for JavaScript 5.1
- Supertypes
- AgentRunRequest<TCustomState>
agentId
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The ID of the agent requesting human intervention. This can be used to correlate the interrupt with a specific agent, especially in cases where multiple agents may be running concurrently and using the same middleware.
HumanInTheLoopInterrupt
- Since
- ArcGIS Maps SDK for JavaScript 5.1
- Supertypes
- Partial<Omit<UiInterrupt, "agentId" | "id">>
HumanInTheLoopMiddlewareOptions
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Options for configuring the HumanInTheLoopMiddleware.
interrupt
- Signature
-
interrupt (request: HumanInTheLoopInterruptRequest<TCustomState>): HumanInTheLoopInterrupt | Promise<HumanInTheLoopInterrupt>
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates interrupt details only when this step has no matching response.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | The agent run request that triggered the interrupt, containing details about the agent, node, and execution context. | |
- Returns
- HumanInTheLoopInterrupt | Promise<HumanInTheLoopInterrupt>
An object containing the interrupt details, which will be thrown as a NodeInterrupt to pause the agent's execution.
outputKey
- Type
- keyof AgentGraphState
| undefined
- Since
- ArcGIS Maps SDK for JavaScript 5.1
An optional key in the agent state where the human response should be stored.
HumanInTheLoopToolMessageRequest
- Since
- ArcGIS Maps SDK for JavaScript 5.1
- Supertypes
- FunctionToolMiddlewareRequest<TInput>
args
- Type
- object
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The arguments passed to the tool that is requesting human intervention.
toolName
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The name of the tool that is requesting human intervention.
HumanInTheLoopToolMiddlewareOptions
- Since
- ArcGIS Maps SDK for JavaScript 5.1
This middleware is designed to allow for human intervention during agent execution by throwing an interrupt that can be handled by the orchestrator to pause the agent and prompt the user for input or approval.
interrupt
- Signature
-
interrupt (request: HumanInTheLoopToolMessageRequest<TInput>): HumanInTheLoopInterrupt | Promise<HumanInTheLoopInterrupt>
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates interrupt details only when this step has no matching response.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | The tool middleware request that triggered the interrupt, containing details about the tool, input arguments, and execution context. | |
outputKey
- Type
- keyof TInput | undefined
- Since
- ArcGIS Maps SDK for JavaScript 5.1
An optional key in the tool input where the human response should be stored.
Functions
createHumanInTheLoopMiddleware
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates agent-level middleware that pauses the agent before execution when a response from the end user is needed. The application can use the interrupt to request approval, a selection, or additional information.
Use it when the response applies to the agent's overall task. For example, require approval before a task that may modify data or make a consequential decision: "Do you approve saving the results? (This will modify the saved feature layer.)"
Add it to the middlewares array of a FunctionAgent, LLMAgent, or
WorkflowAgent.
- Signature
-
createHumanInTheLoopMiddleware <TCustomState extends AgentData = AgentData>(options?: HumanInTheLoopMiddlewareOptions<TCustomState>): AgentLifecycleMiddleware<TCustomState>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| options | Configuration options for the middleware, including the interrupt handler and optional output key for storing the human response in the agent state. | |
- Returns
- AgentLifecycleMiddleware
Agent lifecycle middleware to add to an agent's
middlewaresarray.
- Example
- const agent = new LLMAgent({name: "Approved task",prompt: "Complete the user's task after approval.",middlewares: [createHumanInTheLoopMiddleware({interrupt: async ({ agentId }) => ({message: `Agent ${agentId} is requesting approval to continue. Do you approve?`,}),}),],});
createHumanInTheLoopToolMiddleware
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates tool middleware that pauses a tool call before the tool executes when a response from the end user is needed. The application can use the interrupt to request approval, a selection, or additional information.
Use it when the response applies to a specific tool operation. For example, ask what name to use for the saved results, or require approval before a tool changes data: "Do you approve updating the Parcels layer with these values? (This will modify its saved data.)"
Add it to a FunctionTool's middlewares array. The tool can be
supplied through an LLMAgent's tools array or a named toolLoaders entry on an
SkillAgent referenced by a skill's allowed-tools metadata.
- Signature
-
createHumanInTheLoopToolMiddleware <TInput extends AgentData = AgentData, TOutput = unknown>(options?: HumanInTheLoopToolMiddlewareOptions<TInput>): FunctionToolMiddleware<TInput, TOutput>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| options | Configuration options for the middleware, including the interrupt handler and optional output key for storing the human response in the tool input. | |
- Returns
- FunctionToolMiddleware<TInput, TOutput>
FunctionTool middleware to add to a tool's
middlewaresarray.
- Example
- const myTool = new FunctionTool({name: "sensitiveOperation",description: "Executes a sensitive operation after approval.",execute: async (input) => {// perform sensitive operation},middlewares: [createHumanInTheLoopToolMiddleware({interrupt: async ({ toolName, args }) => ({message: `Tool ${toolName} is requesting approval to execute with arguments: ${JSON.stringify(args)}. Do you approve?`,}),}),],});
getHumanInTheLoopPayload
- Type parameters
- <TPayload = unknown>
- Since
- ArcGIS Maps SDK for JavaScript 5.1
This function retrieves the human-in-the-loop (HITL) response payload from the agent execution configuration.
- Signature
-
getHumanInTheLoopPayload <TPayload = unknown>(config: AgentExecutionConfig | undefined): TPayload | undefined
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | The agent execution configuration that may contain a HITL response. | |
- Returns
- TPayload | undefined
The payload from the HITL response if available; otherwise, undefined.