import { FunctionAgent } from "@arcgis/ai-components/agent-utils/FunctionAgent.js";- Inheritance
- FunctionAgent→
BaseAgent<AgentCustomState<TInput, TOutput>>→ Accessor.js
- Since
- ArcGIS Maps SDK for JavaScript 5.1
FunctionAgent executes a user-provided function as its core logic. It supports optional input and output schemas for validation and structured data handling.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | FunctionAgentConstructProperties<TInput, TOutput> | | |
Properties
| Property | Type | Class |
|---|---|---|
| inherited | ||
| FunctionAgentExecute<TInput, TOutput> | | |
| readonly inherited | ||
| | ||
| inherited | ||
| inherited | ||
| | ||
| readonly inherited |
description
- Type
- string
Description of the agent's purpose and functionality. This can be used in registration metadata to provide context about the agent's functionality. A good description is clear and concise. Use bullet points to describe tasks the agent can accomplish. Provide examples of user questions or prompts that could be answered by the agent.
- Default value
- ""
execute
- Type
- FunctionAgentExecute<TInput, TOutput>
The execute function contains the core logic of the FunctionAgent. It receives the current agent state and an optional execution configuration, and returns one of the following:
- a structured output object - used in a follow-up node for further processing in the graph, or
- a string representing a the final message to display in the chat UI.
inputSchema
- Type
- ZodObjectSchema
| undefined
The input schema defines the expected structure of the agent state when the execute function is invoked. If provided, the agent will validate incoming state against this schema and throw an error if validation fails.
middlewares
- Type
- AgentMiddleware
[]
An optional array of middleware functions that can be used to extend or modify the agent's behavior during execution. This allows for flexible customization of the agent's execution logic. For example, middlewares can be used to implement trace messages (i.e. logging), human-in-the-loop interrupts, or other custom actions.
name
- Type
- string
A name for the agent, which is used in the registration metadata and can be displayed in tooling. It should be unique across agents to avoid registration conflicts. A good agent name clearly indicates the scope and purpose of the agent. For example, "WeatherAgent" or "CustomerSupportAgent" are descriptive names that convey the agent's functionality as opposed to generic names like "Agent1" or "MyAgent".
The name is also used to generate the agent's id.
outputSchema
- Type
- ZodObjectSchema
| undefined
The output schema defines the expected structure of the result returned by the execute function. If provided, the agent will validate the output against this schema and handle it accordingly.
registration
- Type
- AgentRegistration
The registration property assembles the necessary metadata and graph definition for this agent, which is consumed by the orchestrator during registration.
Methods
| Method | Signature | Class |
|---|---|---|
| initialize(): void | | |
| inherited | run(state?: Partial<AgentGraphState<TCustomState>>, config?: AgentExecutionConfig): Promise<AgentGraphState<TCustomState>> |
run
- Signature
-
run (state?: Partial<AgentGraphState<TCustomState>>, config?: AgentExecutionConfig): Promise<AgentGraphState<TCustomState>>
Executes the agent's graph with the provided state and configuration. This method is responsible for invoking the compiled graph and returning the resulting state after execution.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| state | An optional partial state object to initialize the graph execution. This can include any custom fields defined by the agent. | | |
| config | An optional execution configuration that can influence the agent's behavior during invocation. | |
- Returns
- Promise<AgentGraphState
> A promise that resolves to the updated agent graph state after execution.
Type definitions
FunctionAgentExecute
FunctionAgentExecute defines the signature for the execute function used by FunctionAgent.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| state | AgentNodeState<TInput, TOutput> | Agent state at invocation time. | |
| config | Optional execution configuration. | |
FunctionAgentConstructProperties
- Supertypes
- Partial<Pick<FunctionAgent<TInput, TOutput>, "description" | "inputSchema" | "middlewares" | "outputSchema">> ‚ Pick<FunctionAgent<TInput, TOutput>‚ "execute" | "name">