Open your agent in the console and select Tools. This panel has four tabs:
- Functions
- MCP Servers
- Caches
- JSON Web Tokens
This page documents the Functions tab. Related pages:
What a Function does
A Function lets the agent collect structured inputs, perform an action, and continue the conversation with the result.
Common uses:
- call an external HTTP or HTTPS service
- send an email
- send one or more SMS messages
- transfer the active call
Functions can also use caches. A cache can hold an HTTP or HTTPS Function result, or a token generated by a JSON Web Token configuration.
Functions tab
The Functions tab shows a table with these columns:
NameURIDTMFCacheOutputInstructions
Available actions:
CreateEditDelete
Create or edit a Function
Select Create or Edit to open the Function modal.
When you create a Function, first choose a function type:
- Send a Text Message (SMS)
- Send An Email
- Transfer a Call
- Build a Webhook
The rest of the modal changes based on that type.
Name
Use a short, descriptive name. Keep one action per Function.
Recommended style:
- lowercase
- underscores between words
Examples:
lookup_ordercreate_callbacksend_follow_up_sms
Cache
Use the Cache field for HTTP and HTTPS webhook Functions when the Function result should be stored and reused.
If a valid value is already present in the selected cache, Leilani returns the cached value instead of running the Function again.
Use a separate cache for credentials such as JWTs. Do not use the same cache for both a credential and a Function result.
Cache and output visibility settings do not apply to SMS, email, or TEL transfer Functions.
DTMF Sequence
This field is optional.
Allowed characters:
0-9*#
Use DTMF when callers should be able to trigger the workflow from the keypad.
During a call, Leilani buffers DTMF input and checks for a matching Function after about three seconds without another keypad digit. When a sequence matches, Leilani asks for any missing required details and then runs that Function.
Instructions
Instructions tell the agent when to use the Function.
Write them to specify:
- which caller requests map to this Function
- which details must be collected first
- what outcome the Function supports
Keep this field direct and operational.
Prompt
Prompt is optional.
Use it when the Function result needs to be summarized or constrained before the agent speaks. Prompt is available for HTTP, HTTPS, SMS, and email Functions. TEL transfer Functions do not use a Prompt field.
Examples:
- return the result in one sentence
- mention the status and ETA only
- confirm success and ask the next question
Output Visibility
Enable Hide function output when the agent should not see the raw Function result.
This option is available for HTTP and HTTPS webhook Functions. It is useful when the Function returns sensitive or overly detailed data, but the workflow still needs to run.
Scheme
Supported execution schemes in the current builder:
HTTPSHTTPMAILTOSMSTEL
Choose the scheme first. The rest of the form depends on it.
Operation
Operation is used for HTTP and HTTPS.
Supported values:
GETPOSTPUTPATCHDELETE
URI
For HTTP and HTTPS Functions, the scheme is selected separately. Enter only the remainder of the URI in the URI field.
Examples:
- HTTPS:
//orders.example.com/status - HTTP:
//services.example.com/webhook
For SMS, email, and TEL Functions, the builder exposes purpose-specific fields and formats the destination for the selected channel:
- SMS:
sms:+15551234567,+15557654321 - MAILTO:
mailto:ops@example.com?subject=Call%20summary - TEL:
tel:+15551234567 - TEL with local extension:
tel:101;phone-context=pbx.example.com
JSON Filter
This field is available for HTTP and HTTPS.
Use a JSON Pointer when only part of the collected input should be sent in the request body.
Examples:
/payload/data/items/0/ticket
Use this when the Function collects more information than the remote service needs in the body.
GET and DELETE requests do not send a JSON body. For those methods, collected inputs become query parameters, and existing query parameters from the URI are preserved.
Headers
Headers are used with HTTP and HTTPS.
Use them for:
- authorization
- environment identifiers
- routing headers required by the target service
Header values can reference collected inputs with JSON Pointer placeholders.
Examples:
Bearer {/auth_token}{/order_id}
Headers are normalized to lowercase when saved.
If a collected input is replaced from a cache value, header placeholders see the replaced value.
Parameters (JSON Schema)
The Parameters editor defines the structured inputs the agent must collect before the Function runs.
Use it to define:
- the fields the Function needs
- the type of each field
- which fields are required
Recommended pattern:
- define an object
- describe every field clearly
- mark only required fields as required
- disable extra fields unless they are needed
Typical HTTP or HTTPS Function inputs:
order_idemailappointment_dateauth_token
For message Functions:
- SMS and email use message templates with
{{ field_name }}variables - template variables are used to generate the JSON Schema automatically
- the advanced editor lets you review or override the generated schema
- TEL transfer Functions do not collect model parameters
How Functions behave during a call
- The agent identifies a matching Function from the caller's request or a configured DTMF sequence.
- The agent collects the required inputs defined in the Parameters editor.
- If an HTTP or HTTPS Function uses an output cache and the cache has a current value, Leilani can reuse that value instead of running the Function again.
- Otherwise the Function runs with the selected scheme, URI, headers, and collected inputs.
- If an HTTP or HTTPS output cache is selected, the result is stored there for reuse.
- The agent continues the conversation using the Function result and the optional Prompt field.
Scheme-specific guidance
HTTP and HTTPS
Use HTTP and HTTPS for APIs, webhooks, and company services.
General guidance:
- use
GETfor lookups - use
POST,PUT, orPATCHwhen sending structured data - use header placeholders for tokens and request metadata
- use JSON Filter when the request body should be a nested object
- if exact query formatting matters, put values directly in the URI with placeholders
- use a cache only when a repeated response is safe to reuse
MAILTO
Use MAILTO when the Function should send an email.
The email builder collects:
- recipient email address
- subject
- email body template
- template-derived parameters
Use {{ field_name }} in the body template for values Leilani should collect before sending. The email body is sent as HTML.
SMS
Use SMS when the Function should send a text message.
The SMS builder collects:
- one or more phone numbers
- message template
- template-derived parameters
Separate multiple destination numbers with commas. Use {{ field_name }} in the message template for values Leilani should collect before sending.
TEL
Use TEL when the Function should transfer the active call.
Use either:
- a global number such as
+15551234567 - a local extension with
phone-context
Examples:
+15551234567101;phone-context=pbx.example.com
Local TEL numbers require a phone-context. Global numbers should be E.164-style numbers that start with +.
TEL Functions transfer the current call and do not use parameters, Prompt, cache, or output visibility settings.
Message templates
SMS and email Functions use Minijinja-style templates.
Example SMS template:
Hi {{ first_name }}, your appointment is confirmed for {{ appointment_time }}.
Leilani detects first_name and appointment_time, creates matching string parameters, and asks the caller for those values before running the Function.
If you manually edit the schema and then change the template, the UI warns when template fields and schema fields are out of sync. Use Sync from template when the template should be the source of truth.
Working with caches and JWTs
Webhook Functions often depend on caches and JSON Web Tokens.
There are two separate cache patterns:
- use a Function's Cache field to cache that HTTP or HTTPS Function's output
- use a cache-backed JWT as an input value that can be inserted into headers, bodies, or URI templates
Typical JWT-to-header pattern:
- Create a cache for a token or other reusable artifact.
- If the token should be generated automatically, create a JSON Web Token that writes into that cache.
- Create a Function parameter such as
auth_token. - In the Function instructions, tell Leilani to use the token cache ID as the
auth_tokenvalue. - Reference that parameter in a header, such as
Bearer {/auth_token}. - If the Function response should also be cached, select a different cache in the Function modal.
During calls, a Function can use a cache ID as an input value. If only part of a cached object is needed, append a JSON Pointer after the cache ID.
See JSON Web Tokens and Caches for the supporting configuration.
Limitations and notes
SMTPandSMTPSare not available as execution schemes in the current UI.JSON Filteraffects the HTTP request body, not the URI itself.GETandDELETEcan derive query parameters from collected inputs, but URI placeholders are more predictable when exact formatting matters.- SMS and email body content comes from the Function template, not from a
bodyfield in the URI.