We're going to build a deep reasoning research agent that attacks ambiguous technical questions with explicit step-by-step logic, then critiques its own work before returning a final answer. This kind of system is useful when you need transparent, auditable decisions rather than a black box guess.
What you'll need
- Python 3.10 or higher
- An Oxlo.ai API key from https://portal.oxlo.ai
- The OpenAI SDK:
pip install openai
Step 1: Set up the Oxlo.ai client
Before adding logic, verify that the OpenAI SDK can reach Oxlo.ai. The client instantiation is standard; only the base_url points to Oxlo.ai.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[{"role": "user", "content": "Confirm connection."}],
)
print(response.choices[0].message.content)
Step 2: Design the reasoning prompt
A deep reasoning system lives or dies by its prompt structure. I force the model to separate observations from conclusions so it cannot anchor on an early guess. Store this as a module-level constant so you can version it in git.
SYSTEM_PROMPT = """You are a deep reasoning research agent. Answer complex questions through explicit, verifiable reasoning.
Follow this exact format:
REASONING_STEPS:
1. [First principled observation]
2. [Logical deduction or calculation]
3. [Consideration of edge cases or alternatives]
... add steps as needed
INITIAL_ANSWER:
[Your tentative conclusion based only on the steps above]
SELF_CRITIQUE:
[Identify the weakest step, any unsupported assumptions, or missing context]
FINAL_ANSWER:
[Your refined answer after addressing the critique]
Rules:
- Do not skip REASONING_STEPS or SELF_CRITIQUE.
- If you lack information, state exactly what is missing rather than guessing.
- Use precise, technical language.
"""
Step 3: Generate the initial reasoning trace
Pass the prompt and a hard question to the model. I use kimi-k2.6 on Oxlo.ai because it handles long chain-of-thought traces well, and the flat per-request pricing means a verbose reasoning block does not inflate the bill.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
SYSTEM_PROMPT = """You are a deep reasoning research agent. Answer complex questions through explicit, verifiable reasoning.
Follow this exact format:
REASONING_STEPS:
1. [First principled observation]
2. [Logical deduction or calculation]
3. [Consideration of edge cases or alternatives]
... add steps as needed
INITIAL_ANSWER:
[Your tentative conclusion based only on the steps above]
SELF_CRITIQUE:
[Identify the weakest step, any unsupported assumptions, or missing context]
FINAL_ANSWER:
[Your refined answer after addressing the critique]
Rules:
- Do not skip REASONING_STEPS or SELF_CRITIQUE.
- If you lack information, state exactly what is missing rather than guessing.
- Use precise, technical language.
"""
question = (
"A distributed system has three nodes. Network partitions can occur between any two nodes. "
"What is the minimum number of distinct partition scenarios I need to model to guarantee "
"coverage of all single and dual partition events? Explain your reasoning."
)
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
],
)
draft = response.choices[0].message.content
print(draft)
Step 4: Critique with a second pass
Self-critique inside a single prompt helps, but a stronger pattern is an external verification pass where a fresh context reviews the draft. Because Oxlo.ai charges a flat rate per request, the second call costs the same as the first, so I do not hesitate to add this layer.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
SYSTEM_PROMPT = """You are a deep reasoning research agent. Answer complex questions through explicit, verifiable reasoning.
Follow this exact format:
REASONING_STEPS:
1. [First principled observation]
2. [Logical deduction or calculation]
3. [Consideration of edge cases or alternatives]
... add steps as needed
INITIAL_ANSWER:
[Your tentative conclusion based only on the steps above]
SELF_CRITIQUE:
[Identify the weakest step, any unsupported assumptions, or missing context]
FINAL_ANSWER:
[Your refined answer after addressing the critique]
Rules:
- Do not skip REASONING_STEPS or SELF_CRITIQUE.
- If you lack information, state exactly what is missing rather than guessing.
- Use precise, technical language.
"""
VERIFIER_PROMPT = """You are a logic verifier. Review the reasoning trace below.
Identify any logical fallacies, unsupported assumptions, or calculation errors.
Rate overall argument strength from 1 to 10. Be concise and specific."""
question = (
"A distributed system has three nodes. Network partitions can occur between any two nodes. "
"What is the minimum number of distinct partition scenarios I need to model to guarantee "
"coverage of all single and dual partition events? Explain your reasoning."
)
# Generate draft
r1 = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
],
)
draft = r1.choices[0].message.content
# Verify draft
r2 = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": VERIFIER_PROMPT},
{"role": "user", "content": f"Question: {question}\n\nDraft:\n{draft}"},
],
)
critique = r2.choices[0].message.content
print("=== DRAFT ===")
print(draft)
print("\n=== VERIFICATION ===")
print(critique)
Step 5: Package the agent
Finally, add a synthesis pass that incorporates the critique to produce a polished answer. The result is a three-step deep reasoning pipeline: draft, verify, refine. Because Oxlo.ai has no cold starts on popular models, this sequential chain executes without latency penalties between requests.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
SYSTEM_PROMPT = """You are a deep reasoning research agent. Answer complex questions through explicit, verifiable reasoning.
Follow this exact format:
REASONING_STEPS:
1. [First principled observation]
2. [Logical deduction or calculation]
3. [Consideration of edge cases or alternatives]
... add steps as needed
INITIAL_ANSWER:
[Your tentative conclusion based only on the steps above]
SELF_CRITIQUE:
[Identify the weakest step, any unsupported assumptions, or missing context]
FINAL_ANSWER:
[Your refined answer after addressing the critique]
Rules:
- Do not skip REASONING_STEPS or SELF_CRITIQUE.
- If you lack information, state exactly what is missing rather than guessing.
- Use precise, technical language.
"""
VERIFIER_PROMPT = """You are a logic verifier. Review the reasoning trace below.
Identify any logical fallacies, unsupported assumptions, or calculation errors.
Rate overall argument strength from 1 to 10. Be concise and specific."""
SYNTHESIS_PROMPT = """You are a synthesis editor. Given the original question, the draft reasoning, and the verifier critique, produce a final polished answer. Preserve the reasoning steps but correct any errors identified in the critique. Output in the same format: REASONING_STEPS, FINAL_ANSWER."""
def deep_reason(question: str) -> str:
r1 = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
],
)
draft = r1.choices[0].message.content
r2 = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": VERIFIER_PROMPT},
{"role": "user", "content": f"Question: {question}\n\nDraft:\n{draft}"},
],
)
critique = r2.choices[0].message.content
r3 = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": SYNTHESIS_PROMPT},
{"role": "user", "content": f"Question: {question}\n\nDraft:\n{draft}\n\nCritique:\n{critique}"},
],
)
final = r3.choices[0].message.content
return final
question = (
"A distributed system has three nodes. Network partitions can occur between any two nodes. "
"What is the minimum number of distinct partition scenarios I need to model to guarantee "
"coverage of all single and dual partition events? Explain your reasoning."
)
print(deep_reason(question))
Run it
Save the final script as reasoner.py and run it.
python reasoner.py
The agent prints a structured trace. Here is an excerpt of real output from kimi-k2.6 on Oxlo.ai.
REASONING_STEPS:
1. A three-node system has nodes A, B, and C. The possible communication links are AB, AC, and BC: three distinct links.
2. A single partition event is the failure of exactly one link. There are C(3,2) = 3 such scenarios.
3. A dual partition event is the simultaneous failure of exactly two distinct links. There are C(3,2) chosen from the 3 links = 3 such scenarios.
4. The scenario where all three links fail is a triple partition, which the problem excludes.
5. Total distinct scenarios = single + dual = 3 + 3 = 6.
INITIAL_ANSWER:
6 scenarios.
SELF_CRITIQUE:
The calculation assumes links fail independently and that order does not matter. This is standard for network partitions, but the problem does not explicitly state independence. However, because it asks for distinct partition scenarios rather than temporal sequences, the combinatorial approach holds.
FINAL_ANSWER:
You need to model 6 distinct partition scenarios: 3 single-link partitions and 3 dual-link partitions.
Next steps
Wire this agent into a Slack bot or CI pipeline so it answers architecture questions on demand. You can also swap kimi-k2.6 for deepseek-v3.2 or qwen-3-32b on Oxlo.ai to compare reasoning styles without rewriting any client code.
Top comments (0)