页面简介
Enable thinking and reasoning effort in Pydantic AI with the Thinking capability, or use native settings for OpenAI, Anthropic, Google, Bedrock and more.
正文摘录
Thinking Thinking (or reasoning) is the process by which a model works through a problem step-by-step before providing its final answer. The simplest way to enable thinking across supported providers is the Thinking capability. Provider-specific settings are available for advanced usage when you need direct access to a provider’s native thinking controls. Unified thinking settings Use the Thinking capability to enable thinking: thinking_capability.pyfrom pydantic_ai import Agent from pydantic_ai.capabilities import Thinking agent = Agent('anthropic:claude-opus-5-5', capabilities=[Thinking(effort='high')]) You can also set the underlying thinking field in ModelSettings directly: unified_thinking.pyfrom pydantic_ai import Agent agent = Agent('anthropic:claude-opus-5-5', model_settings={'thinking': 'high'}) The Thinking.effort value accepts: True — enable thinking with the provider’s default effort level False — disable thinking; on a model that can’t turn thinking off, think as little as the model allows (its lowest effort, level, or budget). A model that offers no thinking setting at all keeps its default 'minimal' / 'low' / 'medium' / 'high' / 'xhigh' / 'max' — enable thinking at a specific effort level (unsupported levels map to the closest available value) These are the same values accepted by the underlying thinking model setting. When omitted, the model uses its default behavior. Provider-specific settings (documented in the sections below) take precedence when both are set, except that thinking=False still disables reasoning on Cerebras and on Groq’s qwen3 models. If the provider-specific setting comes from a broader scope than thinking (for example, the model’s settings while thinking comes from this capability, agent.run() or a direct request), a UserWarning names both. Settings given as a callable (dynamic model settings) are not checked, and neither are capability settings, this capability’s thinking included, once any capability’s settings are a callable or are deferred with defer_loading. Readable thinking APIs return the model’s thinking as a summary, as the raw reasoning on some open models, or not at all, and several only return it when asked. The Thinking.summary field, or the underlying thinking_summary model setting, asks for it portably: thinking_summary.pyfrom pydantic_ai import Agent from pydantic_ai.capabilities import Thinking agent = Agent('anthropic:claude-opus-5-5', capabilities=[Thinking(effort='high', summary=True)]) True — ask for readable thinking wherever the API has a switch for it, including on models that think without a thinking setting False — ask the API not to return thinking content where it can. The model still thinks, and is billed for it, as configured by thinking Unset — when thinking enables thinking, summaries are requested where that is safe to do by default: Anthropic, Claude on Bedrock, Google, and Groq. OpenAI’s Responses API is left alone, because reasoning summaries may require organization verification; set True to request them there Provider-specific settings take precedence, with a UserWarning naming both when the provider-specific one comes from a broader scope, as for thinking. Thinking an API returns anyway is never stripped from the response: ProviderUnset, with thinking enabledTrueFalseNotesAnthropic, Bedrock (Claude)thinking.display='summarized'display='summarized'display='omitted'A model that thinks without a thinking setting (Claude Opus 5 and later, Sonnet 5 and later, Haiku 5.5, Fable, and Mythos) gets an explicit {'type': 'adaptive', 'display': ...} when only thinking_summary is set. False still returns the signed thinking blocks, with empty content. display is never added to a disabled or between_tools block. anthropic_thinking_display and bedrock_thinking_display take precedenceGoogleinclude_thoughts=Trueinclude_thoughts=True, also on models that think by defaultinclude_thoughts=False, keeping the level or budgetgoogle_thinking_config takes precedenceGroqreasoning_format='parsed'reasoning_format='parsed'reasoning_format='hidden'Reasoning models only, with or without thinking. groq_reasoning_format takes precedenceOpenAI Responses, Bedrock MantleNot sentreasoning.summary='auto' when the request reasonsNot sentThere is no value that turns summaries off; leaving summary out does. openai_reasoning_summary takes precedenceBedrock (OpenAI GPT-5.6 and GPT-6)Not sentreasoning.summary='auto' unless thinking is offNot sentThe Responses API shape these models take on Converse; the summary comes back as reasoningTextBedrock (OpenAI GPT-OSS)Not sentNot sentinclude_reasoning=FalseAny include_reasoning value, True included, drops the reasoning from the responseCerebrasNot sentNot sentreasoning_format='hidden'Sent for gpt-oss only. Cerebras also documents hidden for GLM 5.3 Flash, which it serves only on dedicated endpoints; Pydantic AI doesn’t send it there. Cerebras’ Qwen, Kimi and Gemma models don’t support hiddenvLLMNot sentNot sentinclude_reasoning=FalseVia extra_body, under any extra_body you setOpenRouterNot sentNot sentreasoning.exclude=TrueAnthropic routes still return the thinking in reasoning_details, which becomes a ThinkingPart. openrouter_reasoning takes precedence The other providers have no such switch, so thinking_summary is ignored there: OpenAI’s Chat Completions API, xAI, Mistral, Cohere, Ollama, DeepSeek, Moonshot AI, Z.AI, Hugging Face, GitHub Copilot, Snowflake Cortex, the Qwen, DeepSeek, Grok, and Magistral models on Bedrock, and realtime models. Provider translation The Thinking capability maps each effort value to the selected provider’s native format. On Anthropic and Claude on Bedrock, the display that comes with it follows thinking_summary: ProviderThinking() / Thinking(effort=True)Thinking(effort='high')NotesAnthropic (adaptive thinking)anthropic_thinking={'type': 'adaptive', 'display': 'summarized'}{type: 'adaptive', display: 'summarized'} + effort='high'Claude Opus 4.7, 4.8, 5, 5.5, Sonnet 5 and 5.5, and Haiku 5.5 also support effort='xhigh'; 'max' → effort='max'. thinking=False → type='disabled' on models that think by default, type='between_tools' on Sonnet 5.5, and {type: 'adaptive'} + effort='low' on Opus 5.5 and the Fable and Mythos models, which can’t turn thinking off (Mythos Preview, which has no effort setting, gets nothing)Anthropic (older)anthropic_thinking={'type': 'enabled', 'budget_tokens': 10000, 'display': 'summarized'}budget_tokens=16384Budget-based; 'low' → 2048 tokens, 'xhigh' and 'max' → 32768. Claude Opus 4.5 also takes an effort up to 'high', so 'xhigh' and 'max' send effort='high'OpenAIreasoning_effort='medium'reasoning_effort='high'Unified efforts map to the closest effort the model accepts: GPT-5.6 and GPT-6 Astra map 'minimal' to 'low', as do GPT-5.1 through GPT-5.5 on OpenAI’s API, the o-series accept low–high, and the -pro models accept only high (GPT-5 Pro) or medium–xhigh. 'max' → reasoning_effort='max' on the Responses API for GPT-5.6 and GPT-6, and 'xhigh' (or the closest accepted effort) everywhere else, including Codex and ChatGPT plan usage: the Chat Completions API rejects 'max'. thinking=False → 'none' where accepted; models that can’t turn reasoning off (the o-series, GPT-5, the -pro models, GPT-6 Astra) get their lowest effort instead (e.g. 'low' on o3, 'minimal' on GPT-5). gpt-5-search-api has no effort setting on OpenAI’s API, so thinking sends nothingGoogle (Gemini 3+, Gemma 4)include_thoughts=Truethinking_level='HIGH'Unified efforts snap to the nearest documented level — e.g. gemini-3.1-flash-lite-image and Gemma 4 (levels: minimal, high) map 'low' to 'MINIMAL' and 'medium'/'xhigh'/'max' to 'HIGH' — and models without minimal map unified 'minimal' to 'LOW'; 'xhigh' and 'max' → 'XHIGH' on gemini-4-hydrogen and gemini-4-neon, and 'HIGH' on models without that level; gemini-3.1-flash-image applies its minimal, high set only on the Gemini API (see Google). thinking=False → the lowest level the model accepts, without include_thoughts ('LOW' on Gemini 3.1 Pro, which can’t turn thinking off on the Gemini API; on Google Cloud it gets thinking_budget=0, which turns thinking off there)Google (Gemini 2.5)include_thoughts=Truethinking_budget=24576'minimal' → thinking_budget=128, or 512 on gemini-2.5-flash-lite on the Gemini API, its minimum there; thinking=False → thinking_budget=0; Gemini 2.5 Pro can’t turn thinking off, so it gets its minimum, thinking_budget=128Groqreasoning_format='parsed' (gpt-oss also reasoning_effort='medium')reasoning_format='parsed' (gpt-oss also reasoning_effort='high')gpt-oss: unified effort → reasoning_effort (low/medium/high, via extra_body); it can’t turn reasoning off, so thinking=False → reasoning_effort='low' with reasoning_format='hidden'; qwen3: thinking=False → reasoning_effort='none' (true disable, via extra_body)Mistralreasoning_effort='high'reasoning_effort='high'Only on adjustable-reasoning models (e.g. mistral-small-latest, mistral-medium-3-5, and magistral-medium-latest and magistral-small-latest, which point at them); dated magistral ids reason always-on and get no reasoning_effort. Small 4 and Medium 3.5 accept only 'high'/'none', so every enabled level (incl. 'minimal') → 'high' and only thinking=False → 'none'; Large 4 (mistral-large-4, mistral-large-4-0, mistral-large-latest) accepts 'low'/'medium'/'high' and can’t turn reasoning off, so False/'minimal'/'low' → 'low', 'medium' → 'medium', and True/'high'/'xhigh'/'max' → 'high'; DeepSeek V4.1 Flash (deepseek-v4-1-flash-1017) reasons only when asked to, so False → 'none', 'minimal'/'low' → 'low', True/'medium'/'high' → 'high', and 'xhigh'/'max' → 'xhigh'; GLM-5.3 (zai-glm-5-3, zai-glm-5-3-flash, zai-glm-5, zai-glm-latest, glm-5-latest) can’t turn reasoning off, so False/'minimal'/'low' → 'low' and every other level → 'high'OpenRouterreasoning={'effort': 'medium', 'enabled': True}reasoning={'effort': 'high', 'enabled': True}thinking=False → effort='none'; routes to models that can’t turn reasoning off ge