import { FunctionTool } from "@arcgis/ai-components/agent-utils/tools/FunctionTool.js";- Inheritance
- FunctionTool→
Accessor.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
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | FunctionToolConstructProperties<TInput, TOutput> | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| FunctionToolExecute<TInput, TOutput> | | |
| z.ZodType | | |
| FunctionToolMiddleware<TInput, TOutput>[] | | |
| | ||
| z.ZodType | | |
| |
description
- 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
- 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
- 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
- Type
- FunctionToolMiddleware<TInput, TOutput>[]
Middleware that can wrap this tool's execution.
name
- 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
- 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
- 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
| Method | Signature | Class |
|---|---|---|
| getTool(): StructuredToolInterface | |
Type definitions
FunctionToolExecute
- Type parameters
- <TInput extends object, TOutput>
Execute function used by FunctionTool.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| input | TInput | Structured tool input. | |
| config | Optional execution configuration. | |
- Returns
- Promise
| TOutput
FunctionToolMiddlewareRequest
config
- Type
- AgentExecutionConfig | undefined
FunctionToolMiddlewareHandler
- Supertypes
- Middleware<FunctionToolMiddlewareRequest
‚ FunctionToolResult >
FunctionToolMiddleware
name
- Type
- string
handler
- Type
- FunctionToolMiddlewareHandler<TInput, TOutput>
outputKey
- Type
- keyof TInput | undefined
FunctionToolLike
resultMode
- 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.
FunctionToolMiddlewareTool
description
- Type
- string
name
- Type
- string
resultMode
- Type
- ToolResultMode
FunctionToolConstructProperties
- Type parameters
- <TInput extends AgentData, TOutput>
- Supertypes
- Partial<Pick<FunctionTool<TInput, TOutput>, "inputSchema" | "middlewares" | "outputSchema" | "resultMode">> ‚ Pick<FunctionTool<TInput, TOutput>‚ "description" | "execute" | "name">