> ## 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.

# A/B Testing

> Route calls to agent versions or languages using call metadata

Advanced A/B Testing routes calls according to customer data instead of relying only on random traffic distribution.

For example, you can send enterprise customers to one agent version, route Hindi-speaking customers to Hindi versions, and use the standard A/B test for everyone else.

## Standard versus Advanced A/B Testing

| Standard A/B Test                                       | Advanced A/B Test                                           |
| ------------------------------------------------------- | ----------------------------------------------------------- |
| Distributes calls between versions by percentage        | Checks call metadata before selecting a version or language |
| Uses the same distribution rules for all eligible calls | Supports ordered `IF`, `ELSE IF`, and `ELSE` rules          |
| Can be used as a fallback after advanced rules          | Can return one target or run a weighted split inside a rule |

Both tests can be enabled at the same time. Advanced rules run first. If no advanced rule matches, CallKaro continues to the standard A/B test and published-version lookup.

## Before you start

* Create the agent versions you want to route calls to.
* Include the values used by your conditions in the call's `metadata` object.

See [Agent Versions](/agents/understanding-the-agent/agent-versions) and [Create Outbound Call](/api-reference/outbound-call) for details.

## Configure an Advanced A/B Test

1. Open your agent.
2. Open **Manage Versions**.
3. Select **Advanced A/B Test**.
4. Enter the condition for the first **IF** block.
5. Choose whether the block returns a **Version** or a **Language**.
6. Select one target, or choose a split and assign percentages to multiple targets.
7. Add **ELSE IF** rules for additional customer groups.
8. Optionally add an **ELSE** block to handle every remaining call.
9. Open **Test & Preview** and enter sample metadata on your conditions.
10. Select **Save & Enable**.

Rules are evaluated from top to bottom. The first matching block wins, and all later blocks are skipped.

## Write conditions

Every comparison must be wrapped in parentheses and must contain at least one `metadata.variable_name` value.

```text theme={null}
(metadata.city == 'Delhi')
```

Combine comparisons by wrapping the complete expression in another pair of parentheses:

```text theme={null}
((metadata.age >= 25) AND (metadata.plan == 'enterprise'))
```

Supported comparison operators:

| Operator | Meaning                  |
| -------- | ------------------------ |
| `==`     | Equal to                 |
| `!=`     | Not equal to             |
| `>`      | Greater than             |
| `<`      | Less than                |
| `>=`     | Greater than or equal to |
| `<=`     | Less than or equal to    |

Use uppercase `AND` or `OR`. Do not mix `AND` and `OR` at the same bracket level; add brackets to make the intended order explicit.

```text theme={null}
((metadata.city == 'Delhi') OR ((metadata.age >= 25) AND (metadata.plan == 'enterprise')))
```

<Note>
  Text comparisons are case-insensitive. Numeric-looking values are compared as numbers. A missing metadata value does not match `==`, `>`, `<`, `>=`, or `<=`, but it does match `!=` when compared with a present value.
</Note>

## Choose what a rule returns

### Return a version

The selected agent version runs the call immediately. This bypasses the standard A/B test and published-version lookup.

Use this when the rule identifies the exact prompt and configuration that should handle the customer.

### Return a language

The rule changes the call language, then CallKaro selects a version using this order:

1. Standard A/B test versions for that language.
2. The published version for that language.
3. The agent's default-language configuration if no suitable version is available.

Use this when multiple versions can handle the selected language.

## Split traffic inside a rule

A matching block can return multiple versions or languages. Assign a percentage to each target; all shares must be whole numbers greater than zero and total exactly 100%.

For example, an enterprise rule could send:

* 70% of matching calls to `Enterprise v2`.
* 30% of matching calls to `Enterprise v3`.

The target is drawn again for each call. Advanced version splits do not keep a customer on the same version for future calls.

## Routing priority

CallKaro resolves the version in this order:

1. A version explicitly supplied with the call request.
2. The first matching Advanced A/B rule.
3. An eligible previous version for repeat-caller handling.
4. The standard ratio-based A/B test for the selected language.
5. The published version for the selected language.
6. The default-language fallback.

An explicitly supplied version always bypasses Advanced A/B Testing.

## Test before enabling

The **Test & Preview** tab evaluates the unsaved rules using sample call metadata. You can enter values manually, use saved metadata presets, or import JSON, CSV, or Excel data.

The preview shows:

* Which rules matched, did not match, or were skipped.
* Which block won.
* The version or language targets returned by that block.
* A sample weighted result when the block contains a split.

The preview uses the same condition grammar and comparison behavior as live call routing.

## Edit or disable the test

Return to **Manage Versions** and select **Edit Advanced A/B Test** to change the rules.

Selecting **Disable** stops rule evaluation but keeps the configuration so it can be enabled again later. Versions referenced by saved rules cannot be deleted or deactivated, even while the test is disabled. Remove the version from every advanced rule before deleting or deactivating it.

## Availability and limitations

<Warning>
  Advanced A/B routing currently applies to direct API calls, regular outbound calls, and inbound agent resolution. Batch calls and WhatsApp agent resolution continue to use their existing version-selection behavior.
</Warning>

* Direct and regular outbound calls can evaluate the `metadata` supplied with the request.
* Inbound routing does not currently receive call metadata. An `ELSE` block provides the most predictable inbound fallback.
* If no rule matches and there is no `ELSE` block, the call continues through standard A/B and published-version resolution.

## Example

Suppose an agent has three active versions:

* `Enterprise English`
* `Standard English`
* `Hindi Sales`

Configure the rules as follows:

| Block   | Condition                               | Return                        |
| ------- | --------------------------------------- | ----------------------------- |
| IF      | `(metadata.plan == 'enterprise')`       | Version: `Enterprise English` |
| ELSE IF | `(metadata.preferred_language == 'hi')` | Version: `Hindi Sales`        |
| ELSE    | No condition                            | Version: `Standard English`   |

For this call metadata:

```json theme={null}
{
  "plan": "enterprise",
  "preferred_language": "hi"
}
```

The first rule wins and the call uses `Enterprise English`. The second rule is not evaluated after the first match.
