use unified thinking for pydantic-ai#9477
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
No issues found across 4 files
Architecture diagram
sequenceDiagram
participant Client as Client/UI
participant API as AI Endpoint
participant Factory as ProviderFactory
participant Provider as Provider (OpenAI/Azure/Anthropic/...)
participant Agent as pydantic-ai Agent
participant Model as pydantic-ai Model
participant Profile as ModelProfile
Note over Client,Profile: Unified Thinking Flow (PR introduces _default_thinking pattern)
Client->>API: POST /ai/chat (messages, model config)
API->>Factory: create_agent(model_name, max_tokens, ...)
Factory->>Provider: create_model(max_tokens)
Provider->>Profile: lookup profile(model_name)
Profile-->>Provider: supports_thinking, thinking_always_enabled, etc.
Provider-->>Factory: Model instance (with model-specific settings)
Factory->>Provider: _build_agent_settings(model)
alt Provider is OpenAI/Azure OpenAI
Provider->>Provider: _default_thinking(model)
alt Custom base_url (non-OpenAI endpoint)
Provider-->>Factory: None (suppress thinking)
else Official OpenAI endpoint
Profile-->>Provider: supports_thinking? (from model profile)
alt Profile says supports_thinking or thinking_always_enabled
Provider->>Provider: openai_reasoning_summary = "auto"
Provider-->>Factory: ModelSettings(thinking=True, openai_reasoning_summary="auto")
else Profile does NOT support thinking
Provider-->>Factory: None
end
end
else Provider is Anthropic
Provider->>Provider: _default_thinking(model)
Profile-->>Provider: supports_thinking? (true for all Anthropic models)
Provider-->>Factory: ModelSettings(thinking=True)
end
Factory->>Agent: Agent(model, model_settings=settings, toolsets, instructions, output_type)
Agent-->>Factory: Agent instance
Factory-->>API: Agent instance
Note over API,Agent: Request execution uses the unified thinking setting
API->>Agent: run(message, message_history)
Agent->>Model: generate(messages, model_settings)
Model->>Model: Apply thinking from model_settings
Model-->>Agent: Response with reasoning/thinking steps
Agent-->>API: Streamed response
API-->>Client: StreamingResponse (includes reasoning content)
There was a problem hiding this comment.
Pull request overview
This PR updates marimo’s pydantic-ai integration to use unified thinking settings instead of per-model/provider “thinking” parameters, primarily to support Claude Opus 4.7 (which requires adaptive thinking payloads) and to simplify reasoning configuration across providers.
Changes:
- Introduces agent-level “thinking” settings via
model_settingsand removes provider-specific thinking params (e.g., Anthropic beta thinking config, Google thinking config, OpenAI reasoning effort). - Updates Anthropic model handling to respect pydantic-ai’s profile for sampling restrictions (e.g., Opus 4.7 disallowing temperature).
- Bumps
pydantic-ai-slimlower bounds in dependency groups and expands provider tests to validate unified thinking behavior and Anthropic payload translation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
marimo/_server/ai/providers.py |
Moves “thinking” to agent-level settings and relies on pydantic-ai model profiles; adjusts OpenAI/Azure/Anthropic/Google/Bedrock behavior accordingly. |
tests/_server/ai/test_providers.py |
Reworks tests to assert unified thinking behavior and validates Anthropic thinking payload translation (adaptive vs enabled). |
pyproject.toml |
Bumps pydantic-ai-slim minimum versions in dependency groups to >=1.84.0. |
packages/llm-info/data/models.yml |
Adds Claude Opus 4.7 model metadata (including thinking: true). |
| def _default_thinking(self, model: Model) -> ThinkingLevel | None: | ||
| """Default unified thinking flag. Return None to skip.""" | ||
| del model | ||
| return True |
There was a problem hiding this comment.
claude 3.5 and below aren't even available anymore by Claude
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.6-dev17 |
📝 Summary
Closes #9417 . This avoids specifying thinking and params for individual models.
https://pydantic.dev/docs/ai/advanced-features/thinking/#unified-thinking-settings
📋 Pre-Review Checklist
✅ Merge Checklist