A ready-to-run example is available here!The built-in
route_task_to_model tool (ClassifyAndSwitchLLMTool) lets an agent switch models mid-conversation based on what the current task looks like. When the agent calls the tool, a lightweight classifier LLM inspects the recent conversation, picks the most suitable saved LLM profile, and switches the conversation to that profile before the agent continues. Conversation history and combined usage metrics are preserved across the switch.
This differs from Model Routing, where a Router decides per request based on fixed rules. Here the decision is made by an LLM, and the agent decides when to ask for it.
How It Works
- Save the candidate LLM profiles. The tool switches profiles by name, so every model it can choose must exist in the
LLMProfileStore, or be supplied inline (see below). - Define a meta-profile. A
MetaProfilenames the classifier profile and describes how to map a task to a target profile. - Enable the tool on the agent. Set
enable_classify_and_switch_llm_tool=TrueonOpenHandsAgentSettingsand pointactive_meta_profile(ormeta_profile) at the routing configuration. - Let the agent call it. The agent starts on its configured LLM and switches only when it invokes
route_task_to_model.
Meta-Profile Shapes
AMetaProfile supports two mutually exclusive routing modes.
Structured classes
Provide a fixed set of task categories. The classifier is shown the categories and returns the number of the best match; the tool switches to that class’smodel, which is a saved profile name.
Direct prompt
Provide a free-formprompt_template instead of classes. The template must contain {{ instance_text }} (the recent conversation) and may contain {{ model_table }} (the model_table text). The classifier is expected to return JSON with a model field naming a saved profile:
Where Meta-Profiles Come From
Meta-profiles are stored by name in~/.openhands/meta-profiles and managed with MetaProfileStore. The tool resolves its configuration lazily, at invocation time, in this order:
- If
active_meta_profileis set, the store is authoritative and the meta-profile is loaded by name. - If the store cannot resolve that name, or no name is set, the inline
meta_profilefrom the agent settings is used. Cloud runtimes rely on this because their ephemeral filesystem has no meta-profile store. - If neither applies, the alphabetically first meta-profile in the store is used.
LLMProfileStore, or from the meta_profile_llms map on the settings when supplied inline.
If the classifier returns no usable answer, or names a profile that does not exist, the tool returns an error observation instead of silently routing to a default model. The agent sees the failure and can retry.
Enabling the Tool
Wire everything throughOpenHandsAgentSettings:
Ready-to-run Example
This example is available on GitHub: examples/01_standalone_sdk/59_route_task_to_model.py
examples/01_standalone_sdk/59_route_task_to_model.py
The model name should follow the LiteLLM convention:
provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o).
The LLM_API_KEY should be the API key for your chosen provider.Next Steps
- LLM Profile Store - Save and manage the profiles the router chooses between
- Model Routing - Rule-based per-request routing with a
Router - Agent Settings - Configure agents declaratively with
OpenHandsAgentSettings

