- Notifications
You must be signed in to change notification settings - Fork1k
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue inhttps://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.
frompydantic_aiimportAgentfrompydantic_ai.models.geminiimportGeminiModelfrompydantic_ai.models.googleimportGoogleModelSettingssettings=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.
frompydantic_aiimportAgentfrompydantic_ai.models.googleimportGoogleModelfrompydantic_ai.providers.googleimportGoogleProviderfrompydantic_ai.models.googleimportGoogleModelSettingssettings=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\n$10^{300} = 10^{(3 \\times 100)} = (10^3)^{100}$\n\nNow, calculate $10^3$:\n$10^3 = 10 \\times 10 \\times 10 = 1000$\n\nSo, the comparison is now between:\n$2^{100}$ and $(1000)^{100}$\n\nSince both numbers are raised to the same positive power (100), we just need to compare their bases:\n$2$ 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.12Pydantic AI 0.3.1