Chain of Thoughts
Set chain_of_thought=True on any ChatConfig to make the model reason step by step
before answering. The feature works identically across all five provider kits —
OpenAI, Anthropic, Google, Ollama, and HuggingFace — with zero adapter changes.
How it works
When chain_of_thought=True, the kit creates a non-mutating copy of the active
RactoPrompt and appends the following constraint to the [CONSTRAINTS] section of
the compiled system prompt:
“Before answering, reason through the problem step by step. State each reasoning step clearly and explicitly, then conclude with your final answer.”
The constraint is added last, after all caller-defined rules, so it never
overrides your own constraints. The original RactoPrompt object is never mutated.
Basic usage
from ractogateway import openai_developer_kit as gpt, RactoPrompt
prompt = RactoPrompt(
role="You are a maths tutor.",
aim="Solve the problem the student gives you.",
constraints=["Show every calculation step.", "Use plain English."],
tone="Patient and encouraging",
output_format="text",
)
kit = gpt.Chat(model="gpt-4o", default_prompt=prompt)
response = kit.chat(gpt.ChatConfig(
user_message="What is 17 × 23?",
chain_of_thought=True,
))
print(response.content)
# "Step 1: Break 17 × 23 into (17 × 20) + (17 × 3).
# Step 2: 17 × 20 = 340.
# Step 3: 17 × 3 = 51.
# Step 4: 340 + 51 = 391.
# Answer: 391."
Works with every kit
Swap gpt for any other kit — the API is identical:
from ractogateway import anthropic_developer_kit as claude
from ractogateway import google_developer_kit as gemini
from ractogateway import ollama_developer_kit as local
from ractogateway import huggingface_developer_kit as hf
config = claude.ChatConfig(user_message="Explain recursion.", chain_of_thought=True)
response = claude.Chat(model="claude-opus-4-6", default_prompt=prompt).chat(config)
Works with streaming
for chunk in kit.stream(gpt.ChatConfig(
user_message="Explain the travelling salesman problem.",
chain_of_thought=True,
temperature=0.4,
)):
print(chunk.delta.text, end="", flush=True)
Tips
Goal |
Setting |
|---|---|
Richer, more expressive reasoning |
Raise |
Long multi-step reasoning chains |
Increase |
Structured final answer only |
Add |
Disable for a specific call |
Simply omit |
ChatConfig field reference
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Inject CoT reasoning instruction |
|
|
|
Raise for richer reasoning traces |
|
|
|
Increase for long reasoning chains |
Implementation details
The helper lives in src/ractogateway/_cot.py:
from ractogateway._cot import apply_chain_of_thought
modified_prompt = apply_chain_of_thought(original_prompt)
# Returns a new RactoPrompt; original_prompt is unchanged
Each kit calls apply_chain_of_thought immediately after resolving the active prompt
(in chat(), achat(), stream(), and astream()), so the constraint is always
present in the compiled system prompt that the adapter receives.