DEV Community

shashank ms
shashank ms

Posted on

Introduction to Agentic Workloads for LLM: A Beginner's Guide

We are going to build an inventory agent that processes restocking requests by checking warehouse stock and supplier lead times. It helps operations teams automate routine procurement decisions without maintaining a brittle rules engine. Because the agent makes multiple LLM calls in a single turn, running it on Oxlo.ai keeps costs predictable. Oxlo.ai charges one flat rate per request, so you are not penalized when the agent chains tool calls or handles long context. You can see the exact breakdown at https://oxlo.ai/pricing.

What you will need

Before we start, grab an Oxlo.ai API key from https://portal.oxlo.ai. You also need Python 3.10 or newer and the OpenAI SDK.

pip install openai

Step 1: Set up the Oxlo.ai client

Oxlo.ai exposes a fully OpenAI-compatible endpoint, so we only need to change the base URL and plug in our key.

from openai import OpenAI
import json

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key="YOUR_OXLO_API_KEY"  # Get this from https://portal.oxlo.ai
)

Step 2: Define the agent's tools

The agent needs two functions to do its job: one that looks up current stock and one that checks supplier lead times. In a real deployment these would query your ERP. For this tutorial we will mock them with a dictionary so the code is fully runnable.

def check_inventory(sku: str):
    warehouse = {"WM-2024": 50, "KB-PRO": 1200, "MON-4K": 15}
    return {"sku": sku, "in_stock": warehouse.get(sku, 0)}

def check_lead_time(sku: str):
    suppliers = {"WM-2024": 14, "KB-PRO": 3, "MON-4K": 30}
    return {"sku": sku, "lead_days": suppliers.get(sku, -1)}

tools = [
    {
        "type": "function",
        "function": {
            "name": "check_inventory",
            "description": "Check current stock level for a SKU",
            "parameters": {
                "type": "object",
                "properties": {
                    "sku": {"type": "string", "description": "Stock keeping unit code"}
                },
                "required": ["sku"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "check_lead_time",
            "description": "Check supplier lead time in days for a SKU",
            "parameters": {
                "type": "object",
                "properties": {
                    "sku": {"type": "string", "description": "Stock keeping unit code"}
                },
                "required": ["sku"]
            }
        }
    }
]

Step 3: Write the system prompt

The system prompt is the agent's instruction manual. It tells the model what it controls and how to behave when stock is low.

SYSTEM_PROMPT = """You are an inventory planning agent for a small electronics store. Your job is to process restocking requests from the purchasing manager.

Workflow:
1. Parse the SKU and desired quantity from the user's message.
2. Use check_inventory to see how many units are currently in stock.
3. If the requested quantity is available, confirm the order can be fulfilled immediately.
4. If stock is insufficient, use check_lead_time to find out how long a restock takes.
5. Respond with a concise decision: approve immediate fulfillment, or explain the shortfall and earliest possible date.

Do not guess numbers. Always call the provided tools before giving a final answer."""

Step 4: Build the agent loop

This is the core of the agent. We send the user message to Oxlo.ai with the tool definitions attached. If the model decides it needs data, it returns a tool call, we execute the Python function, and send the result back for the final answer. I am using qwen-3-32b because Oxlo.ai lists it as a strong choice for agent workflows.

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

    # First pass: let the model decide if it needs tools
    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=messages,
        tools=tools,
        tool_choice="auto"
    )

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

    # Execute any tool calls
    if message.tool_calls:
        for tool_call in message.tool_calls:
            name = tool_call.function.name
            args = json.loads(tool_call.function.arguments)

            if name == "check_inventory":
                result = check_inventory(**args)
            elif name == "check_lead_time":
                result = check_lead_time(**args)
            else:
                result = {"error": "Unknown tool"}

            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "name": name,
                "content": json.dumps(result)
            })

        # Second pass: get the final natural language answer
        final = client.chat.completions.create(
            model="qwen-3-32b",
            messages=messages,
            tools=tools
        )
        return final.choices[0].message.content

    return message.content

Run it

Let us test with a request that we know cannot be fulfilled from stock alone. The agent should discover the shortage, look up the lead time, and explain the situation.

request = "I need 200 units of SKU WM-2024 by next Wednesday."
print(run_agent(request))

When I run this, the output looks like the following. Your exact wording may vary, but the facts should match the mock data.

Current stock for WM-2024 is 50 units, which is 150 units short of your request.
Supplier lead time is 14 days.
Because today is not specified, the earliest possible fulfillment would be two weeks from the order date.
Next Wednesday is not possible. I recommend approving a partial shipment of 50 units now and back-ordering the remaining 150 for delivery in 14 days.

Wrap-up and next steps

You now have a working agentic loop on Oxlo.ai. The flat per-request pricing is especially useful here because even this simple interaction triggers two API calls, and real agents often need three or more turns.

Two concrete ways to extend this. First, replace the mock dictionaries with real HTTP requests to your warehouse management system. Second, add a third tool that actually submits a purchase order so the agent can move from advising to acting.

Top comments (0)