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

# Custom Functions

> Create custom functions for your AI agents

## What are Custom Functions?

Custom functions allow you to extend your AI agent's capabilities by integrating with external APIs or writing custom business logic. Unlike built-in functions, custom functions are fully configurable to match your specific needs.

**Three Types:**

* **Pre-Call** - Modify system prompt and metadata before call starts
* **In-Call** - Execute actions during active calls
* **Post-Call** - Process call data after call ends

## Basic vs Advanced Mode

### Basic Mode (API Integration)

Configure functions through a user-friendly interface without writing code.

**Features:**

* API URL configuration
* HTTP method selection (GET, POST, PUT, DELETE)
* Headers and authentication
* Parameter mapping from call data
* Perfect for integrating with existing APIs

### Advanced Mode (Custom Code)

Write Python or JavaScript code for complex business logic.

**Features:**

* Full programming capabilities
* **AI-powered code generation** - Generate functions using AI
* Pre-imported libraries (axios, moment, lodash for post-call)
* Security-validated execution environment
* Complete control over function behavior

<Tip>
  Start with Basic Mode for simple API integrations, then upgrade to Advanced Mode when you need custom logic.
</Tip>

## Function Types Comparison

<CardGroup cols={3}>
  <Card title="Pre-Call Functions" icon="play" href="/agents/functions/custom-functions/pre-call">
    Modify system prompt and metadata before calls start
  </Card>

  <Card title="In-Call Functions" icon="phone" href="/agents/functions/custom-functions/in-call">
    Execute actions during active calls with AI triggers
  </Card>

  <Card title="Post-Call Functions" icon="stop" href="/agents/functions/custom-functions/post-call">
    Process call data and execute business logic after calls
  </Card>
</CardGroup>

## Key Differences

| Feature                  | Pre-Call              | In-Call            | Post-Call         |
| ------------------------ | --------------------- | ------------------ | ----------------- |
| **Execution Time**       | Before call starts    | During active call | After call ends   |
| **Language (Advanced)**  | Python                | Python             | JavaScript        |
| **Description Required** | No                    | Yes (AI trigger)   | No                |
| **Parameters**           | Optional              | Required (typed)   | JSON with mapping |
| **Primary Use**          | Setup & customization | Real-time actions  | Data processing   |

## Common Use Cases

### Pre-Call Functions

* Fetch user preferences from database
* Customize system prompt based on lead data
* Set language and greeting based on region
* Load context from CRM

### In-Call Functions

* Check inventory availability
* Book appointments (non-Cal.com)
* Validate customer data
* Query databases
* Call external APIs during conversation

### Post-Call Functions

* Calculate next date of action (NDOA)
* Update CRM with call results
* Send follow-up emails
* Generate reports
* Trigger workflows based on call outcome

## Getting Started

<Steps>
  <Step title="Choose Function Type">
    Select pre-call, in-call, or post-call based on when you need the function to execute
  </Step>

  <Step title="Select Mode">
    Basic for API integration, Advanced for custom code
  </Step>

  <Step title="Configure Function">
    Set up API details or write code
  </Step>

  <Step title="Test">
    Test your function with sample calls
  </Step>
</Steps>

<Note>
  Advanced mode functions can be generated using AI. Click "Generate with AI" in the code editor!
</Note>

## Variable Mapping

All custom functions can access call data through variable mapping:

**Available Sources:**

* **Call Metadata** - Fields you define (name, email, phone, etc.)
* **Post-Call Variables** - AI-extracted data from conversation
* **Static Values** - Fixed text or numbers

This allows your functions to use real call data when making API calls or executing logic.

## Next Steps

Choose a function type to learn more:

<CardGroup cols={1}>
  <Card title="Pre-Call Functions" icon="play" href="/agents/functions/custom-functions/pre-call">
    Learn about pre-call functions and how to modify prompts
  </Card>

  <Card title="In-Call Functions" icon="phone" href="/agents/functions/custom-functions/in-call">
    Discover how to execute actions during calls
  </Card>

  <Card title="Post-Call Functions" icon="stop" href="/agents/functions/custom-functions/post-call">
    Explore post-call data processing and automation
  </Card>
</CardGroup>
