Skip to main content
A ready-to-run example is available here!
The route_task_to_model tool (a.k.a. ClassifyAndSwitchLLMTool) lets an agent start on a default LLM profile and switch to a better-suited profile per task. When the agent calls the tool, a lightweight classifier LLM inspects the recent conversation, picks the most suitable saved LLM profile for the task, and switches the conversation to that profile before the agent continues. A meta-profile declaratively describes how to classify a task. It supports two shapes:
  • Structured classes — a fixed set of {description, model} rows; the classifier returns a class index.
  • Direct prompt — a prompt_template rendered with {{ instance_text }} and {{ model_table }}; the classifier returns the model name directly as JSON. This is the shape used by the Pareto prompt meta-profiles.
Both modes require the target models to exist as saved LLM profiles (the tool switches to them by name) or to be supplied inline via meta_profile_llms.

Wiring the tool through settings

Enable the tool and set the active meta-profile on OpenHandsAgentSettings — that is all it takes to wire route_task_to_model into the agent:

Structured-classes meta-profile

The classifier returns a 1-based class index; model is the saved profile name to switch to. classifier_model is itself a saved profile name used to run the classification call.

Direct-prompt meta-profile

Instead of fixed classes, give the classifier a free-form prompt template and a model table. The classifier returns the model name directly as JSON {"model": "<name>", "reason": "..."}.

Ready-to-run Example

This example is available on GitHub: examples/01_standalone_sdk/59_route_task_to_model.py
Route each task to the best LLM profile with the built-in route_task_to_model tool, demonstrating both the structured-classes and direct-prompt meta-profile shapes:
examples/01_standalone_sdk/59_route_task_to_model.py
You can run the example code as-is.
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.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.

Next Steps