---
title: "How to build an AI agent that checks order status and processes refunds"
description: "Build an AI agent that handles order status and refunds by defining four custom tools—get order, check eligibility, initiate refund, update ticket—using Twilio Agent Connect’s function tool decorator to call existing APIs. The agent verifies identity with Twilio Verify’s one-time passcode before any refund, enforced in both prompt and code to prevent prompt injection bypass. Refund decisions are grounded in the company’s return policy from Enterprise Knowledge, while hard rules like return windows are enforced in eligibility tool code to avoid hallucinations. High-value or repeat requests escalate to a human in Twilio Flex via Agent Connect’s handoff tool, which packages conversation ID and reason with an AI-generated summary. The same agent works across voice, SMS, WhatsApp, RCS, and chat through a single handler, with ConversationRelay providing median latency under 0.5 second and Conversation Memory recording outcomes for future context."
---

# How to build an AI agent that checks order status and processes refunds

[Twilio](https://yomu.fyi/company/twilio) · Jesse Sumrak · Oct 22, 2026

**Type:** Tutorial

## Summary

Build an AI agent that handles order status and refunds by defining four custom tools—get order, check eligibility, initiate refund, update ticket—using Twilio Agent Connect’s function tool decorator to call existing APIs. The agent verifies identity with Twilio Verify’s one-time passcode before any refund, enforced in both prompt and code to prevent prompt injection bypass. Refund decisions are grounded in the company’s return policy from Enterprise Knowledge, while hard rules like return windows are enforced in eligibility tool code to avoid hallucinations. High-value or repeat requests escalate to a human in Twilio Flex via Agent Connect’s handoff tool, which packages conversation ID and reason with an AI-generated summary. The same agent works across voice, SMS, WhatsApp, RCS, and chat through a single handler, with ConversationRelay providing median latency under 0.5 second and Conversation Memory recording outcomes for future context.

## Approach / What changed

Define four custom function tools (get order status, check refund eligibility, initiate refund, update ticket) via Twilio Agent Connect’s @function\_tool decorator. Add Twilio Verify one-time passcode before refund. Load return policy into Enterprise Knowledge base for grounding. Enforce hard rules in tool code. Set auto-approval thresholds and escalate high-value/repeat requests via Agent Connect handoff to Twilio Flex. Use a single message handler for all channels with ConversationRelay for voice.

## Takeaways

- The agent must verify customer identity via one-time passcode (Twilio Verify) before processing refunds, enforced both in prompt and in refund tool code to prevent prompt injection.
- Policy grounding alone is insufficient; hard rules like return windows must be enforced directly in eligibility tool code to prevent AI hallucinations from issuing incorrect refunds.
- Start deployment with read-only order status before enabling refunds, and set conservative auto-approval thresholds with weekly review of escalated cases to build trust.

## FAQ

### How do you stop an AI agent from issuing fraudulent refunds?

Use Twilio Verify to send a one-time passcode to the customer's phone or email on file before any refund. Pair this with eligibility rules enforced in code and approval limits that escalate high-value or repeat requests to a human.

### Can the same AI agent handle order questions over phone and SMS?

Yes. Twilio Agent Connect routes all channels through a single message handler, so one agent with one set of tools covers voice, SMS, WhatsApp, RCS, and chat. ConversationRelay handles speech for phone calls with sub-second latency.

### What happens when an AI refund agent can't resolve a request?

Agent Connect's built-in handoff tool transfers the conversation to a human in Flex with the conversation ID and escalation reason. With Conversation Intelligence, the human agent receives an AI-generated summary, and the customer stays on the same call or chat.

**Tags:** [AI Agents](https://yomu.fyi/topic/ai-agents), [API](https://yomu.fyi/topic/api), [Customer Service](https://yomu.fyi/topic/customer-service), [Identity Verification](https://yomu.fyi/topic/identity-verification), [Twilio](https://yomu.fyi/topic/twilio)

- Source: [Twilio](https://www.twilio.com/en-us/blog/insights/ai-agent-order-status-refunds)
- Source URL: https://www.twilio.com/en-us/blog/insights/ai-agent-order-status-refunds
- Ingested by Yomu: 2026-10-23T15:00:17.319Z

[Read original post](https://www.twilio.com/en-us/blog/insights/ai-agent-order-status-refunds)
