Function calling in AI commands
Let the AI pick the next action, then branch your command on it.
On this page
Function calling lets a command's GPT step choose what happens next. You describe a few functions, the AI picks the one that fits the input and fills in its arguments, and the command runs the steps you set up for that function. It is how you build small agents out of custom commands.
# Declare functions in a GPT step
- Type / in the chat and click Create, or open a command you made and edit it.
- In a GPT step, under run options, click the wrench button, Functions.
- Write your declaration in function declaration: one JSON object, or several in an array. HARPA starts you off
with a
get_stock_priceexample. - Pick the function call mode:
| Mode | What the AI does |
|---|---|
| None | Doesn't call a function |
| Auto | Calls a function or answers with text, as it sees fit |
| Required | Always calls the first function |
Each declaration needs a name and a description, and usually parameters, a JSON Schema of the arguments. The
format is OpenAI's: see OpenAI's function calling guide.
The line under the field says whether your JSON is valid; an invalid declaration is ignored.
{
"name": "get_current_weather",
"description": "Get the current weather in a city",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "The city, e.g. Berlin" },
"unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }
},
"required": ["location", "unit"]
}
}
enum limits a value to a fixed list. The description fields matter most: the AI chooses by them.
# Use the function the AI picked
The step stores the AI's choice in two parameters, named after the step's parameter (gpt by default):
| Parameter | Holds |
|---|---|
{{gptFunc}} | The name of the function the AI called |
{{gptArgs}} | Its arguments, e.g. {{gptArgs.location}} |
{{gpt}} | The text answer, if the AI answered instead |
Rename the step's parameter to weather and they become {{weatherFunc}} and {{weatherArgs}}.
To act on the choice, add a Group step per function and give it a run condition (the condition icon on the step):
{{gptFunc}} = get_current_weather
Inside the group, add the steps that do the work: fetch a page with {{page URL}},
search with {{serp query}}, call a Request step, or send the arguments to another GPT step. More on groups
and conditions in Conditions and jumps.
# Example: a Spanish tutor
The command takes any text. English gets translated into Spanish; Spanish gets a grammar check.
- Add an Ask step that stores your text in
{{text}}. - Add a GPT step with the prompt
{{text}}, turn on Functions, set function call to Auto, and declare two functions:
[
{
"name": "translate",
"description": "The text is in English: translate it into Spanish.",
"parameters": {
"type": "object",
"properties": { "text": { "type": "string", "description": "The text I sent." } },
"required": ["text"]
}
},
{
"name": "grammar_check",
"description": "The text is in Spanish: check its grammar and spelling.",
"parameters": {
"type": "object",
"properties": { "text": { "type": "string", "description": "The text I sent." } },
"required": ["text"]
}
}
]
- Add two Group steps with the conditions
{{gptFunc}} = translateand{{gptFunc}} = grammar_check. - In each group, add a GPT step that works on
{{gptArgs.text}}, for example:
Act as a Spanish teacher. Translate the text into Spanish, show the translation in a
code block, then explain the main grammar choices in short bullet points.
Text: "{{gptArgs.text}}"
Act as a Spanish teacher. Show the corrected text in a code block, then list each
mistake in English in short bullet points.
Text: "{{gptArgs.text}}"
- Save the command and run it with an English sentence, then with a Spanish one.
# Good to know
- Functions work on HARPA's cloud models that support function calling and on your own API keys. Web session connections, and models without function calling, ignore them.
- A GPT step with functions can also answer in text when the mode is Auto: check
{{gptFunc}}before you use the arguments. - A chunked step keeps only the text answers: use functions on a step that sends one request.