Skip to content

How to dynamically change model and tools at runtime in LlmAgent? #3647

@SmartInvoker

Description

@SmartInvoker

📝 Question

Hi team,

I'm trying to dynamically switch the model and modify tools for an LlmAgent during runtime (not at initialization).

For example:

Change agent.model based on user input or callback logic

Add/remove/replace agent.tools after the agent has already been created

Update model configuration (temperature, top_p, etc.) dynamically

Dynamically register MCP servers or LiteLLM models while the app is running

However, I cannot find clear documentation describing:

Which fields of LlmAgent can be safely mutated during runtime?

Whether modifying agent.model inside before_model_callback is officially supported?

Whether modifying agent.tools inside callbacks is guaranteed to work?

Whether the ADK Runtime caches any of these fields, causing dynamic modifications to be ignored?

What is the recommended pattern for supporting runtime model switching or tool switching?

🧪 Example of what I'm trying to do
def before_model(ctx, request):
if ctx.state.use_fast_model:
ctx.agent.model = "gemini-2.0-flash"
else:
ctx.agent.model = "gpt-4o"

# Dynamically override tools
ctx.agent.tools = my_dynamic_tools

return None  # continue model call

I want to confirm whether this is the correct and supported method, or if there is a preferred API for runtime switching.

🙏 What I need

Could the team clarify:

The officially supported way to modify the model and tools during runtime

Whether there is any limitation with ADK’s caching / agent graph

Whether future versions of ADK will provide a built-in runtime switching API

Thank you!

Metadata

Metadata

Labels

answered[Status] This issue has been answered by the maintainercore[Component] This issue is related to the core interface and implementationgoogle support[Status] This issue is hand offed to google support teamquestion[Component] This issue is asking a question or clarification

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions