Skip to main content

Callable Functions in the AI Agent Node - ConvyAI

Overview​

The AI Agent node supports Function Tools - user-defined JavaScript functions that the model can invoke during execution. Functions extend what the AI can do within a flow: validate data, perform calculations, extract structured values, call external services, or transform input before generating a final response.

Functions:

  • Accept parameters defined via JSON Schema
  • Can execute custom logic (validations, calculations, data extraction)
  • Return output that the AI uses in its final response
  • Support standard and async functions
  • Allow fetch for HTTP calls and console.log for debugging

Function configuration​

Open the Function Tools List section in the AI Agent node and add a new function.

Function configuration modal

Each function is configured through a modal with the following fields:

FieldRequiredDescription
NameYesUnique identifier for the function.
DescriptionYesNatural language description used by the model to decide when to invoke the function.
Code JSYesThe JavaScript implementation.
Input schema JSONNoJSON Schema definition of the function's input parameters.

Code editor​

The function code editor is built on CodeMirror and includes the following features:

FeatureDescription
Syntax highlightingCode is highlighted according to JavaScript syntax.
Hint & autocompleteTyping $ opens an autocomplete menu with available variables and objects. Continue typing to filter (e.g., $.vars shows only vars-compatible values).
Automatic validationCode is validated in real time. Syntactic and structural errors are detected immediately.
Error reportingErrors appear as markers in the left margin. Hovering over a marker shows a tooltip with the error description (e.g., Unexpected token, Missing bracket).
Save guardSaving is blocked if blocking errors are present. The function can only be saved when the code is valid.

Variable autocomplete​

The editor provides an autocomplete system activated by typing $. A hint below the code block reminds the user of this shortcut. Pressing $ opens a contextual menu with all available variables and a search box; selecting a variable inserts it at the cursor position.

Available variable categories:

VariableDescription
$.argsObject containing the arguments passed to the function at call time, as defined in the input schema.
$.inputObject containing the user's question (question field) and any files passed as input (attachments field).
$.contextExecution context: current bot ID and name, communication channel, conversation ID, and related metadata.
$.entitiesObject containing the flow variables defined in the current execution environment.

JSON Schema input definition​

Input parameters are defined using JSON Schema. Variables declared in the schema are accessible inside the function via $.args.

{
"type": "object",
"properties": {
"orderId": {
"type": "string",
"description": "The order ID to look up."
},
"language": {
"type": "string",
"enum": ["en", "it", "fr"]
}
},
"required": ["orderId"]
}

Inside the function, access these values as $.args.orderId and $.args.language.