Run Function

Let your AI Agent call a function during a conversation.

Overview

The Run Function action lets your AI Agent call a function mid-conversation. The agent passes in the values the function needs, the function runs in Regal, and the agent gets the result back to use in the call.

Use it to validate what a caller says, look up a record, format a date, or apply a business rule, while keeping the logic in code instead of in the prompt.

Prerequisites

  • An active function. Drafts don't run on live calls.
  • An AI Agent you can edit.

Add the Action to Your Agent

You can add the action yourself or ask Copilot to attach a function to your agent.

  1. Open your AI Agent and go to its actions.

  2. Add a custom action and choose Function as the type.

  3. Select your function. Its inputs appear for mapping.

  4. Map each input (see below).

  5. Save the action.


Map Your Inputs

Each input on the function needs a source. Choose one per input:

SourceUse it when
AI VariableThe agent should collect the value during the conversation, like an email address the caller reads out
Contact AttributeThe value already lives on the contact's profile
Task AttributeThe value comes from the task that started the call
Static ValueThe value is the same on every call

Update Your Agent Prompt

Tell your agent when to call the function and what to do with the result. For example:

When the caller gives you an email address, call Validate Email. If validated_email
is empty, ask the caller to repeat it. Otherwise, continue with the validated address.

Use the Output

After the function runs, its output fields are available to your agent for the rest of the conversation. To reuse a value later in the call, such as in branching logic or another action, map it with Response Mapping.

Map the Response

Response mapping maps parts of the function's response to the contact data used on the call. Once mapped, you can reference a value later in the call with the same handlebars syntax you use for contact and task attributes. This works the same way as response mappings in custom actions. See Set Contact Data & Response Variables for more on how variables work.

  1. Open the Run Function action on your agent.
  2. In Response Mapping, choose an output field from the function and the variable to map it to.
  3. Save the action.
  4. Reference the variable in your prompt, branching logic, or other actions.

Test Your Setup

  1. Run a test call with your agent and trigger the situation that should call the function.
  2. Confirm the agent calls it and uses the output as expected.
  3. If something looks off, open the function and run it from the Test function drawer with the same inputs.
🚧

Calls always use the latest active version of the function. If you change the function, the next call uses the change.

Troubleshooting & FAQ

My agent isn't calling the function.
Check that your prompt says when to call it, and that the action is saved on the agent.

The function isn't available to select.
Make sure it's activated. Drafts don't appear as live options.

The agent passes the wrong value.
Check the input mapping and the input's description on the function. Add detail to the description if the agent is guessing.

My function returns an error.
Run it from the Test function drawer with the same inputs to see the output or error.

My mapped variable is empty.
Confirm the function returns that output field, and check that the mapping points to the right field. Run the function from the Test function drawer to see its output.


Did this page help you?