How to assign thinking budget to gemini models?

from agno.agent import Agent
from agno.models.google import Gemini
from agno.tools.duckduckgo import DuckDuckGoTools

agent = Agent(
    model=Gemini(id="gemini-2.5-flash"),
    tools=[DuckDuckGoTools()],
    markdown=True,
    debug_mode=True,
)
agent.print_response("give me an update on Israel and Iran war", stream=True)

Hey @Prajwal
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

Hi @Prajwal ! I just released a PR that should make it easier to do this : PR

from agno.agent import Agent
from agno.models.google import Gemini
from agno.tools import python
from agno.tools.yfinance import YFinanceTools
from google.ai.generativelanguage_v1beta import ThinkingConfig
from agno.tools.python import PythonTools

agent = Agent(
    model=Gemini(id="gemini-2.5-flash"),
    tools=[PythonTools()],
    instructions="Use tables to display data. Don't include any other text.",
    markdown=True,
    debug_mode=True,
    monitoring=True,
    thinking_budget=10000,
    include_thoughts=True,
    stream_intermediate_steps=True
)
agent.print_response("write a snake game in python use pyqt for ui", stream=True)
[{
	"resource": "/c:/Users/prajw/Downloads/AI-OS/python-backend/assistant.py",
	"owner": "pyright",
	"code": {
		"value": "reportArgumentType",
		"target": {
			"$mid": 1,
			"path": "/v1.29.4/configuration/config-files/",
			"scheme": "https",
			"authority": "docs.basedpyright.com",
			"fragment": "reportArgumentType"
		}
	},
	"severity": 8,
	"message": "Argument of type \"Literal['exact']\" cannot be assigned to parameter \"count\" of type \"CountMethod | None\" in function \"select\"\n  Type \"Literal['exact']\" is not assignable to type \"CountMethod | None\"\n    \"Literal['exact']\" is not assignable to \"CountMethod\"\n    \"Literal['exact']\" is not assignable to \"None\"",
	"source": "basedpyright",
	"startLineNumber": 82,
	"startColumn": 37,
	"endLineNumber": 82,
	"endColumn": 44,
	"modelVersionId": 67
},{
	"resource": "/C:/Users/prajw/Downloads/AI-OS/python-backend/test.py",
	"owner": "pyright",
	"code": {
		"value": "reportCallIssue",
		"target": {
			"$mid": 1,
			"path": "/v1.29.4/configuration/config-files/",
			"scheme": "https",
			"authority": "docs.basedpyright.com",
			"fragment": "reportCallIssue"
		}
	},
	"severity": 8,
	"message": "No parameter named \"include_thoughts\"",
	"source": "basedpyright",
	"startLineNumber": 16,
	"startColumn": 5,
	"endLineNumber": 16,
	"endColumn": 21,
	"modelVersionId": 104
},{
	"resource": "/C:/Users/prajw/Downloads/AI-OS/python-backend/test.py",
	"owner": "pyright",
	"code": {
		"value": "reportCallIssue",
		"target": {
			"$mid": 1,
			"path": "/v1.29.4/configuration/config-files/",
			"scheme": "https",
			"authority": "docs.basedpyright.com",
			"fragment": "reportCallIssue"
		}
	},
	"severity": 8,
	"message": "No parameter named \"thinking_budget\"",
	"source": "basedpyright",
	"startLineNumber": 15,
	"startColumn": 5,
	"endLineNumber": 15,
	"endColumn": 20,
	"modelVersionId": 104
}]

i copied the entire β€œgemini.py” which have your modifed code

Hey @Prajwal the import looks incorrect. it should be

from google.genai.types import ThinkingConfig

Could you refer again to the PR and take reference from that

Hey @Prajwal The PR is merged. Once released in Agno you should be able to directly use Thinking Budget as shown in cookbook/models/google/gemini/agent_with_thinking_budget.py

1 Like

i get this error

β–°β–±β–±β–±β–±β–±β–± Thinking...
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                                                                ┃
┃ Three missionaries and three cannibals need to cross a river. They have a boat that can carry up to two people at a time. If, at any time, the cannibals outnumber the missionaries on either  ┃
┃ side of the river, the cannibals will eat the missionaries. How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram     ┃
┃                                                                                                                                                                                                ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Traceback (most recent call last):
  File "/home/godboy/Downloads/AI-OS/python-backend/thinking.py", line 28, in <module>
    agent.print_response(task, stream=True)
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/agent/agent.py", line 7086, in print_response
    for resp in self.run(
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/agent/agent.py", line 888, in _run_stream
    for event in self._handle_model_response_stream(
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/agent/agent.py", line 3066, in _handle_model_response_stream
    for model_response_event in self.model.response_stream(
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/models/base.py", line 762, in response_stream
    yield from self.process_response_stream(
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/models/base.py", line 724, in process_response_stream
    for response_delta in self.invoke_stream(
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/models/google/gemini.py", line 281, in invoke_stream
    request_kwargs = self.get_request_params(system_message, response_format=response_format, tools=tools)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/agno/models/google/gemini.py", line 200, in get_request_params
    config["thinking_config"] = ThinkingConfig(**thinking_config_params)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/godboy/Downloads/AI-OS/aios/lib/python3.12/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ThinkingConfig
thinking_budget
  Extra inputs are not permitted [type=extra_forbidden, input_value=1280, input_type=int]
    For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden

after running this code

"""
An example of how to use the thinking budget parameter with the Gemini model.
This requires `google-genai > 1.10.0`

- Turn off thinking use thinking_budget=0
- Turn on dynamic thinking use thinking_budget=-1
- To use a specific thinking token budget (e.g. 1280) use thinking_budget=1280
- Use include_thoughts=True to get the thought summaries in the response.
"""

from agno.agent import Agent
from agno.models.google import Gemini
from dotenv import load_dotenv

load_dotenv()

task = (
    "Three missionaries and three cannibals need to cross a river. "
    "They have a boat that can carry up to two people at a time. "
    "If, at any time, the cannibals outnumber the missionaries on either side of the river, the cannibals will eat the missionaries. "
    "How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram"
)

agent = Agent(
    model=Gemini(id="gemini-2.5-pro", thinking_budget=1280, include_thoughts=True),
    markdown=True,
)
agent.print_response(task, stream=True)

any update on thinking parameter ?

Hi @Prajwal! We are experiencing some issues with gemini-2.5-pro from Gemini API. Temporarily you could try using gemini-2.5-flashmodel and the cookbook should work.

In case you still experience issues try upgrading to latest Agno version. Thanks!

im getting this issue, also i tried with 2.5 flash also i have provided the logs and code above.

i dont know much but i think the new agno update is giving issue in google dependency i have another topic where im getting this error when i add β€œcomposio-agnoβ€œ dependency in my requirement and try to run it in docker.

Hi @Prajwal ! I replied to your other issue as well.

I think just upgrade the google-genai package should solve all issues

yup i did that and now its working.