Skip to content

use unified thinking for pydantic-ai#9477

Merged
Light2Dark merged 1 commit into
mainfrom
sham/use-pydantic-ai-unified-thinking
May 7, 2026
Merged

use unified thinking for pydantic-ai#9477
Light2Dark merged 1 commit into
mainfrom
sham/use-pydantic-ai-unified-thinking

Conversation

@Light2Dark
Copy link
Copy Markdown
Collaborator

@Light2Dark Light2Dark commented May 7, 2026

📝 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

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 7, 2026 9:00pm

Request Review

@Light2Dark Light2Dark marked this pull request as ready for review May 7, 2026 21:40
Copilot AI review requested due to automatic review settings May 7, 2026 21:40
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Loading

@Light2Dark Light2Dark added the bug Something isn't working label May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_settings and 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-slim lower 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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude 3.5 and below aren't even available anymore by Claude

Comment thread pyproject.toml
@Light2Dark Light2Dark merged commit 6b8d3d1 into main May 7, 2026
58 of 60 checks passed
@Light2Dark Light2Dark deleted the sham/use-pydantic-ai-unified-thinking branch May 7, 2026 22:25
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.6-dev17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please update to support Claude Opus 4.7

3 participants