We are going to build a Socratic tutor agent that guides students through reasoning instead of handing them answers. It maintains conversation history, stays on curriculum, and runs entirely through the Oxlo.ai API. This is useful for edtech teams who want to drop a reasoning layer into an LMS or homework helper without managing token budgets that balloon as student threads get longer.
What you'll need
- An Oxlo.ai API key
- Python 3.10 or newer
- The OpenAI SDK installed with
pip install openai
Step 1: Configure the Oxlo.ai client
First, we configure the client. Oxlo.ai is fully OpenAI SDK compatible, so we only need to change the base URL and plug in our key. I will test connectivity with a quick call to Llama 3.3 70B.
from openai import OpenAI
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key="YOUR_OXLO_API_KEY",
)
# Verify the connection
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
Step 2: Define the Socratic system prompt
The system prompt is the only teacher training the model receives. It enforces Socratic rules: one question at a time, no direct answers, and a tight word limit to keep the student engaged.
SYSTEM_PROMPT = """You are a Socratic tutor for high school physics. Your goal is to help the student discover the answer through guided reasoning. Do not give the final answer directly. Ask one focused question at a time. If the student is stuck, provide a small hint, not the solution. Keep responses under 120 words. Always encourage the student to explain their reasoning."""
Step 3: Build the tutoring engine
Next, we wrap the API call in a small class that appends messages to a history list. Because Oxlo.ai charges per request rather than per token, we can pass the full conversation context every turn without worrying about escalating costs as the thread grows.
class SocraticTutor:
def __init__(self, client, model="llama-3.3-70b"):
self.client = client
self.model = model
self.history = []
def chat(self, user_message):
# Prepend system prompt, then full history, then latest user message
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
messages.extend(self.history)
messages.append({"role": "user", "content": user_message})
response = self.client.chat.completions.create(
model=self.model,
messages=messages,
)
assistant_msg = response.choices[0].message.content
# Store both sides for the next turn
self.history.append({"role": "user", "content": user_message})
self.history.append({"role": "assistant", "content": assistant_msg})
return assistant_msg
Step 4: Prime the session with curriculum context
Before the first student message, we prime the session with a topic and learning objective. This gives the model a concrete thread to pull on for its opening question.
def start_lesson(tutor, topic, objective):
primer = (
f"We are studying {topic}. The learning objective is: {objective}. "
"Ask me one concrete question to start."
)
return tutor.chat(primer)
tutor = SocraticTutor(client, model="llama-3.3-70b")
opening = start_lesson(
tutor,
topic="Newton's Second Law",
objective="Relate net force to acceleration and mass",
)
print(f"Tutor: {opening}")
Step 5: Run the interactive loop
Finally, we wire up a simple REPL loop so a student can type answers and receive guidance. In production, you would replace input() with an HTTP endpoint or WebSocket message.
print("Type your answer, or 'exit' to quit.\n")
print(f"Tutor: {opening}\n")
while True:
user_input = input("Student: ")
if user_input.lower() in {"exit", "quit"}:
break
reply = tutor.chat(user_input)
print(f"Tutor: {reply}\n")
Run it
Here is a sample transcript from a real run against Oxlo.ai. The model keeps its questions focused and refuses to solve the problem for the student.
$ python tutor.py
Tutor: Imagine you push a 10 kg box with a net force of 20 N. What do you think will happen to the box's motion, and why?
Student: it will move at a constant speed of 2 m/s
Tutor: That is a thoughtful guess, but think about what a net force actually does to an object. Does a net force produce constant speed, or does it change something about the motion?
Student: it changes the acceleration?
Tutor: Exactly. Net force causes acceleration. Now, can you use the relationship F equals m times a to calculate the acceleration of the box?
Student: 2 m/s squared
Tutor: Correct. You just applied Newton's Second Law. If the net force doubled but mass stayed the same, what would happen to the acceleration?
Next steps
That is the core of a reasoning tutor. Two concrete extensions you could ship next: integrate Oxlo.ai's JSON mode to parse student answers into structured confidence scores, or stream responses via stream=True so the tutor feels more responsive in a web UI. You can explore flat request-based pricing for these longer sessions at https://oxlo.ai/pricing.
Top comments (0)