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

# How to Route Calls to the Previously Present Agent

> Ensure calls are routed to the most recent agent who communicated with the client.

> [!NOTE]
>
> Learn how to set up call routing automation that ensures clients are always connected to the last agent they spoke with. This guide walks you through configuring the logic step-by-step, improving customer experience by maintaining continuity and personalizing support with every call.

**User level**: Admin

***

Routing calls to the last agent a client spoke with is a powerful strategy to enhance customer experience. This approach is especially beneficial for businesses with recurring interactions, ongoing support cases, or high-value clients. It builds trust, reduces repetition, and ensures smoother, more personalized conversations -ultimately boosting satisfaction and efficiency.

## How to Set Up Routing to the Last Agent

To implement this use case effectively, the setup involves two key components working together.

* An automation scenario in **CloudTalk Workflow Automation** ensures the agent who last spoke with the client is automatically assigned as their **favorite agent**.

* A routing logic is configured in the **Call Flow Designer** to prioritise connecting incoming calls to this favorite agent.

This two-part setup guarantees both continuity and flexibility in customer interactions.

### Automating Favorite Agent Assignment

1. Navigate to **Cloudtalk Dashboard > Settings > Workflow Automations** and click **`+ Add Workflow`**

2. Select **Call ended** as the [trigger](/en/articles/5648924-triggers) event.

   ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/11948146/91b3ae181800-screenshot-2b2025-08-06-2bat-2b09-13-40.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=e48cd05f247f099a919e268ba4c2776c)

3. Define [conditions](/en/articles/5649346-conditions) to determine when a favorite agent should be assigned. For example, only after an outgoing call where conversation with contact lasted longer than 5 seconds.

   ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/11948146/5e528b162f0c-screenshot-2025-08-06-at-09-25-49.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=4d4a8c6bbd0e818533487db8c3141ab7)

4. To assign a favorite agent to the contact profile, set up an **API Request** to CloudTalk's Edit Contact endpoint. Configure the [API Request action](/en/articles/5649782-actions) using the structure below:

   1. **Endpoint:**\
      `https://api.cloudtalk.io/api/contacts/edit/#{{ event.properties.contacts[0].id }}.json`

   2. **Method:** `POST`

   3. **Headers:**

      * `Authorization: Basic your_encoded_credentials`

      ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/11948146/01f7a1b029b5-screenshot-2b2025-08-07-2bat-2b11-35-21.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=60d495c695947a0939dafa268d0fa750)

   4. **Values:**

      * `name → #{{ event.properties.contacts[0].name }}`

      * `favorite_agent → #{{ event.properties.agent.id }}`

      ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/11948146/4823d2e663e7-screenshot-2b2025-08-06-2bat-2b09-41-34.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=9e528f21cd05d564d88fe4a483733c91)

5. Once all steps are configured, save the setup and activate the workflow to start assigning favorite agents automatically based on your defined conditions.

> [!WARNING]
>
> **Important:** The correct API base URL is `https://api.cloudtalk.io`. Do not use `my.cloudtalk.io`, which is the dashboard host and does not serve the public API.

> [!NOTE]
>
> 💡This setup enables assigning a favorite agent to existing contacts in your contact list. If you also need to assign agents to unknown numbers, please reach out to [CloudTalk Support](https://support.cloudtalk.io/hc/en-us/requests/new?ticket_form_id=26305535257884) for guidance on the required implementation.

### Prioritising Favorite Agent in Call Routing

1. Go to your **CloudTalk Dashboard → Numbers**, and click **+ Configure** (or the flow name) in the **Call Flow** column next to the number you want to apply the routing logic to.

2. Once the Call Flow Designer opens, click the **`+`** button at the appropriate point in your routing sequence and add a **Ring to** step. In the config panel, set **Ring target** to **Favorite agent**. Set the **Ring for** duration and click **Save**.

3. Set up follow-up actions for both **Answered** and **If unanswered** branches, if needed (e.g., forward to team or voicemail).

4. Click **Save** in the top-right corner to make your flow live.

   ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/11948146/2b7e6e5497eb-screenshot-2026-08-19-at-09-25-07.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=fe302f0ee5f4331c729e217b4bfdbbcf)

5. Save you Call flow.

> [!WARNING]
>
> If the contact doesn't have a favorite agent yet, the **Ring to** step (target: *Favorite agent*) will be skipped automatically. The call will then continue with the next step you've set up under the "If unanswered" path in your call flow.

***

*Need help or have a question?* Just reach out through our [Support portal](https://support.cloudtalk.io/hc/en-us/requests/new?ticket_form_id=26305535257884) — we're here for you.


## Related topics

- [Workflow Automations guide](/en/articles/10568412-workflow-automations-guide.md)
- [Call Flow Designer Guide](/en/articles/3669429-call-flow-designer-guide.md)
- [Call Tags](/en/articles/5854602-call-tags.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.