ollama/ollama
Thinking
Some models emit reasoning ("thinking") tokens before their actual answer. The thinking/ package isolates that content so the daemon can return it as a separate field and the CLI can render it differently.
Purpose
Keep reasoning content visible without confusing it with the model's final answer. The CLI dims thinking output; API consumers read it from a separate field; tooling can choose to discard it entirely.
Key abstractions
| Symbol | Location | Purpose |
|---|---|---|
| Stream parser | thinking/ |
Detects the start and end of a thinking block in a token stream and emits typed events (thinking-start, thinking-delta, thinking-end). |
Capability thinking |
types/model/capabilities.go |
Models advertise this when their template uses thinking blocks. |
How it works
graph LR
Stream[runner token stream] --> Parser[thinking parser]
Parser -->|inside thinking block| ThinkingDelta[thinking content]
Parser -->|outside| ContentDelta[regular content]The parser uses model-specific delimiters (e.g., <think>...</think> for some models, harmony channels for GPT-OSS-style models). Which delimiters apply is decided by the parser registered for the model family in model/parsers/.
API surface
- Per-request
thinkflag (enable/disable thinking output). Recently extended to accept"max"as a value (api: accept "max" as a think value (#15787)). - Per-response
thinkingfield onChatResponse(api/types.go). - OpenAI compat:
responsesendpoint mapsreasoning_effortto thethinkflag (openai: map responses reasoning effort to think (#15789)).
Integration points
- The daemon checks
model.CheckCapabilities(CapabilityThinking)before handlingthink=true. - The CLI's
ensureThinkingSupport(cmd/cmd.go) warns when the user runs a model that doesn't support thinking. - The OpenAI/Anthropic compat layers translate thinking to/from the right field name (
reasoning_contentfor Anthropic,reasoning_effortfor OpenAI Responses).
Entry points for modification
- New delimiter style → add a model-family parser in
model/parsers/<family>/. - New API surface (e.g., a different
thinkvalue) → extendapi/types.goand the corresponding middleware translator.
Key source files
| File | Purpose |
|---|---|
thinking/ |
Parser for thinking blocks. |
types/model/capabilities.go |
CapabilityThinking. |
cmd/cmd.go |
ensureThinkingSupport warning. |
middleware/openai.go, middleware/anthropic.go |
Compat translation. |
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.