DEV Community

shashank ms
shashank ms

Posted on

Engineering LLM Solutions for Real-World Problems

We are building a support ticket triage agent that reads refund requests, looks up order status via a mock database, and applies a simple policy to either approve or escalate. This kind of tool is ideal for small engineering teams who want to cut first-response time without maintaining a complex rules engine. I am using Oxlo.ai here because its request-based pricing keeps costs flat regardless of prompt length, which matters once you start adding tool schemas and policy documents. Details are at https://oxlo.ai/pricing.

What you'll need

Step 1: Initialize the Oxlo.ai client

I import the OpenAI SDK and point the base URL at Oxlo.ai. Because Oxlo.ai is fully OpenAI SDK compatible, this single line swap is all that is needed to route requests to Oxlo.ai instead of OpenAI.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

Step 2: Define the system prompt

The system prompt encodes the business logic. I keep it explicit so the model does not hallucinate order details or override the refund policy.

SYSTEM_PROMPT = """You are a support agent for an e-commerce store.
You have access to a get_order_status tool.
Policy:
- If the order exists, is delivered, and the refund request is under $50, approve the refund.
- If the refund is $50 or more, or the order is not delivered, escalate to a human.
- Always ask for the order ID if it is missing.
Do not make up order details. Only use data from the tool."""

Step 3: Mock the order database

In production this would query PostgreSQL or Shopify, but a hardcoded dictionary is enough to verify that the agent correctly integrates external data.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = """You are a support agent for an e-commerce store.
You have access to a get_order_status tool.
Policy:
- If the order exists, is delivered, and the refund request is under $50, approve the refund.
- If the refund is $50 or more, or the order is not delivered, escalate to a human.
- Always ask for the order ID if it is missing.
Do not make up order details. Only use data from the tool."""

ORDERS = {
    "ORD-1001": {"status": "delivered", "total": 29.99, "item": "USB-C cable"},
    "ORD-1002": {"status": "shipped", "total": 199.99, "item": "mechanical keyboard"},
    "ORD-1003": {"status": "delivered", "total": 12.50, "item": "screen protector"},
}

def get_order_status(order_id: str):
    return ORDERS.get(order_id, {"error": "Order not found"})

Step 4: Describe the tool schema

Oxlo.ai supports function calling, so I define the JSON schema for get_order_status and pass it with every chat request. This lets the model decide when it needs real data.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = """You are a support agent for an e-commerce store.
You have access to a get_order_status tool.
Policy:
- If the order exists, is delivered, and the refund request is under $50, approve the refund.
- If the refund is $50 or more, or the order is not delivered, escalate to a human.
- Always ask for the order ID if it is missing.
Do not make up order details. Only use data from the tool."""

ORDERS = {
    "ORD-1001": {"status": "delivered", "total": 29.99, "item": "USB-C cable"},
    "ORD-1002": {"status": "shipped", "total": 199.99, "item": "mechanical keyboard"},
    "ORD-1003": {"status": "delivered", "total": 12.50, "item": "screen protector"},
}

def get_order_status(order_id: str):
    return ORDERS.get(order_id, {"error": "Order not found"})

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_order_status",
            "description": "Look up an order by ID and return status, total, and item name.",
            "parameters": {
                "type": "object",
                "properties": {
                    "order_id": {
                        "type": "string",
                        "description": "The order ID, e.g. ORD-1001",
                    }
                },
                "required": ["order_id"],
            },
        },
    }
]

Step 5: Handle tool calls and generate a response

I send the conversation to Qwen 3 32B. If the model requests a tool, I execute the local function, append the result, and send the updated message history back for the final answer.

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = """You are a support agent for an e-commerce store.
You have access to a get_order_status tool.
Policy:
- If the order exists, is delivered, and the refund request is under $50, approve the refund.
- If the refund is $50 or more, or the order is not delivered, escalate to a human.
- Always ask for the order ID if it is missing.
Do not make up order details. Only use data from the tool."""

ORDERS = {
    "ORD-1001": {"status": "delivered", "total": 29.99, "item": "USB-C cable"},
    "ORD-1002": {"status": "shipped", "total": 199.99, "item": "mechanical keyboard"},
    "ORD-1003": {"status": "delivered", "total": 12.50, "item": "screen protector"},
}

def get_order_status(order_id: str):
    return ORDERS.get(order_id, {"error": "Order not found"})

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_order_status",
            "description": "Look up an order by ID and return status, total, and item name.",
            "parameters": {
                "type": "object",
                "properties": {
                    "order_id": {
                        "type": "string",
                        "description": "The order ID, e.g. ORD-1001",
                    }
                },
                "required": ["order_id"],
            },
        },
    }
]

def run_agent(user_message: str) -> str:
    messages = [
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": user_message},
    ]

    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=messages,
        tools=tools,
        tool_choice="auto",
    )

    message = response.choices[0].message
    messages.append(message)

    if message.tool_calls:
        tool_call = message.tool_calls[0]
        function_name = tool_call.function.name
        arguments = json.loads(tool_call.function.arguments)

        if function_name == "get_order_status":
            result = get_order_status(**arguments)
            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "name": function_name,
                "content": json.dumps(result),
            })

        final_response = client.chat.completions.create(
            model="qwen-3-32b",
            messages=messages,
            tools=tools,
        )
        return final_response.choices[0].message.content

    return message.content

if __name__ == "__main__":
    query = "I want a refund for order ORD-1001. It never arrived."
    print(run_agent(query))

Run it

With the agent saved as support_agent.py, I run a quick test. The first query targets a small delivered item that should be approved, and the second targets an expensive shipped item that must be escalated.

$ python support_agent.py
I have reviewed order ORD-1001 for the USB-C cable ($29.99). The order shows as delivered and the refund amount is under $50, so I have approved your refund. You should see the credit within 3 to 5 business days.

$ python -c "from support_agent import run_agent; print(run_agent('I want a refund for order ORD-1002.'))"
I checked order ORD-1002 for the mechanical keyboard ($199.99). Because the order is still in shipped status and the refund amount is $50 or more, I am escalating this to a human agent who can assist you further.

Next steps

Swap the mock ORDERS dict for a real database connection using SQLAlchemy or your existing API, and add retry logic around the Oxlo.ai client. If you need to process screenshots or photos attached to tickets, switch to Kimi K2.6 on Oxlo.ai to handle both vision and reasoning in the same pipeline.

Top comments (0)