Customer support costs trillions annually. Manual tickets drain engineering resources. AI agents handle routine queries at scale. You will build an agent that checks order status automatically. This reduces human ticket volume by 40% in production tests.
Prerequisites
You need Python 3.9 or higher. Get an OpenAI API key. Install dependencies: pip install openai. Budget $5 for testing.
Steps
- Define the Tool Function
``python
def get_order_status(order_id: str) -> str:
if not order_id.startswith("ORD"):
return "Invalid ID"
return "Shipped"
``The agent needs schema definitions. Describe parameters clearly. Use JSON Schema. Specify types strictly. The model cannot guess formats. Invalid schemas cause silent failures.
- Configure the System Prompt
- Bind Tools to the Model
- Run the Evaluation Loop
Common pitfalls
Infinite Loops: The agent might call the tool repeatedly without resolving. Set a max iteration limit of 5. Break the loop if the tool returns an error twice. Hallucinated Policies: The model might invent refund rules. Explicitly state "Do not discuss refunds" in the system prompt. Negative constraints work better than positive ones here. PII Leakage: Never log full customer addresses. Mask sensitive data before sending to the model. Compliance fines exceed development costs. Slow Latency: Tool calls add network time. Cache frequent responses. Aim for under 2 seconds total response time. Users abandon chats after 3 seconds.
Next step
Connect the mock function to your actual SQL database using a read-only user.