
We are going to build a command-line reasoning agent that takes fuzzy, multi-step questions and works through them explicitly before answering. This pattern is useful for developers who need transparent, auditable logic inside research tools, support agents, or code-review pipelines. Instead of guessing how a model reached a conclusion, we will force it to show its work in a structured format we can parse and log.
What you'll need
Python 3.10 or newer installed locally. The OpenAI SDK, which you can install with pip install openai. An Oxlo.ai API key from https://portal.oxlo.ai. Oxlo.ai is a fully OpenAI-compatible inference platform with flat per-request pricing, so long reasoning traces do not inflate your bill the way token-based providers do. You can see exact plan details at https://oxlo.ai/pricing. You will also need a terminal and an internet connection. No GPU is required because Oxlo.ai handles inference on its own infrastructure with no cold starts.
Step 1: Set up the Oxlo.ai client
Before we write any logic, we need to point the OpenAI SDK at Oxlo.ai and confirm the endpoint is alive. I always run a one-line smoke test with a lightweight model so I know my key and network are fine. Using an environment variable keeps the key out of source control.
from openai import OpenAI
import os
# Initialize the client pointing at Oxlo.ai
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY", "YOUR_OXLO_API_KEY")
)
# Quick connectivity check using a lightweight model
ping = client.chat.completions.create(
model="llama-3.3-70b",
messages=[{"role": "user", "content": "Say hello"}]
)
print(ping.choices[0].message.content)
Step 2: Define the reasoning system prompt
The system prompt is the only training we need. By forcing XML tags, we get structured output without touching JSON mode or tool definitions. This keeps the example portable across every model Oxlo.ai hosts, from llama-3.3-70b to kimi-k2.6.
SYSTEM_PROMPT = """You are a careful reasoning assistant. When given a question, follow these rules exactly:
1. First, write a step-by-step chain of thought inside <reasoning> tags.
2. Consider edge cases, definitions, and numerical relationships.
3. Only after you have finished reasoning, write your final answer inside <answer> tags.
4. Do not skip the reasoning section, even if the question seems simple."""
Step 3: Build the reasoning wrapper
Now we wrap the API call in a function so we can swap models easily. I default to kimi-k2.6 because it handles advanced reasoning well, but the same code works for deepseek-v3.2 or qwen-3-32b on Oxlo.ai. I set temperature to 0.2 because we want creative problem solving without randomness.
def deep_reason(question: str, model: str = "kimi-k2.6"):
"""
Send a question to the Oxlo.ai chat endpoint.
Default to kimi-k2.6 for advanced reasoning.
"""
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
],
temperature=0.2,
)
return response.choices[0].message.content
Step 4: Parse and display the response
Raw text is fine for a tutorial, but I want to see the reasoning separate from the answer. A small regex parser does the job. If the model ever forgets the tags, we fall back to printing the raw response so nothing is lost. This is simpler than strict JSON mode and survives minor formatting variations.
import re
def show_answer(raw: str):
"""
Extract <reasoning> and <answer> blocks from the model output.
Falls back to raw text if parsing fails.
"""
reasoning = re.search(r"<reasoning>(.*?)</reasoning>", raw, re.DOTALL)
answer = re.search(r"<answer>(.*?)</answer>", raw, re.DOTALL)
if reasoning:
print("=== REASONING ===")
print(reasoning.group(1).strip())
if answer:
print("\n=== ANSWER ===")
print(answer.group(1).strip())
if not reasoning and not answer:
# If the model ignored the format, print everything
print(raw)
Step 5: Test with a complex problem
Finally, we feed it a classic cognitive reflection problem. These questions are useful because the intuitive answer is wrong, and the correct answer requires careful algebra. This is exactly where deep reasoning models shine. If the model rushes, the system prompt will usually nudge it back into step-by-step thinking.
if __name__ == "__main__":
# A classic cognitive reflection test.
# The intuitive answer is $1, but the correct answer requires algebra.
question = (
"A bat and a ball cost $11 total. The bat costs $10 more than the ball. "
"How much does the ball cost? Explain your reasoning carefully."
)
raw_output = deep_reason(question, model="kimi-k2.6")
show_answer(raw_output)
Run it
Save the complete script as reasoner.py and run it from your terminal. Here is the full file for copy and paste convenience.
from openai import OpenAI
import os
import re
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY", "YOUR_OXLO_API_KEY")
)
SYSTEM_PROMPT = """You are a careful reasoning assistant. When given a question, follow these rules exactly:
1. First, write a step-by-step chain of thought inside <reasoning> tags.
2. Consider edge cases, definitions, and numerical relationships.
3. Only after you have finished reasoning, write your final answer inside <answer> tags.
4. Do not skip the reasoning section, even if the question seems simple."""
def deep_reason(question: str, model: str = "kimi-k2.6"):
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
],
temperature=0.2,
)
return response.choices[0].message.content
def show_answer(raw: str):
reasoning = re.search(r"<reasoning>(.*?)</reasoning>", raw, re.DOTALL)
answer = re.search(r"<answer>(.*?)</answer>", raw, re.DOTALL)
if reasoning:
print("=== REASONING ===")
print(reasoning.group(1).strip())
if answer:
print("\n=== ANSWER ===")
print(answer.group(1).strip())
if not reasoning and not answer:
print(raw)
if __name__ == "__main__":
question = (
"A bat and a ball cost $11 total. The bat costs $10 more than the ball. "
"How much does the ball cost? Explain your reasoning carefully."
)
raw_output = deep_reason(question)
show_answer(raw_output)
Execute the script after exporting your key.
export OXLO_API_KEY="sk-..."
python reasoner.py
You should see output similar to this.
=== REASONING ===
Let the cost of the ball be x dollars.
Then the bat costs x + 10 dollars.
Total cost: x + (x + 10) = 11
2x + 10 = 11
2x = 1
x = 0.5
So the ball costs $0.50 and the bat costs $10.50.
The difference is $10.00, and the total is $11.00. This checks out.
=== ANSWER ===
The ball costs $0.50.
Next steps
First, replace the regex parser with Pydantic validation if you want to productionize this. Second, add a loop that lets the user ask follow-up questions. Because Oxlo.ai does not charge by the token, multi-turn conversations with long context windows stay predictable. You can also compare how qwen-3-32b, deepseek-v3.2, and kimi-k2.6 reason through the same problem without worrying about prompt length driving up cost. Since Oxlo.ai is a drop-in OpenAI SDK replacement, moving from a prototype script to a deployed endpoint only takes a few minutes.

