> ## Documentation Index
> Fetch the complete documentation index at: https://docs.theomnibot.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Functions: Connect Agents to External APIs and Flows

> Create AI Functions to let your AI Agents collect data, trigger automation flows, and call external APIs mid-conversation without breaking the chat flow.

AI Functions bridge the gap between an AI Agent's conversational ability and your live business systems. Without them, an Agent can only draw on knowledge it already has. With AI Functions, the Agent can pause mid-conversation, collect whatever information it needs from the customer, trigger a Flow to run an external API call or an automation workflow, and then weave the result back into its reply naturally. For example, when a customer asks *"What's the weather in Hanoi today?"*, an AI Function can fire a Flow that calls a weather API and hand the live data back to the Agent so it replies with the real current conditions.

## How AI Functions Work

1. The Agent recognises that the customer's intent matches an enabled Function's purpose.
2. If the Function requires data (such as a date or email address), the Agent collects it through natural conversation.
3. Once all data is collected, the Agent triggers the linked Flow.
4. The Flow executes — it can save data, fire a webhook, call an external API, or transfer the chat to a human.
5. The result is passed back to the Agent, which rewrites it into a smooth, natural reply.

## How to Create an AI Function

Go to **AI Functions** from the left navigation and click **+ Create AI Function** to open the configuration screen.

| Field                           | Required | Description                                                                                                                                                                                                                                              |
| ------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Name**                        | Yes      | A clear, descriptive name using at least two words (e.g., `get_current_weather`, not `weather`). Use English or unaccented text so the AI can map it reliably.                                                                                           |
| **Purpose**                     | Yes      | Explains to the AI when this Function should be triggered. Write a clear, complete description such as *"Allows users to book a medical appointment"*. You do not need to list required parameters here.                                                 |
| **What data to collect?**       | No       | The parameters the Agent must collect from the customer before running the Flow (e.g., `date`, `email`, `city`). Use meaningful variable names — `email` instead of `collect_1` — so the AI can map chat data correctly.                                 |
| **What is the output message?** | Yes      | The raw result message returned after the Function finishes, such as *"Your appointment has been booked successfully"* or a dynamic variable like `{{data_from_api}}`. The Agent reads this output, rewrites it naturally, and sends it to the customer. |
| **Trigger Flow ID**             | No       | The ID of the Flow to run once all required data has been collected. Inside that Flow you can save data to Custom Fields, call external APIs, or transfer the conversation to a human agent via an Inbox Action.                                         |

<Note>
  The output message is almost never sent word-for-word. The Agent uses it as raw material and rephrases it into a natural conversational reply before sending it to the customer.
</Note>

## Common AI Function Examples

The table below shows five ready-to-use patterns that cover the most frequent business scenarios:

| Example              | Name                     | Purpose                                                     | Data to Collect                                                 | Trigger Flow                                           | Output Message                                                              |
| -------------------- | ------------------------ | ----------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------- |
| **Book Appointment** | `book_appointment`       | Lets users book an appointment                              | `date`, `email`, `reason`                                       | Optional — save booking to CRM                         | Your appointment has been booked successfully.                              |
| **Human Transfer**   | `connect_user_to_human`  | Lets users talk to a real support staff member              | —                                                               | Flow containing an Inbox Action to transfer to human   | You have been connected to a support representative. We will reply shortly. |
| **Weather API**      | `get_current_weather`    | Lets users check the current weather in a specific location | `city`                                                          | Flow containing an External Request to a weather API   | `{{data_from_api}}`                                                         |
| **Email List**       | `join_email_list`        | Lets users subscribe to the email newsletter list           | `email`                                                         | Optional — add contact to email platform               | Subscription successful.                                                    |
| **Shipping Quote**   | `request_shipping_quote` | Lets users request a shipping quote for a parcel            | `origin_address`, `destination_address`, `dimensions`, `weight` | Flow that calculates the quote based on parcel details | `{{quote}}`                                                                 |

## Tips for System Prompt Guidance

The System Message (Prompt) of your AI Agent has a strong influence over how Functions behave. You can use it to pre-guide the data collection process and make conversations feel more natural.

<Tip>
  If you have a restaurant booking Function, add a note to your Agent's System Message like: *"When a user wants to book a table, always ask for the expected time and the number of guests first."* This helps the Agent proactively gather all required data in the right order instead of asking several follow-up questions.
</Tip>

You can also instruct the Agent on tone and sequencing — for example, telling it to confirm collected details with the customer before actually triggering a booking or order Function.

## Enabling and Linking a Function to an Agent

<Steps>
  <Step title="Enable the Function">
    In the AI Functions list, make sure the toggle for your Function is set to **Enabled**.
  </Step>

  <Step title="Open the Agent configuration">
    Go to **AI Agents**, find the Agent that should use this Function, and open its settings.
  </Step>

  <Step title="Attach the Function">
    In the Agent's tools section, select the AI Function you created to link it to the Agent. The Agent will now consider this Function whenever a matching customer intent is detected.
  </Step>

  <Step title="Save">
    Click **Confirm** (or **Save**) to apply the changes.
  </Step>
</Steps>

<Warning>
  If you delete a Flow that is referenced by an AI Function's Trigger Flow ID, the Function will fail to execute when triggered. Always update or re-link the Function before removing the associated Flow.
</Warning>
