Functions

functions.md

Open your agent in the console and select Functions. This panel has three tabs:

  • Functions
  • JSON Web Tokens
  • Caches

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 an SMS
  • transfer the active call

Functions can also use caches. A cache can hold a previous Function result or a token generated by a JSON Web Token configuration.

Functions tab

The Functions tab shows a table with these columns:

  • Name
  • Operation
  • URI
  • DTMF
  • Cache
  • Output
  • Instructions

Available actions:

  • Create
  • Edit
  • Delete

Create or edit a Function

Select Create or Edit to open the Function modal.

Name

Use a short, descriptive name. Keep one action per Function.

Recommended style:

  • lowercase
  • underscores between words

Examples:

  • lookup_order
  • create_callback
  • send_follow_up_sms

Cache

Use the Cache field 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.

DTMF Sequence

This field is optional.

Allowed characters:

  • 0-9
  • *
  • #

Use DTMF when callers should be able to trigger the workflow from the keypad.

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.

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 is useful when the Function returns sensitive or overly detailed data, but the workflow still needs to run.

Scheme

Supported execution schemes:

  • HTTPS
  • HTTP
  • MAILTO
  • SMS
  • TEL

Choose the scheme first. The rest of the form depends on it.

Operation

Operation is used for HTTP and HTTPS.

Supported values:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

URI

In the console, the scheme is selected separately. Enter only the remainder of the URI in the URI field.

Examples:

  • HTTPS: //orders.example.com/status
  • MAILTO: ops@example.com
  • SMS: +15551234567
  • TEL: +15551234567
  • TEL with local extension: 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.

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}

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_id
  • email
  • appointment_date
  • auth_token

For non-HTTP schemes:

  • MAILTO: include subject and body; add cc and bcc when needed
  • SMS: include body
  • TEL: no collected parameters

How Functions behave during a call

  1. The agent identifies a matching Function from the caller's request or a configured DTMF sequence.
  2. The agent collects the required inputs defined in the Parameters editor.
  3. If the Function uses a cache and the cache has a current value, Leilani can reuse that value instead of running the Function again.
  4. Otherwise the Function runs with the selected scheme, URI, headers, and collected inputs.
  5. If a cache is selected, the result is stored there for reuse.
  6. 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 internal services.

General guidance:

  • use GET for lookups
  • use POST, PUT, or PATCH when 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

MAILTO

Use MAILTO when the Function should send an email.

Typical fields:

  • subject
  • body
  • optional cc
  • optional bcc

You can also include default cc or bcc values in the URI field.

SMS

Use SMS when the Function should send a text message.

Typical field:

  • body

Use one destination number per Function.

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:

  • +15551234567
  • 101;phone-context=pbx.example.com

Working with caches and JWTs

Functions often depend on caches and JSON Web Tokens.

Typical pattern:

  1. Create a cache for a token or other reusable artifact.
  2. If the token should be generated automatically, create a JSON Web Token that writes into that cache.
  3. Create a Function that uses that cached value in a header or request body.
  4. If the Function response should also be cached, select a different cache in the Function modal.

See JSON Web Tokens and Caches for the supporting configuration.

Limitations and notes

  • SMTP and SMTPS are not available as execution schemes in the current UI.
  • JSON Filter affects the HTTP request body, not the URI itself.
  • GET and DELETE can derive query parameters from collected inputs, but URI placeholders are more predictable when exact formatting matters.