How It Works
Named LLM configurations are defined in theconfig.toml
file using sections that start with llm.
. For example:
[llm]
section and can override any of those settings. You can define as many custom configurations as needed.
Using Custom Configurations
With Agents
You can specify which LLM configuration an agent should use by setting thellm_config
parameter in the agent’s configuration section:
Configuration Options
Each named LLM configuration supports all the same options as the default LLM configuration. These include:- Model selection (
model
) - API configuration (
api_key
,base_url
, etc.) - Model parameters (
temperature
,top_p
, etc.) - Retry settings (
num_retries
,retry_multiplier
, etc.) - Token limits (
max_input_tokens
,max_output_tokens
) - And all other LLM configuration options
Use Cases
Custom LLM configurations are particularly useful in several scenarios:- Cost Optimization: Use cheaper models for tasks that don’t require high-quality responses, like repository exploration or simple file operations.
- Task-Specific Tuning: Configure different temperature and top_p values for tasks that require different levels of creativity or determinism.
- Different Providers: Use different LLM providers or API endpoints for different tasks.
- Testing and Development: Easily switch between different model configurations during development and testing.
Example: Cost Optimization
A practical example of using custom LLM configurations to optimize costs:- Repository exploration uses a cheaper model since it mainly involves understanding and navigating code
- Code generation uses GPT-4 with a higher token limit for generating larger code blocks
- The default configuration remains available for other tasks
Custom Configurations with Reserved Names
OpenHands can use custom LLM configurations named with reserved names, for specific use cases. If you specify the model and other settings under the reserved names, then OpenHands will load and them for a specific purpose. As of now, one such configuration is implemented: draft editor.Draft Editor Configuration
Thedraft_editor
configuration is a group of settings you can provide, to specify the model to use for preliminary drafting of code edits, for any tasks that involve editing and refining code. You need to provide it under the section [llm.draft_editor]
.
For example, you can define in config.toml
a draft editor like this:
- Uses GPT-4 for high-quality edits and suggestions
- Sets a low temperature (0.2) to maintain consistency while allowing some flexibility
- Uses a high top_p value (0.95) to consider a wide range of token options
- Disables presence and frequency penalties to maintain focus on the specific edits needed
- Review and suggest code improvements
- Refine existing content while maintaining its core meaning
- Make precise, focused changes to code or text
Custom LLM configurations are only available when using OpenHands in development mode, via
main.py
or cli.py
. When running via docker run
, please use the standard configuration options.