▾
import { createAgentMiddleware, createAgentLifecycleMiddleware, createToolMiddleware } from "@arcgis/ai-components/agent-utils/middlewares/middleware.js";Functions
createAgentMiddleware
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates named middleware for an LLMAgent's middlewares array. This may be used for defining agent guardrails. It supports lifecycle, model-call,
and tool-call hooks. For lifecycle-only middleware accepted by FunctionAgent,
WorkflowAgent, and an LLMAgent, use
createAgentLifecycleMiddleware().
- Signature
-
createAgentMiddleware <TCustomState extends AgentData = EmptyAgentData>(name: string, hooks: AgentMiddlewareHooks<TCustomState>): AgentMiddleware<TCustomState>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| name | The name of the middleware. | | |
| hooks | The hooks to be used in the middleware. | |
- Returns
- AgentMiddleware
The created agent middleware.
createAgentLifecycleMiddleware
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
- Since
- ArcGIS Maps SDK for JavaScript 5.2
Creates named lifecycle middleware from AgentLifecycleHooks hooks. Use it with FunctionAgent, WorkflowAgent, or LLMAgent to run code before or after agent execution, without model-call or tool-call hooks.
- Signature
-
createAgentLifecycleMiddleware <TCustomState extends AgentData = EmptyAgentData>(name: string, hooks: AgentLifecycleMiddleware<TCustomState>["hooks"]): AgentLifecycleMiddleware<TCustomState>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| name | The name of the middleware. | | |
| hooks | AgentLifecycleMiddleware | The lifecycle hooks to be used in the middleware. | |
- Returns
- AgentLifecycleMiddleware
The created agent lifecycle middleware.
createToolMiddleware
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Creates named middleware for a FunctionTool's middlewares array. Use the wrapToolCall
hook in ToolMiddlewareHooks to inspect or modify tool inputs and results, or
control whether execution proceeds.
- Signature
-
createToolMiddleware <TInput extends AgentData = AgentData, TOutput = unknown>(name: string, hooks: ToolMiddlewareHooks<TInput, TOutput>, options?: { outputKey?: string; }): FunctionToolMiddleware<TInput, TOutput>
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| name | The name of the middleware. | | |
| hooks | ToolMiddlewareHooks<TInput, TOutput> | The hooks to be used in the middleware. | |
| options | { outputKey?: string; } | Optional configuration for the middleware, such as the output key. | |
- Returns
- FunctionToolMiddleware<TInput, TOutput>
The created function tool middleware.