▾
import type { MiddlewareHandler, Middleware, AgentMiddlewareAgent, AgentRunRequest, BeforeAgentUpdate } from "@arcgis/ai-components/agent-utils/middlewares/types.js";Type definitions
MiddlewareHandler
- Type parameters
- <TRequest, TResult>
Handles a middleware request and returns the resulting value.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | TRequest | The request payload for the current middleware stage. | |
- Returns
- Promise
| TResult
Middleware
- Type parameters
- <TRequest, TResult>
Wraps a middleware request and delegates to the next handler.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | TRequest | The request payload for the current middleware stage. | |
| handler | MiddlewareHandler<TRequest, TResult> | The next handler in the middleware chain. | |
- Returns
- Promise
| TResult
AgentMiddlewareAgent
Agent metadata provided to middleware hooks.
id
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Unique identifier for the agent, used for registration and invocation purposes.
name
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Name of the agent, used for display and identification purposes.
AgentRunRequest
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Execution metadata and the read-only current state provided to agent middleware hooks.
agent
- Type
- AgentMiddlewareAgent
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The agent that is being executed. This can be used in middleware hooks to access agent metadata and provide context for interrupts or other middleware behavior.
config
- Type
- AgentExecutionConfig | undefined
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The current execution configuration for the agent run, which may include configurable parameters, metadata, and other contextual information. This can be used in middleware hooks to make decisions based on the execution context or to store and retrieve information related to the agent run.
nodeName
- Type
- string
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The name of the current node being executed in the agent's workflow. This can be used in middleware hooks to provide context or make decisions based on the specific node.
state
- Type
- Readonly<AgentGraphState
>
- Since
- ArcGIS Maps SDK for JavaScript 5.1
The current reduced state. Read it without mutation; return a partial update from the hook to change state.
BeforeAgentUpdate
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Partial graph-state update returned by a beforeAgent hook.
- Supertypes
- Partial<AgentGraphState
>
jumpTo
- Type
- "end" | undefined
Applies the update, skips remaining beforeAgent hooks and graph execution, then runs afterAgent hooks.
AgentMiddleware
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Named lifecycle, model-call, and tool-call hooks used by an LLMAgent.
hooks
- Type
- AgentMiddlewareHooks
Hooks to run during the agent lifecycle, model calls, and tool calls.
AgentLifecycleMiddleware
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Named lifecycle hooks for FunctionAgent, WorkflowAgent, or LLMAgent, without model-call or tool-call hooks.
hooks
- Type
- AgentLifecycleHooks
& { beforeModel?: never; afterModel?: never; wrapModelCall?: never; wrapToolCall?: never; }
Lifecycle hooks to run before or after agent execution.
AgentLifecycleHooks
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Hooks that run before agent execution and after it completes.
afterAgent
- Type
- MiddlewareHandler<AgentRunRequest
, Partial<AgentGraphState > | void> | undefined
Runs in reverse registration order after completion, including returned failures and early exits. Does not run as a finally handler for thrown errors, cancellation, or interruption.
AgentMiddlewareHooks
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
Lifecycle and LangChain hooks for model requests made by an LLMAgent.
- Supertypes
- AgentLifecycleHooks<TCustomState>
afterModel
- Type
- LangChainAgentMiddleware["afterModel"] | undefined
Runs after a model call so the response or resulting state can be inspected or updated.
beforeModel
- Type
- LangChainAgentMiddleware["beforeModel"] | undefined
Runs before a model call so its request or state can be inspected or updated.
wrapModelCall
- Signature
-
wrapModelCall (request: Parameters<ModelCallHook>[0], handler: Parameters<ModelCallHook>[1], config?: AgentExecutionConfig): ReturnType<ModelCallHook>
Wraps a model call; inspect or modify its request, invoke the handler, or provide a response.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | | | |
| handler | | | |
| config | | |
- Returns
- ReturnType<ModelCallHook>
wrapToolCall
- Signature
-
wrapToolCall (request: Parameters<ToolCallHook>[0], handler: Parameters<ToolCallHook>[1], config?: AgentExecutionConfig): ReturnType<ToolCallHook>
Wraps a tool call made during model execution; inspect or modify it, invoke the handler, or provide a result.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| request | | | |
| handler | | | |
| config | | |
- Returns
- ReturnType<ToolCallHook>
ToolMiddlewareHooks
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Hooks for intercepting and controlling a FunctionTool call.
wrapToolCall
- Type
- FunctionToolMiddlewareHandler<TInput, TOutput> | undefined
- Since
- ArcGIS Maps SDK for JavaScript 5.1
Hook that wraps a tool call, allowing you to intercept and modify the request and response of a tool execution. This can be used for logging, modifying inputs/outputs, or implementing custom behavior around tool calls.