The thinking layer adds a context-aware reasoning phase before the model generates its response. The agent analyzes the request, plans its approach, and considers available tools before executing.
Enable Thinking
from definable.agent import Agent
# Simple enable
agent = Agent(model="gpt-4o", thinking=True)
output = await agent.arun("What are the pros and cons of microservices?")
print(output.content)
# Access reasoning steps
for step in output.reasoning_steps:
print(f"[{step.title}] {step.reasoning}")
Custom Configuration
from definable.agent.reasoning import Thinking
agent = Agent(
model="gpt-4o",
thinking=Thinking(
model="gpt-4o-mini", # Cheaper model for thinking
instructions="Focus on trade-offs and practical considerations.",
),
)
Model for the thinking phase. Defaults to the agent’s model.
Custom prompt for the thinking phase.
How It Works
- Before calling the main model, the agent runs a thinking phase.
- The thinking model receives the user message, system prompt, and available tool descriptions.
- It produces reasoning steps (analysis, plan, considerations).
- These steps are injected into the system prompt for the main model call.
- The main model generates its response with the reasoning context.
Streaming Thinking Events
async for event in agent.arun_stream("Explain quantum computing."):
if event.event == "ReasoningStarted":
print("Thinking...")
elif event.event == "ReasoningStep":
print(f" [{event.step.title}] {event.step.reasoning}")
elif event.event == "ReasoningCompleted":
print("Done thinking.\n")
elif event.event == "RunContent" and event.content:
print(event.content, end="", flush=True)
Imports
from definable.agent.reasoning import Thinking