ESM
import { FunctionTool } from "@arcgis/ai-components/agent-utils/tools/FunctionTool.js";
Inheritance
FunctionToolAccessor.js
Since
ArcGIS Maps SDK for JavaScript 5.1

FunctionTool is a tool implementation that allows users to define custom logic through a provided execute function, along with input/output schemas for validation and optional middleware for extensibility.

The FunctionTool is passed to LLMAgents as part of their tools array, and can be invoked by the agent during execution based on the agent's prompt and reasoning process. The resultMode property allows the tool to either return a final response directly or continue the agent's processing after execution, providing flexibility in how the tool's output is used within the agent's workflow.

Constructors

Constructor

Constructor

Parameters

ParameterTypeDescriptionRequired
properties

Properties

description

Property
Type
string

A concise, but clear description of the tool's functionality. This should provide enough information for the agent to understand when and why to use the tool. You can include examples of a user's input that would trigger the tool, the values to extract, and sample output to illustrate its purpose.

execute

Property
Type
FunctionToolExecute<TInput, TOutput>

The execute function contains the custom logic that will be executed when the tool is invoked by an agent. It receives the input object and an optional execution configuration, and returns either a result directly or a promise that resolves to the result.

The result is validated against the output schema, if provided.

inputSchema

Property
Type
z.ZodType | undefined

The input schema defines the expected structure of the input object when invoking the tool. This should be a Zod schema object. The agent will validate the input against this schema before execution.

middlewares

Property
Type
FunctionToolMiddleware<TInput, TOutput>[]

Middleware that can wrap this tool's execution.

name

Property
Type
string

The name of the tool, which will be used to invoke it. This should be unique among the tools available to an agent. It should also be descriptive of the tool's functionality to make it clear to the agent when to use it.

outputSchema

Property
Type
z.ZodType | undefined

The output schema defines the expected structure of the result returned by the tool. This should be a Zod schema object. The agent will validate the output against this schema after execution.

resultMode

Property
Type
ToolResultMode

The result mode determines how the agent should treat the output of this tool. If set to terminal, the agent will return the tool's output directly as its final response. If set to continue, the agent will continue processing after invoking the tool, allowing for further reasoning or tool calls.

Default value
"continue"

Methods

MethodSignatureClass
getTool(): StructuredToolInterface

getTool

Method
Signature
getTool (): StructuredToolInterface

Builds the LangChain tool adapter used by LLM agents.

Returns
StructuredToolInterface

Type definitions

FunctionToolExecute

Type definition
Type parameters
<TInput extends object, TOutput>

Execute function used by FunctionTool.

Parameters

ParameterTypeDescriptionRequired
input
TInput

Structured tool input.

config

Optional execution configuration.

Returns
Promise | TOutput

FunctionToolResult

Type definition
Type parameters
<TOutput = unknown>
Type
TOutput | string

FunctionToolMiddlewareRequest

Type definition
Type parameters
<TInput extends AgentData = AgentData>

config

Property
Type
AgentExecutionConfig | undefined

input

Property
Type
TInput

tool

Property
Type
FunctionToolMiddlewareTool

toolCallId

Property
Type
string | undefined

FunctionToolMiddlewareHandler

Type definition
Type parameters
<TInput extends AgentData = AgentData, TOutput = unknown>

FunctionToolMiddleware

Type definition
Type parameters
<TInput extends AgentData = AgentData, TOutput = unknown>

name

Property
Type
string

handler

Property
Type
FunctionToolMiddlewareHandler<TInput, TOutput>

outputKey

Property
Type
keyof TInput | undefined

ToolResultMode

Type definition
Type
"continue" | "terminal"

FunctionToolLike

Type definition

name

Property
Type
string | undefined

Name of the tool, used for invocation by agents. This should be unique among the tools available to an agent.

resultMode

Property
Type
ToolResultMode | undefined

Result mode determines how the agent should treat the output of this tool. If set to "terminal", the agent will return the tool's output directly as its final response. If set to "continue", the agent will continue processing after invoking the tool, allowing for further reasoning or tool calls.

getTool

Property
Type
() => StructuredToolInterface

FunctionToolMiddlewareTool

Type definition

description

Property
Type
string

name

Property
Type
string

resultMode

Property
Type
ToolResultMode

FunctionToolConstructProperties

Type definition
Type parameters
<TInput extends AgentData, TOutput>
Supertypes
Partial<Pick<FunctionTool<TInput, TOutput>, "inputSchema" | "middlewares" | "outputSchema" | "resultMode">> ‚  Pick<FunctionTool<TInput, TOutput>‚ "description" | "execute" | "name">