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

# Practical Examples

> Example flows using variables—booking, routing, DTMF, tool testing, web tools, single-prompt agent

## Example 1: Appointment Booking (Flow Agent)

**Goal:** Collect details in a conversation, call a booking API, then confirm.

**Variables:**

* **Custom:** `business_name`, `business_phone`
* **AI extracted (Conversation):** `customer_name`, `appointment_date`, `appointment_time`
* **Toolpath (Tool – Booking API):** After **Test Tool**, use path selector for `booking_id` (`$.data.booking.id`), `confirmation_code` (`$.data.booking.confirmation_code`)
* **Static (Confirmation node):** `confirmation_message` = `"Your appointment at {{business_name}} is confirmed for {{appointment_date}} at {{appointment_time}}. Confirmation code: {{confirmation_code}}"`

**Flow:** Start → Conversation (collect) → Tool (book) → Conversation (confirm) → End. Each step sees system + custom + variables from previous steps.

## Example 2: Customer Support Routing (Flow Agent)

**Goal:** Classify issue and urgency, look up account, then route.

**Variables:**

* **Custom:** `support_hours_start`, `support_hours_end`, `emergency_number`
* **AI extracted:** `issue_type` (enum: billing, technical, general), `urgency_level` (low, medium, high, critical)
* **Toolpath (CRM):** `account_status`, `is_premium`, `customer_id`
* **Static:** `routing_decision` = `"{{issue_type}}_{{urgency_level}}_{{account_status}}"`

Use these in router conditions and transfer nodes.

## Example 3: DTMF Account Verification (Flow Agent)

**Goal:** Capture account number via keypad, call account API, then speak balance or failure.

**Variables:**

* **DTMF (Start):** `account_number`
* **Toolpath (Account API):** `account_verified`, `account_name`, `account_balance`
* **Static:** `verification_success_message` and `verification_failure_message` using `{{account_name}}`, `{{account_balance}}`, `{{account_number}}`

## Example 4: API Tool Testing & Extraction (Flow Agent)

**Goal:** Call a weather API and use response in the next message.

**Steps:**

1. Configure tool (URL, params e.g. `{{user_location}}`, headers).
2. Click **Test Tool** with e.g. `user_location = "New York"`.
3. In path selector: pick `$.current.temperature` → `current_temperature`, `$.current.conditions` → `weather_conditions`, `$.location.city` → `city_name`, `$.forecast[0].high` → `tomorrow_high`.
4. In the next conversation node: `"The current temperature in {{city_name}} is {{current_temperature}}°C with {{weather_conditions}}. Tomorrow's high will be {{tomorrow_high}}°C."`

**Takeaways:** Test first, use path selector, test success and error responses, handle optional fields.

## Example 5: Web Tool Variable Extraction (Flow Agent)

**Goal:** Add to cart via web tool and confirm in a message.

**Steps:**

1. Define **expected response** (object or string). Example object: `{"cart": {"total": 149.99, "item_count": 2, "items": [...], "discount_code": "SAVE10"}}`.
2. In path selector (against that structure): `$.cart.total` → `cart_total`, `$.cart.item_count` → `cart_item_count`, `$.cart.items[0].name` → `first_item_name`, `$.cart.discount_code` → `discount_code`.
3. For string response, use `$` for the full string (e.g. `cart_summary`).

**Message:** `"I've added {{first_item_name}} to your cart. Total: ${{cart_total}}, {{cart_item_count}} items. Code: {{discount_code}}."`

**Web vs API:** Web tools run in the browser; you define expected response and optionally test manually. API tools use **Test Tool** and real response for path selection.

## Example 6: Single Prompt Agent with Variables

**Goal:** Create a simple customer support agent for a restaurant using a single prompt agent (no flow builder).

**Agent type:** Single Prompt Agent

**Step 1: Define custom variables**

In the Variables Panel, create custom variables that act as configuration parameters:

```
restaurant_name: "Bella Italia"
restaurant_phone: "+1 (555) 123-4567"
restaurant_address: "123 Main Street, New York, NY"
opening_time: "11:00 AM"
closing_time: "10:00 PM"
accepts_reservations: true
delivery_available: true
menu_url: "https://bellaitalia.com/menu"
```

**Step 2: Configure the single prompt**

**System prompt:**

```
You are a friendly customer service assistant for {{restaurant_name}}.

Restaurant Information:
- Phone: {{restaurant_phone}}
- Address: {{restaurant_address}}
- Hours: {{opening_time}} to {{closing_time}}
- Menu: {{menu_url}}

Current Context:
- Current time: {{current_time}}
- Current date: {{current_date}}
- Day of week: {{current_weekday}}
- Customer phone: {{user_number}}

Services:
{{#if accepts_reservations}}
- We accept reservations. You can help customers book tables.
{{/if}}
{{#if delivery_available}}
- We offer delivery service.
{{/if}}

Your Role:
- Answer questions about our menu, hours, and location
- Help with reservations and orders
- Be warm, friendly, and professional
- If you don't know something, offer to have someone call them back
```

**Step 3: Available variables**

**Custom (configuration):** `restaurant_name`, `restaurant_phone`, `restaurant_address`, `opening_time`, `closing_time`, `accepts_reservations`, `delivery_available`, `menu_url`

**System:** `current_time`, `current_date`, `current_weekday`, `user_number`, `call_id`, `direction`, and all other system variables

**Not available:** Extracted variables, static variables, or variables from conversation history (single prompt agents don’t have flow nodes).

**Step 4: Example conversation**

**User:** "What time do you close?"

**Agent (using variables):** *"We're open from `{{opening_time}}` to `{{closing_time}}`. Right now it's `{{current_time}}`, so we're currently open!"*

**Rendered:** *"We're open from 11:00 AM to 10:00 PM. Right now it's 2:30 PM, so we're currently open!"*

**Step 5: Updating configuration**

To change hours, update only the custom variables (e.g. `opening_time`, `closing_time`). The agent uses the new values without changing the prompt.

**Step 6: Multi-environment**

Use different custom variable values per location (e.g. NYC vs Boston: different `restaurant_name`, `restaurant_phone`, `restaurant_address`). Same prompt, different configuration.

**Advantages of single prompt agents:** Simple setup, quick deployment, easy updates via variables, multi-environment support, no extraction needed for simple Q\&A.

**When to upgrade to Flow Builder:** When you need to collect customer info, check availability via API, process orders, transfer by intent, or extract structured data from conversations.

**Takeaways:** Custom variables act as configuration; system variables are available; no extraction; use `{{variable_name}}` and `{{#if}}` for conditionals; ideal for straightforward conversational agents and multi-environment configs.

***

See [Extracted Variables](./extracted-variables) for AI/toolpath/DTMF details, [Availability & Context](./availability-and-context) for flow position and [Single Prompt Agent Variables](./availability-and-context#single-prompt-agent-variables), and [Best Practices](./best-practices) for naming and extraction strategy.
