Types
import type { MiddlewareHandler, Middleware, AgentMiddlewareAgent, AgentRunRequest, AgentMiddlewareHandler } from "@arcgis/ai-components/agent-utils/middlewares/types.js";

Type definitions

MiddlewareHandler

Type definition
Type parameters
<TRequest, TResult>

Handles a middleware request and returns the resulting value.

Parameters

ParameterTypeDescriptionRequired
request
TRequest

The request payload for the current middleware stage.

Returns
Promise | TResult

Middleware

Type definition
Type parameters
<TRequest, TResult>

Wraps a middleware request and delegates to the next handler.

Parameters

ParameterTypeDescriptionRequired
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

Type definition

description

Property
Type
string | undefined
Since
ArcGIS Maps SDK for JavaScript 5.1

Description of the agent, which can be used to provide context in middleware hooks and interrupts.

id

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 5.1

Unique identifier for the agent, used for registration and invocation purposes.

name

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 5.1

Name of the agent, used for display and identification purposes.

AgentRunRequest

Type definition
Type parameters
<TCustomState extends AgentData = EmptyAgentData>

agent

Property
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

Property
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

Property
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

Property
Type
Partial<AgentGraphState>
Since
ArcGIS Maps SDK for JavaScript 5.1

The current state of the agent's workflow, which may include custom data and intermediate results. This can be used in middleware hooks to access or modify the agent's state during execution.

AgentMiddlewareHandler

Type definition
Type parameters
<TCustomState extends AgentData = EmptyAgentData>

AgentMiddleware

Type definition
Type parameters
<TCustomState extends AgentData = EmptyAgentData>

name

Property
Type
string

handler

Property
Type
AgentMiddlewareHandler

hooks

Property
Type
AgentMiddlewareHooks | undefined

outputKey

Property
Type
keyof AgentGraphState | undefined

AfterAgentRequest

Type definition
Type parameters
<TCustomState extends AgentData = EmptyAgentData>
Supertypes
AgentRunRequest<TCustomState>

result

Property
Type
AgentGraphState

AgentMiddlewareHooks

Type definition
Type parameters
<TCustomState extends AgentData = EmptyAgentData>

afterAgent

Method
Signature
afterAgent (request: AfterAgentRequest<TCustomState>): Partial<AgentGraphState<TCustomState>> | Promise<Partial<AgentGraphState<TCustomState>> | void> | void
Since
ArcGIS Maps SDK for JavaScript 5.1

An optional hook that is called after the agent has executed, allowing for modification of the result or additional side effects.

Parameters

ParameterTypeDescriptionRequired
request

The request payload for the afterAgent hook, including the original request and the result of the agent's execution.

Returns
Partial<AgentGraphState> | Promise<Partial<AgentGraphState> | void> | void

A partial update to the agent's state or other modifications to be applied to the final result, or a promise that resolves to such an update.

afterModel

readonly Property
Type
ModelLifecycleHook | undefined

beforeModel

readonly Property
Type
ModelLifecycleHook | undefined

beforeAgent

Method
Signature
beforeAgent (request: AgentRunRequest<TCustomState>): Partial<AgentGraphState<TCustomState>> | Promise<Partial<AgentGraphState<TCustomState>> | void> | void
Since
ArcGIS Maps SDK for JavaScript 5.1

An optional hook that is called before the agent executes, allowing for modification of the request or additional side effects.

Parameters

ParameterTypeDescriptionRequired
request

The request payload for the beforeAgent hook, including the original request.

Returns
Partial<AgentGraphState> | Promise<Partial<AgentGraphState> | void> | void

A partial update to the agent's state or other modifications to be applied to the request, or a promise that resolves to such an update.

wrapAgent

readonly Property
Type
AgentMiddlewareHandler | undefined
Since
ArcGIS Maps SDK for JavaScript 5.1

An optional hook that wraps the entire agent execution, allowing for complete control over the execution flow.

wrapModelCall

readonly Property
Type
LangChainMiddlewareHooks["wrapModelCall"] | undefined

wrapToolCall

readonly Property
Type
LangChainMiddlewareHooks["wrapToolCall"] | undefined

ToolMiddlewareHooks

Type definition
Type parameters
<TInput extends AgentData = AgentData, TOutput = unknown>
Since
ArcGIS Maps SDK for JavaScript 5.1

wrapToolCall

readonly Property
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.

LangChainMiddlewareHooks

Type definition
Supertypes
Pick<LangChainAgentMiddleware‚ "afterModel" | "beforeModel" | "wrapModelCall" | "wrapToolCall">

ModelLifecycleHook

Type definition
Supertypes
NonNullable<LangChainMiddlewareHooks["beforeModel"]>