-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
Thank you for the latest update #907 to support reasoning responses.
I'm still trying to figure out how to filter the thoughts from the responses. I tried both the GeminiModel as well as the Google Model.
With Gemini Model.
from pydantic_ai import Agent from pydantic_ai.models.gemini import GeminiModel from pydantic_ai.models.google import GoogleModelSettings settings = GoogleModelSettings(google_thinking_config={'include_thoughts': True}) agent = Agent(GeminiModel('gemini-2.5-pro-preview-05-06', provider='google-gla'), model_settings=settings) result_sync = agent.run_sync('Which is larger 2^100 or 10^300?') print(result_sync.output)
With Google Model.
from pydantic_ai import Agent from pydantic_ai.models.google import GoogleModel from pydantic_ai.providers.google import GoogleProvider from pydantic_ai.models.google import GoogleModelSettings settings = GoogleModelSettings(google_thinking_config={'include_thoughts': True}) provider = GoogleProvider(api_key='XXXXXX') model = GoogleModel('gemini-2.5-flash', provider=provider) agent = Agent(model, model_settings=settings) result_sync = agent.run_sync('Which is larger 2^100 or 10^300?') print(result_sync.output)
With Gemini Model, I do not see any thoughts in the response, but with the Google Model, I do. But for the Google Model, there is no way to filter the thoughts:
[ModelRequest(parts=[UserPromptPart(content='Which is larger 2^100 or 10^300?', timestamp=datetime.datetime(2025, 6, 18, 11, 47, 43, 437919, tzinfo=datetime.timezone.utc))]), ModelResponse(parts=[TextPart(content="**My Approach to Comparing Exponents**\n\nOkay, here's how I'd tackle the comparison of 2ドル^{100}$ and 10ドル^{300}$. First, the goal is clear: figure out which one is bigger. I immediately note the different bases and exponents, so I need a clever approach.\n\nMy initial thought is to simplify. I can't instantly see a direct comparison, so I look for a way to manipulate them. The exponents, 100ドル$ and 300ドル,ドル jump out. 300 is a multiple of 100, which is useful. I can express 10ドル^{300}$ as $(10^3)^{100},ドル using the rules of exponents.\n\nNow the problem boils down to 2ドル^{100}$ versus $(10^3)^{100},ドル or $(1000)^{100}$. A direct comparison of bases seems possible. Since 1000ドル$ is significantly larger than 2ドル,ドル and both are raised to the same power, 1000ドル^{100}$ is demonstrably bigger.\n\nJust to be thorough, or to have another perspective if the initial method was less obvious, I'd consider using logarithms. If I take the base-10 logarithm of both numbers, I get 100ドル \\log_{10}(2)$ and 300ドル \\log_{10}(10)$. Since $\\log_{10}(2)$ is approximately 0.301, the first simplifies to 30.1. The second is simply 300. The log of 10ドル^{300}$ is vastly larger than the log of 2ドル^{100}$. Because the logarithm is a strictly increasing function, this confirms that 10ドル^{300}$ is the larger number. In this case, I'd probably use the first method as it is more elegant. Either way, 10ドル^{300} > 2^{100}$.\n"), TextPart(content="Let's compare 2ドル^{100}$ and 10ドル^{300}$.\n\nWe can simplify 10ドル^{300}$ by noticing that 300ドル = 3 \\times 100$:\n\n10ドル^{300} = 10^{(3 \\times 100)} = (10^3)^{100}$\n\nNow, calculate 10ドル^3$:\n10ドル^3 = 10 \\times 10 \\times 10 = 1000$\n\nSo, the comparison is now between:\n2ドル^{100}$ and $(1000)^{100}$\n\nSince both numbers are raised to the same positive power (100), we just need to compare their bases:\n2ドル$ vs 1000ドル$\n\nClearly, 1000ドル > 2$.\n\nTherefore, $(1000)^{100} > 2^{100},ドル which means 10ドル^{300} > 2^{100}$.\n\nSo, $\\mathbf{10^{300}}$ is larger.")], usage=Usage(requests=1, request_tokens=19, response_tokens=249, total_tokens=1007, details={'thoughts_tokens': 739, 'text_prompt_tokens': 19}), model_name='models/gemini-2.5-flash-preview-05-20', timestamp=datetime.datetime(2025, 6, 18, 11, 47, 50, 762380, tzinfo=datetime.timezone.utc), vendor_details={'finish_reason': 'STOP'})]
How do I filter the thoughts and with Gemini Models, why am I not getting the thoughts at all?
Example Code
Python, Pydantic AI & LLM client version
Python 3.12
Pydantic AI 0.3.1