import type { MiddlewareHandler, Middleware, AgentMiddlewareAgent, AgentRunRequest, AgentMiddlewareHandler } 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
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>
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
- 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 parameters
- <TCustomState extends AgentData = EmptyAgentData>
- Supertypes
- Middleware<AgentRunRequest
‚ AgentGraphState >
AgentMiddleware
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
name
- Type
- string
hooks
- Type
- AgentMiddlewareHooks
| undefined
outputKey
- Type
- keyof AgentGraphState
| undefined
AfterAgentRequest
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
- Supertypes
- AgentRunRequest<TCustomState>
result
- Type
- AgentGraphState
AgentMiddlewareHooks
- Type parameters
- <TCustomState extends AgentData = EmptyAgentData>
afterAgent
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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.
beforeAgent
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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
- 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.
ToolMiddlewareHooks
- Since
- ArcGIS Maps SDK for JavaScript 5.1
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.
LangChainMiddlewareHooks
- Supertypes
- Pick<LangChainAgentMiddleware‚ "afterModel" | "beforeModel" | "wrapModelCall" | "wrapToolCall">