π OpenHands: AI-Driven Development
Remove legacy LLMConfig and all related code (#14239)
Tim O'Farrell2ed36cfa7d1a
diff --git a/config.template.toml b/config.template.tomlindex 9756ca44bf..e66c3f7796 100644--- a/config.template.toml+++ b/config.template.toml@@ -93,140 +93,6 @@# Maximum age of conversations in seconds before they are automatically closed#conversation_max_age_seconds = 864000 # 10 days-#################################### LLM #####################################-# Configuration for LLM models (group name starts with 'llm')-# use 'llm' for the default LLM config-##############################################################################-[llm]-# AWS access key ID-#aws_access_key_id = ""--# AWS region name-#aws_region_name = ""--# AWS secret access key-#aws_secret_access_key = ""--# API key to use (For Headless / CLI only - In Web this is overridden by Session Init)-api_key = ""--# API base URL (For Headless / CLI only - In Web this is overridden by Session Init)-#base_url = ""--# API version-#api_version = ""--# Reasoning effort for OpenAI o-series models (low, medium, high, or not set)-#reasoning_effort = "medium"--# Cost per input token-#input_cost_per_token = 0.0--# Cost per output token-#output_cost_per_token = 0.0--# Custom LLM provider-#custom_llm_provider = ""--# Maximum number of characters in an observation's content-#max_message_chars = 10000--# Maximum number of input tokens-#max_input_tokens = 0--# Maximum number of output tokens-#max_output_tokens = 0--# Model to use. (For Headless / CLI only - In Web this is overridden by Session Init)-model = "gpt-4o"--# Number of retries to attempt when an operation fails with the LLM.-# Increase this value to allow more attempts before giving up-#num_retries = 8--# Maximum wait time (in seconds) between retry attempts-# This caps the exponential backoff to prevent excessively long-#retry_max_wait = 120--# Minimum wait time (in seconds) between retry attempts-# This sets the initial delay before the first retry-#retry_min_wait = 15--# Multiplier for exponential backoff calculation-# The wait time increases by this factor after each failed attempt-# A value of 2.0 means each retry waits twice as long as the previous one-#retry_multiplier = 2.0--# Drop any unmapped (unsupported) params without causing an exception-#drop_params = false--# Modify params for litellm to do transformations like adding a default message, when a message is empty.-# Note: this setting is global, unlike drop_params, it cannot be overridden in each call to litellm.-#modify_params = true--# Using the prompt caching feature if provided by the LLM and supported-#caching_prompt = true--# Base URL for the OLLAMA API-#ollama_base_url = ""--# Temperature for the API-#temperature = 0.0--# Timeout for the API-#timeout = 0--# Top p for the API-#top_p = 1.0--# If model is vision capable, this option allows to disable image processing (useful for cost reduction).-#disable_vision = true--# Custom tokenizer to use for token counting-# https://docs.litellm.ai/docs/completion/token_usage-#custom_tokenizer = ""--# Whether to use native tool calling if supported by the model. Can be true, false, or None by default, which chooses the model's default behavior based on the evaluation.-# ATTENTION: Based on evaluation, enabling native function calling may lead to worse results-# in some scenarios. Use with caution and consider testing with your specific use case.-# https://github.com/OpenHands/OpenHands/pull/4711-#native_tool_calling = None---# Safety settings for models that support them (e.g., Mistral AI, Gemini)-# Example for Mistral AI:-# safety_settings = [-# { "category" = "hate", "threshold" = "low" },-# { "category" = "harassment", "threshold" = "low" },-# { "category" = "sexual", "threshold" = "low" },-# { "category" = "dangerous", "threshold" = "low" }-# ]-#-# Example for Gemini:-# safety_settings = [-# { "category" = "HARM_CATEGORY_HARASSMENT", "threshold" = "BLOCK_NONE" },-# { "category" = "HARM_CATEGORY_HATE_SPEECH", "threshold" = "BLOCK_NONE" },-# { "category" = "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold" = "BLOCK_NONE" },-# { "category" = "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold" = "BLOCK_NONE" }-# ]-#safety_settings = []--[llm.draft_editor]-# The number of times llm_editor tries to fix an error when editing.-correct_num = 5--[llm.gpt4o-mini]-api_key = ""-model = "gpt-4o"--# Example routing LLM configuration for multimodal model routing-# Uncomment and configure to enable model routing with a secondary model-#[llm.secondary_model]-#model = "kimi-k2"-#api_key = ""-#for_routing = true-#max_input_tokens = 128000-#################################### Agent #################################### Configuration for agents (group name starts with 'agent')@@ -259,9 +125,6 @@ enable_think = true# Whether the finish tool is enabledenable_finish = true-# LLM config group to use-#llm_config = 'your-llm-config-group'-# Whether to use prompt extension (e.g., microagent, repo/runtime info) at all#enable_prompt_extensions = true@@ -275,11 +138,6 @@ enable_history_truncation = true# Whether the condensation request tool is enabledenable_condensation_request = false-[agent.RepoExplorerAgent]-# Example: use a cheaper model for RepoExplorerAgent to reduce cost, especially-# useful when an agent doesn't demand high quality but uses a lot of tokens-llm_config = 'gpt3'-[agent.CustomAgent]# Example: use a custom agent from a different package# This will be automatically be registered as a new agent named "CustomAgent"diff --git a/openhands/core/config/README.md b/openhands/core/config/README.mdindex b16fac1fb5..91b90bc7c3 100644--- a/openhands/core/config/README.md+++ b/openhands/core/config/README.md@@ -6,15 +6,11 @@ OpenHands uses a flexible configuration system that allows settings to be define## Configuration Classes-The main configuration classes are:+The main configuration class is:-- `AppConfig`: The root configuration class-- `LLMConfig`: Configuration for the Language Model-- `AgentConfig`: Configuration for the agent-- `SandboxConfig`: Configuration for the sandbox environment-- `SecurityConfig`: Configuration for security settings+- `OpenHandsConfig`: The root configuration class-These classes are defined as dataclasses, with class attributes holding default values for all fields.+This class is defined as a Pydantic model, with field defaults for all settings.## Loading Configuration from Environment Variables@@ -22,19 +18,8 @@ The `load_from_env` function in the config package is responsible for loading co### Naming Convention for Environment Variables-- Prefix: uppercase name of the configuration class followed by an underscore (e.g., `LLM_`, `AGENT_`)- Field Names: all uppercase-- Full Variable Name: Prefix + Field Name (e.g., `LLM_API_KEY`, `AGENT_MEMORY_ENABLED`)--### Examples--```bash-export LLM_API_KEY='your_api_key_here'-export LLM_MODEL='gpt-4'-export AGENT_MEMORY_ENABLED='true'-export AGENT_ENABLE_STUCK_DETECTION='false' # Disable loop detection-export SANDBOX_TIMEOUT='300'-```+- Full Variable Name: Field Name (e.g., `DEFAULT_AGENT`, `WORKSPACE_BASE`)## Type Handling@@ -56,9 +41,9 @@ Be cautious when setting sensitive information like API keys in environment vari## Usage-The `load_app_config()` function is the recommended way to initialize your configuration. It performs the following steps:+The `load_openhands_config()` function is the recommended way to initialize your configuration. It performs the following steps:-1. Creates an instance of `AppConfig`+1. Creates an instance of `OpenHandsConfig`2. Loads settings from the `config.toml` file (if present)3. Loads settings from environment variables, overriding TOML settings if applicable4. Applies final tweaks and validations to the configuration, falling back to the default values specified in the code@@ -66,26 +51,20 @@ The `load_app_config()` function is the recommended way to initialize your confiThere are also command line args, which may work to override other sources.-Here's an example of how to use `load_app_config()`:+Here's an example of how to use `load_openhands_config()`:````python-from openhands.core.config import load_app_config+from openhands.core.config import load_openhands_config# Load all configuration settings-config = load_app_config()+config = load_openhands_config()# Now you can access your configuration-llm_config = config.get_llm_config()-agent_config = config.get_agent_config()-sandbox_config = config.sandbox--# Use the configuration in your application-print(f"Using LLM model: {llm_config.model}")-print(f"Agent memory enabled: {agent_config.memory_enabled}")-print(f"Sandbox timeout: {sandbox_config.timeout}")+print(f"Default agent: {config.default_agent}")+print(f"Max iterations: {config.max_iterations}")````-By using `load_app_config()`, you ensure that all configuration sources are properly loaded and processed, providing a consistent and fully initialized configuration for your application.+By using `load_openhands_config()`, you ensure that all configuration sources are properly loaded and processed, providing a consistent and fully initialized configuration for your application.## Additional Configuration Methodsdiff --git a/openhands/core/config/__init__.py b/openhands/core/config/__init__.pyindex a0cd0c1f95..7c860c2fa2 100644--- a/openhands/core/config/__init__.py+++ b/openhands/core/config/__init__.py@@ -6,12 +6,10 @@ from openhands.core.config.config_utils import (OH_DEFAULT_AGENT,OH_MAX_ITERATIONS,)-from openhands.core.config.llm_config import LLMConfigfrom openhands.core.config.mcp_config import MCPConfigfrom openhands.core.config.openhands_config import OpenHandsConfigfrom openhands.core.config.utils import (finalize_config,- get_llm_config_arg,load_from_env,load_from_toml,load_openhands_config,@@ -24,12 +22,10 @@ __all__ = ['OH_MAX_ITERATIONS','OpenHandsConfig','MCPConfig',- 'LLMConfig','load_openhands_config','load_from_env','load_from_toml','finalize_config',- 'get_llm_config_arg','get_headless_parser','get_evaluation_parser','parse_arguments',diff --git a/openhands/core/config/arg_utils.py b/openhands/core/config/arg_utils.pyindex 5d2cc59ad0..ded2dba021 100644--- a/openhands/core/config/arg_utils.py+++ b/openhands/core/config/arg_utils.py@@ -44,13 +44,6 @@ def add_common_arguments(parser: argparse.ArgumentParser) -> None:type=str,default=None,)- parser.add_argument(- '-l',- '--llm-config',- default=None,- type=str,- help='Replace default LLM ([llm] section in config.toml) config with the specified LLM config, e.g. "llama3" for [llm.llama3] section in config.toml',- )parser.add_argument('--agent-config',default=None,diff --git a/openhands/core/config/llm_config.py b/openhands/core/config/llm_config.pydeleted file mode 100644index 17b7caf590..0000000000--- a/openhands/core/config/llm_config.py+++ /dev/null@@ -1,205 +0,0 @@-# IMPORTANT: LEGACY V0 CODE - Deprecated since version 1.0.0, scheduled for removal April 1, 2026-# This file is part of the legacy (V0) implementation of OpenHands and will be removed soon as we complete the migration to V1.-# OpenHands V1 uses the Software Agent SDK for the agentic core and runs a new application server. Please refer to:-# - V1 agentic core (SDK): https://github.com/OpenHands/software-agent-sdk-# - V1 application server (in this repo): openhands/app_server/-# Unless you are working on deprecation, please avoid extending this legacy file and consult the V1 codepaths above.-# Tag: Legacy-V0-from __future__ import annotations--import os-from typing import Any--from pydantic import BaseModel, ConfigDict, Field, SecretStr, ValidationError--from openhands.app_server.utils.logger import LOG_DIR-from openhands.app_server.utils.logger import openhands_logger as logger---class LLMConfig(BaseModel):- """Configuration for the LLM model.-- Attributes:- model: The model to use.- api_key: The API key to use.- base_url: The base URL for the API. This is necessary for local LLMs.- api_version: The version of the API.- aws_access_key_id: The AWS access key ID.- aws_secret_access_key: The AWS secret access key.- aws_region_name: The AWS region name.- num_retries: The number of retries to attempt.- retry_multiplier: The multiplier for the exponential backoff.- retry_min_wait: The minimum time to wait between retries, in seconds. This is exponential backoff minimum. For models with very low limits, this can be set to 15-20.- retry_max_wait: The maximum time to wait between retries, in seconds. This is exponential backoff maximum.- timeout: The timeout for the API.- max_message_chars: The approximate max number of characters in the content of an event included in the prompt to the LLM. Larger observations are truncated.- temperature: The temperature for the API.- top_p: The top p for the API.- top_k: The top k for the API.- custom_llm_provider: The custom LLM provider to use. This is undocumented in openhands, and normally not used. It is documented on the litellm side.- max_input_tokens: The maximum number of input tokens. Note that this is currently unused, and the value at runtime is actually the total tokens in OpenAI (e.g. 128,000 tokens for GPT-4).- max_output_tokens: The maximum number of output tokens. This is sent to the LLM.- input_cost_per_token: The cost per input token. This will available in logs for the user to check.- output_cost_per_token: The cost per output token. This will available in logs for the user to check.- ollama_base_url: The base URL for the OLLAMA API.- drop_params: Drop any unmapped (unsupported) params without causing an exception.- modify_params: Modify params allows litellm to do transformations like adding a default message, when a message is empty.- disable_vision: If model is vision capable, this option allows to disable image processing (useful for cost reduction).- caching_prompt: Use the prompt caching feature if provided by the LLM and supported by the provider.- log_completions: Whether to log LLM completions to the state.- log_completions_folder: The folder to log LLM completions to. Required if log_completions is True.- custom_tokenizer: A custom tokenizer to use for token counting.- native_tool_calling: Whether to use native tool calling if supported by the model. Can be True, False, or not set.- reasoning_effort: The effort to put into reasoning. This is a string that can be one of 'low', 'medium', 'high', or 'none'. Can apply to all reasoning models.- seed: The seed to use for the LLM.- safety_settings: Safety settings for models that support them (like Mistral AI and Gemini).- for_routing: Whether this LLM is used for routing. This is set to True for models used in conjunction with the main LLM in the model routing feature.- completion_kwargs: Custom kwargs to pass to litellm.completion.- """-- model: str = Field(default='claude-opus-4-5-20251101')- api_key: SecretStr | None = Field(default=None)- base_url: str | None = Field(default=None)- api_version: str | None = Field(default=None)- aws_access_key_id: SecretStr | None = Field(default=None)- aws_secret_access_key: SecretStr | None = Field(default=None)- aws_region_name: str | None = Field(default=None)- openrouter_site_url: str = Field(default='https://docs.all-hands.dev/')- openrouter_app_name: str = Field(default='OpenHands')- # total wait time: 8 + 16 + 32 + 64 = 120 seconds- num_retries: int = Field(default=5)- retry_multiplier: float = Field(default=8)- retry_min_wait: int = Field(default=8)- retry_max_wait: int = Field(default=64)- timeout: int | None = Field(default=None)- max_message_chars: int = Field(- default=30_000- ) # maximum number of characters in an observation's content when sent to the llm- temperature: float = Field(default=0.0)- top_p: float = Field(default=1.0)- top_k: float | None = Field(default=None)- custom_llm_provider: str | None = Field(default=None)- max_input_tokens: int | None = Field(default=None)- max_output_tokens: int | None = Field(default=None)- input_cost_per_token: float | None = Field(default=None)- output_cost_per_token: float | None = Field(default=None)- ollama_base_url: str | None = Field(default=None)- # This setting can be sent in each call to litellm- drop_params: bool = Field(default=True)- # Note: this setting is actually global, unlike drop_params- modify_params: bool = Field(default=True)- disable_vision: bool | None = Field(default=None)- disable_stop_word: bool | None = Field(default=False)- caching_prompt: bool = Field(default=True)- log_completions: bool = Field(default=False)- log_completions_folder: str = Field(default=os.path.join(LOG_DIR, 'completions'))- custom_tokenizer: str | None = Field(default=None)- native_tool_calling: bool | None = Field(default=None)- reasoning_effort: str | None = Field(default=None)- seed: int | None = Field(default=None)- safety_settings: list[dict[str, str]] | None = Field(- default=None,- description='Safety settings for models that support them (like Mistral AI and Gemini)',- )- for_routing: bool = Field(default=False)- # The number of correction attempts for the LLM draft editor- correct_num: int = Field(default=5)- completion_kwargs: dict[str, Any] | None = Field(- default=None,- description='Custom kwargs to pass to litellm.completion',- )-- model_config = ConfigDict(extra='forbid')-- @classmethod- def from_toml_section(cls, data: dict) -> dict[str, LLMConfig]:- """Create a mapping of LLMConfig instances from a toml dictionary representing the [llm] section.-- The default configuration is built from all non-dict keys in data.- Then, each key with a dict value (e.g. [llm.random_name]) is treated as a custom LLM configuration,- and its values override the default configuration.-- Example:- Apply generic LLM config with custom LLM overrides, e.g.- [llm]- model=...- num_retries = 5- [llm.claude]- model="claude-3-5-sonnet"- results in num_retries APPLIED to claude-3-5-sonnet.-- Returns:- dict[str, LLMConfig]: A mapping where the key "llm" corresponds to the default configuration- and additional keys represent custom configurations.- """- # Initialize the result mapping- llm_mapping: dict[str, LLMConfig] = {}-- # Extract base config data (non-dict values)- base_data = {}- custom_sections: dict[str, dict] = {}- for key, value in data.items():- if isinstance(value, dict):- custom_sections[key] = value- else:- base_data[key] = value-- # Try to create the base config- try:- base_config = cls.model_validate(base_data)- llm_mapping['llm'] = base_config- except ValidationError:- logger.warning(- 'Cannot parse [llm] config from toml. Continuing with defaults.'- )- # If base config fails, create a default one- base_config = cls()- # Still add it to the mapping- llm_mapping['llm'] = base_config-- # Process each custom section independently- for name, overrides in custom_sections.items():- try:- # Merge base config with overrides- merged = {**base_config.model_dump(), **overrides}- custom_config = cls.model_validate(merged)- llm_mapping[name] = custom_config- except ValidationError:- logger.warning(- f'Cannot parse [{name}] config from toml. This section will be skipped.'- )- # Skip this custom section but continue with others- continue-- return llm_mapping-- def model_post_init(self, __context: Any) -> None:- """Post-initialization hook to assign OpenRouter-related variables to environment variables.-- This ensures that these values are accessible to litellm at runtime.- """- super().model_post_init(__context)-- # Assign OpenRouter-specific variables to environment variables- if self.openrouter_site_url:- os.environ['OR_SITE_URL'] = self.openrouter_site_url- if self.openrouter_app_name:- os.environ['OR_APP_NAME'] = self.openrouter_app_name-- # Do not set a default reasoning_effort. Leave as None unless user-configured.-- # Set an API version by default for Azure models- # Required for newer models.- # Azure issue: https://github.com/OpenHands/OpenHands/issues/7755- if self.model.startswith('azure') and self.api_version is None:- self.api_version = '2024-12-01-preview'-- # Set AWS credentials as environment variables for LiteLLM Bedrock- if self.aws_access_key_id:- os.environ['AWS_ACCESS_KEY_ID'] = self.aws_access_key_id.get_secret_value()- if self.aws_secret_access_key:- os.environ['AWS_SECRET_ACCESS_KEY'] = (- self.aws_secret_access_key.get_secret_value()- )- if self.aws_region_name:- os.environ['AWS_REGION_NAME'] = self.aws_region_namediff --git a/openhands/core/config/openhands_config.py b/openhands/core/config/openhands_config.pyindex 03726741db..3bdd20ea13 100644--- a/openhands/core/config/openhands_config.py+++ b/openhands/core/config/openhands_config.py@@ -10,14 +10,12 @@ from typing import Any, ClassVarfrom pydantic import BaseModel, ConfigDict, Field, SecretStr-from openhands.app_server.utils import loggerfrom openhands.core.config.config_utils import (DEFAULT_WORKSPACE_MOUNT_PATH_IN_SANDBOX,OH_DEFAULT_AGENT,OH_MAX_ITERATIONS,model_defaults_to_dict,)-from openhands.core.config.llm_config import LLMConfigfrom openhands.core.config.mcp_config import MCPConfig@@ -25,8 +23,6 @@ class OpenHandsConfig(BaseModel):"""Configuration for the app.Attributes:- llms: Dictionary mapping LLM names to their configurations.- The default configuration is stored under the 'llm' key.default_agent: Name of the default agent to use.runtime: Runtime environment identifier.file_store: Type of file store to use.@@ -57,7 +53,6 @@ class OpenHandsConfig(BaseModel):git_user_email: Git user email for commits made by the agent."""- llms: dict[str, LLMConfig] = Field(default_factory=dict)default_agent: str = Field(default=OH_DEFAULT_AGENT)runtime: str = Field(default='docker')file_store: str = Field(default='local')@@ -118,21 +113,6 @@ class OpenHandsConfig(BaseModel):model_config = ConfigDict(extra='forbid')- def get_llm_config(self, name: str = 'llm') -> LLMConfig:- """'llm' is the name for default config (for backward compatibility prior to 0.8)."""- if name in self.llms:- return self.llms[name]- if name is not None and name != 'llm':- logger.openhands_logger.warning(- f'llm config group {name} not found, using default config'- )- if 'llm' not in self.llms:- self.llms['llm'] = LLMConfig()- return self.llms['llm']-- def set_llm_config(self, value: LLMConfig, name: str = 'llm') -> None:- self.llms[name] = value-def model_post_init(self, __context: Any) -> None:"""Post-initialization hook, called when the instance is created with only default values."""super().model_post_init(__context)diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.pyindex b8d1adfdd4..91dd18b963 100644--- a/openhands/core/config/utils.py+++ b/openhands/core/config/utils.py@@ -22,7 +22,6 @@ from openhands.app_server.file_store import get_file_storefrom openhands.app_server.file_store.files import FileStorefrom openhands.app_server.utils import loggerfrom openhands.core.config.arg_utils import get_headless_parser-from openhands.core.config.llm_config import LLMConfigfrom openhands.core.config.mcp_config import mcp_config_from_tomlfrom openhands.core.config.openhands_config import OpenHandsConfig@@ -118,10 +117,6 @@ def load_from_env(# Start processing from the root of the config objectset_attr_from_env(cfg)- # load default LLM config from env- default_llm_config = cfg.get_llm_config()- set_attr_from_env(default_llm_config, 'LLM_')-def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> None:"""Load the config from the toml file. Supports both styles of config vars.@@ -180,17 +175,6 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> Nonef'Unknown config key "{key}" in [core] section')- # Process llm section if present- if 'llm' in toml_config:- try:- llm_mapping = LLMConfig.from_toml_section(toml_config['llm'])- for llm_key, llm_conf in llm_mapping.items():- cfg.set_llm_config(llm_conf, llm_key)- except (TypeError, KeyError, ValidationError) as e:- logger.openhands_logger.warning(- f'Cannot parse [llm] config from toml, values have not been applied.\nError: {e}'- )-# Process MCP sections if presentif 'mcp' in toml_config:try:@@ -209,8 +193,8 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> None# files - they are silently ignoredknown_sections = {'core',- 'llm','mcp',+ 'llm', # Legacy, ignored'sandbox', # Legacy, ignored'security', # Legacy, ignored'agent', # Legacy, ignored@@ -248,10 +232,6 @@ def finalize_config(cfg: OpenHandsConfig) -> None:parts = cfg.workspace_mount_rewrite.split(':')cfg.workspace_mount_path = base.replace(parts[0], parts[1])- # make sure log_completions_folder is an absolute path- for llm in cfg.llms.values():- llm.log_completions_folder = os.path.abspath(llm.log_completions_folder)-# make sure cache dir existsif cfg.cache_dir:pathlib.Path(cfg.cache_dir).mkdir(parents=True, exist_ok=True)@@ -264,73 +244,6 @@ def finalize_config(cfg: OpenHandsConfig) -> None:)-def get_llm_config_arg(- llm_config_arg: str, toml_file: str = 'config.toml'-) -> LLMConfig | None:- """Get a group of llm settings from the config file.-- A group in config.toml can look like this:-- ```- [llm.gpt-3.5-for-eval]- model = 'gpt-3.5-turbo'- api_key = '...'- temperature = 0.5- num_retries = 8- ...- ```-- The user-defined group name, like "gpt-3.5-for-eval", is the argument to this function. The function will load the LLMConfig object- with the settings of this group, from the config file, and set it as the LLMConfig object for the app.-- Note that the group must be under "llm" group, or in other words, the group name must start with "llm.".-- Args:- llm_config_arg: The group of llm settings to get from the config.toml file.- toml_file: Path to the configuration file to read from. Defaults to 'config.toml'.-- Returns:- LLMConfig: The LLMConfig object with the settings from the config file.- """- # keep only the name, just in case- llm_config_arg = llm_config_arg.strip('[]')-- # truncate the prefix, just in case- if llm_config_arg.startswith('llm.'):- llm_config_arg = llm_config_arg[4:]-- logger.openhands_logger.debug(- f'Loading llm config "{llm_config_arg}" from {toml_file}'- )-- # Check if the file exists- if not os.path.exists(toml_file):- logger.openhands_logger.debug(f'Config file not found: {toml_file}')- return None-- # load the toml file- try:- with open(toml_file, 'r', encoding='utf-8') as toml_contents:- toml_config = toml.load(toml_contents)- except FileNotFoundError as e:- logger.openhands_logger.info(f'Config file not found: {e}')- return None- except toml.TomlDecodeError as e:- logger.openhands_logger.error(- f'Cannot parse llm group from {llm_config_arg}. Exception: {e}'- )- return None-- # update the llm config with the specified section- if 'llm' in toml_config and llm_config_arg in toml_config['llm']:- return LLMConfig(**toml_config['llm'][llm_config_arg])-- logger.openhands_logger.debug(- f'LLM config "{llm_config_arg}" not found in {toml_file}'- )- return None--def parse_arguments() -> argparse.Namespace:"""Parse command line arguments."""parser = get_headless_parser()@@ -369,51 +282,13 @@ def setup_config_from_args(args: argparse.Namespace) -> OpenHandsConfig:Common setup used by both CLI and main.py entry points.Configuration precedence (from highest to lowest):- 1. CLI parameters (e.g., -l for LLM config)+ 1. CLI parameters2. config.toml in current directory (or --config-file location if specified)3. ~/.openhands/settings.json and ~/.openhands/config.toml"""# Load base config from toml and env varsconfig = load_openhands_config(config_file=args.config_file)- # Override with command line arguments if provided- if args.llm_config:- logger.openhands_logger.debug(f'CLI specified LLM config: {args.llm_config}')-- # Check if the LLM config is NOT in the loaded configs- if args.llm_config not in config.llms:- # Try to load from the specified config file- llm_config = get_llm_config_arg(args.llm_config, args.config_file)-- # If not found in the specified config file, try the user's config.toml- if llm_config is None and args.config_file != os.path.join(- os.path.expanduser('~'), '.openhands', 'config.toml'- ):- user_config = os.path.join(- os.path.expanduser('~'), '.openhands', 'config.toml'- )- if os.path.exists(user_config):- logger.openhands_logger.debug(- f"Trying to load LLM config '{args.llm_config}' from user config: {user_config}"- )- llm_config = get_llm_config_arg(args.llm_config, user_config)- else:- # If it's already in the loaded configs, use that- llm_config = config.llms[args.llm_config]- logger.openhands_logger.debug(- f"Using LLM config '{args.llm_config}' from loaded configuration"- )- if llm_config is None:- raise ValueError(- f"Cannot find LLM configuration '{args.llm_config}' in any config file"- )-- # Set this as the default LLM config (highest precedence)- config.set_llm_config(llm_config)- logger.openhands_logger.debug(- f'Set LLM config from CLI parameter: {args.llm_config}'- )-# Override default agent if providedif hasattr(args, 'agent_cls') and args.agent_cls:config.default_agent = args.agent_clsdiff --git a/tests/unit/core/config/test_arg_parser.py b/tests/unit/core/config/test_arg_parser.pyindex c1a7bc84c7..38c5693b8d 100644--- a/tests/unit/core/config/test_arg_parser.py+++ b/tests/unit/core/config/test_arg_parser.py@@ -16,7 +16,6 @@ def test_headless_parser_default_values():assert args.agent_cls is Noneassert args.max_iterations is Noneassert args.max_budget_per_task is None- assert args.llm_config is Noneassert args.name == ''assert not args.no_auto_continueassert args.selected_repo is None@@ -36,7 +35,6 @@ def test_evaluation_parser_default_values():assert args.eval_n_limit is Noneassert args.eval_num_workers == 4assert args.eval_note is None- assert args.llm_config is Noneassert args.name == ''assert not args.no_auto_continueassert args.selected_repo is None@@ -67,8 +65,6 @@ def test_evaluation_parser_custom_values():'8','--eval-note','Test run',- '-l',- 'gpt4','-n','test_session','--no-auto-continue',@@ -87,7 +83,6 @@ def test_evaluation_parser_custom_values():assert args.eval_n_limit == 10assert args.eval_num_workers == 8assert args.eval_note == 'Test run'- assert args.llm_config == 'gpt4'assert args.name == 'test_session'assert args.no_auto_continueassert args.version@@ -145,7 +140,6 @@ def test_headless_parser_help_message(capsys):'-c AGENT_CLS, --agent-cls AGENT_CLS','-i MAX_ITERATIONS, --max-iterations MAX_ITERATIONS','-b MAX_BUDGET_PER_TASK, --max-budget-per-task MAX_BUDGET_PER_TASK',- '-l LLM_CONFIG, --llm-config LLM_CONFIG','--agent-config AGENT_CONFIG','-n NAME, --name NAME','--config-file CONFIG_FILE',@@ -158,7 +152,7 @@ def test_headless_parser_help_message(capsys):assert element in help_output, f"Expected '{element}' to be in the help message"option_count = help_output.count(' -')- assert option_count == 15, f'Expected 15 options, found {option_count}'+ assert option_count == 14, f'Expected 14 options, found {option_count}'def test_evaluation_parser_help_message(capsys):@@ -185,7 +179,6 @@ def test_evaluation_parser_help_message(capsys):'--eval-num-workers EVAL_NUM_WORKERS','--eval-note EVAL_NOTE','--eval-ids EVAL_IDS',- '-l LLM_CONFIG, --llm-config LLM_CONFIG','--agent-config AGENT_CONFIG','-n NAME, --name NAME','--config-file CONFIG_FILE',@@ -198,7 +191,7 @@ def test_evaluation_parser_help_message(capsys):assert element in help_output, f"Expected '{element}' to be in the help message"option_count = help_output.count(' -')- assert option_count == 20, f'Expected 20 options, found {option_count}'+ assert option_count == 19, f'Expected 19 options, found {option_count}'def test_selected_repo_format():diff --git a/tests/unit/core/config/test_config.py b/tests/unit/core/config/test_config.pyindex d34f072228..643eb696f5 100644--- a/tests/unit/core/config/test_config.py+++ b/tests/unit/core/config/test_config.py@@ -1,36 +1,15 @@-import loggingimport os-from io import StringIOimport pytest-from openhands.app_server.utils.logger import openhands_loggerfrom openhands.core.config import (- LLMConfig,OpenHandsConfig,finalize_config,- get_llm_config_arg,load_from_env,load_from_toml,)-def setup_env():- # Create old-style and new-style TOML files- with open('old_style_config.toml', 'w') as f:- f.write('[default]\nLLM_MODEL="GPT-4"\n')-- with open('new_style_config.toml', 'w') as f:- f.write('[app]\nLLM_MODEL="GPT-3"\n')-- yield-- # Cleanup TOML files after the test- os.remove('old_style_config.toml')- os.remove('new_style_config.toml')--@pytest.fixturedef temp_toml_file(tmp_path):# Fixture to create a temporary directory and TOML file for testing@@ -44,32 +23,14 @@ def default_config(monkeypatch):yield OpenHandsConfig()-def test_compat_env_to_config(monkeypatch, setup_env):- # Use `monkeypatch` to set environment variables for this specific test- monkeypatch.setenv('LLM_API_KEY', 'sk-proj-rgMV0...')- monkeypatch.setenv('LLM_MODEL', 'gpt-4o')- monkeypatch.setenv('DEFAULT_AGENT', 'CodeActAgent')-- config = OpenHandsConfig()- load_from_env(config, os.environ)- finalize_config(config)-- assert isinstance(config.get_llm_config(), LLMConfig)- assert config.get_llm_config().api_key.get_secret_value() == 'sk-proj-rgMV0...'- assert config.get_llm_config().model == 'gpt-4o'- assert config.default_agent == 'CodeActAgent'--def test_load_from_old_style_env(monkeypatch, default_config):# Test loading configuration from old-style environment variables using monkeypatch- monkeypatch.setenv('LLM_API_KEY', 'test-api-key')monkeypatch.setenv('DEFAULT_AGENT', 'BrowsingAgent')# Using deprecated WORKSPACE_BASE to test backward compatibilitymonkeypatch.setenv('WORKSPACE_BASE', '/opt/files/workspace')load_from_env(default_config, os.environ)- assert default_config.get_llm_config().api_key.get_secret_value() == 'test-api-key'assert default_config.default_agent == 'BrowsingAgent'# Verify deprecated variables still workassert default_config.workspace_base == '/opt/files/workspace'@@ -82,14 +43,6 @@ def test_load_from_new_style_toml(default_config, temp_toml_file):with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:toml_file.write("""-[llm]-model = "test-model"-api_key = "toml-api-key"--[llm.cheap]-model = "some-cheap-model"-api_key = "cheap-model-api-key"-[core]default_agent = "TestAgent""""@@ -97,76 +50,7 @@ default_agent = "TestAgent"load_from_toml(default_config, temp_toml_file)- # default llm configassert default_config.default_agent == 'TestAgent'- assert default_config.get_llm_config().model == 'test-model'- assert default_config.get_llm_config().api_key.get_secret_value() == 'toml-api-key'---def test_llm_config_native_tool_calling(default_config, temp_toml_file, monkeypatch):- # default is None- assert default_config.get_llm_config().native_tool_calling is None-- # set to false- with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:- toml_file.write(- """-[core]--[llm.gpt4o-mini]-native_tool_calling = false-"""- )- load_from_toml(default_config, temp_toml_file)- assert default_config.get_llm_config().native_tool_calling is None- assert default_config.get_llm_config('gpt4o-mini').native_tool_calling is False-- # set to true using string- with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:- toml_file.write(- """-[core]--[llm.gpt4o-mini]-native_tool_calling = true-"""- )- load_from_toml(default_config, temp_toml_file)- assert default_config.get_llm_config('gpt4o-mini').native_tool_calling is True-- # override to false by env- # see utils.set_attr_from_env- monkeypatch.setenv('LLM_NATIVE_TOOL_CALLING', 'false')- load_from_env(default_config, os.environ)- assert default_config.get_llm_config().native_tool_calling is False- assert (- default_config.get_llm_config('gpt4o-mini').native_tool_calling is True- ) # load_from_env didn't override the named config set in the toml file under [llm.gpt4o-mini]---def test_env_overrides_compat_toml(monkeypatch, default_config, temp_toml_file):- # test that environment variables override TOML values using monkeypatch- with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:- toml_file.write("""-[llm]-model = "test-model"-api_key = "toml-api-key"--[core]-disable_color = true-""")-- monkeypatch.setenv('LLM_API_KEY', 'env-api-key')- monkeypatch.delenv('LLM_MODEL', raising=False)-- load_from_toml(default_config, temp_toml_file)- load_from_env(default_config, os.environ)-- assert os.environ.get('LLM_MODEL') is None- assert default_config.get_llm_config().model == 'test-model'- assert default_config.get_llm_config('llm').model == 'test-model'- assert default_config.get_llm_config().api_key.get_secret_value() == 'env-api-key'- assert default_config.disable_color is Truedef test_security_section_in_toml_is_silently_ignored(default_config, temp_toml_file):@@ -177,9 +61,6 @@ def test_security_section_in_toml_is_silently_ignored(default_config, temp_toml_[core]workspace_base = "/opt/files/workspace"-[llm]-model = "test-model"-[security]confirmation_mode = falsesecurity_analyzer = "semgrep"@@ -188,7 +69,7 @@ security_analyzer = "semgrep"load_from_toml(default_config, temp_toml_file)# Security section is ignored; no error raised- assert default_config.get_llm_config().model == 'test-model'+ assert default_config.workspace_base == '/opt/files/workspace'def test_defaults_dict_after_updates(default_config):@@ -198,8 +79,6 @@ def test_defaults_dict_after_updates(default_config):assert initial_defaults['default_agent']['default'] == 'CodeActAgent'updated_config = OpenHandsConfig()- updated_config.get_llm_config().api_key = 'updated-api-key'- updated_config.get_llm_config('llm').api_key = 'updated-api-key'updated_config.default_agent = 'BrowsingAgent'defaults_after_updates = updated_config.defaults_dict@@ -210,9 +89,7 @@ def test_defaults_dict_after_updates(default_config):def test_invalid_toml_format(monkeypatch, temp_toml_file, default_config):# Invalid TOML format doesn't break the configuration- monkeypatch.setenv('LLM_MODEL', 'gpt-5-turbo-1106')monkeypatch.setenv('WORKSPACE_MOUNT_PATH', '/home/user/project')- monkeypatch.delenv('LLM_API_KEY', raising=False)with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:toml_file.write('INVALID TOML CONTENT')@@ -220,10 +97,6 @@ def test_invalid_toml_format(monkeypatch, temp_toml_file, default_config):load_from_toml(default_config, temp_toml_file)load_from_env(default_config, os.environ)default_config.jwt_secret = None # prevent leak- for llm in default_config.llms.values():- llm.api_key = None # prevent leak- assert default_config.get_llm_config().model == 'gpt-5-turbo-1106'- assert default_config.get_llm_config().custom_llm_provider is Noneassert default_config.workspace_mount_path == '/home/user/project'@@ -239,66 +112,8 @@ def test_load_from_toml_file_not_found(default_config):load_from_toml(default_config, 'nonexistent.toml')# Verify that config object maintains default values- assert default_config.get_llm_config() is not None---def test_core_not_in_toml(default_config, temp_toml_file):- """Test loading configuration when the core section is not in the TOML file.-- default values should be used for the missing sections.- """- with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:- toml_file.write("""-[llm]-model = "test-model"-""")-- load_from_toml(default_config, temp_toml_file)- assert default_config.get_llm_config().model == 'test-model'---def test_load_from_toml_partial_invalid(default_config, temp_toml_file, caplog):- """Test loading configuration with partially invalid TOML content.-- This ensures that:- 1. Valid configuration sections are properly loaded- 2. Invalid fields in LLM section log a warning but don't crash- 3. The config object maintains correct values for valid fields- """- with open(temp_toml_file, 'w', encoding='utf-8') as f:- f.write("""-[core]-debug = true--[llm]-# Not set in LLMConfig-invalid_field = "test"-model = "gpt-4"--[agent]-enable_prompt_extensions = true-""")-- # Create a string buffer to capture log output- log_output = StringIO()- handler = logging.StreamHandler(log_output)- handler.setLevel(logging.WARNING)- formatter = logging.Formatter('%(message)s')- handler.setFormatter(formatter)- openhands_logger.addHandler(handler)-- try:- load_from_toml(default_config, temp_toml_file)-- log_content = log_output.getvalue()-- # The LLM config should log a warning but not raise an exception- assert 'Cannot parse [llm] config from toml' in log_content-- # Verify valid configurations are loaded- assert default_config.debug is True- finally:- openhands_logger.removeHandler(handler)+ assert default_config is not None+ assert default_config.default_agent == 'CodeActAgent'def test_finalize_config(default_config):@@ -334,46 +149,8 @@ def test_cache_dir_creation(default_config, tmpdir):def test_api_keys_repr_str():- # Test LLMConfig- llm_config = LLMConfig(- api_key='my_api_key',- aws_access_key_id='my_access_key',- aws_secret_access_key='my_secret_key',- )-- # Check that no secret keys are emitted in representations of the config object- assert 'my_api_key' not in repr(llm_config)- assert 'my_api_key' not in str(llm_config)- assert 'my_access_key' not in repr(llm_config)- assert 'my_access_key' not in str(llm_config)- assert 'my_secret_key' not in repr(llm_config)- assert 'my_secret_key' not in str(llm_config)-- # Check that no other attrs in LLMConfig have 'key' or 'token' in their name- # This will fail when new attrs are added, and attract attention- known_key_token_attrs_llm = [- 'api_key',- 'aws_access_key_id',- 'aws_secret_access_key',- 'input_cost_per_token',- 'output_cost_per_token',- 'custom_tokenizer',- ]- for attr_name in LLMConfig.model_fields.keys():- if (- not attr_name.startswith('__')- and attr_name not in known_key_token_attrs_llm- ):- assert 'key' not in attr_name.lower(), (- f"Unexpected attribute '{attr_name}' contains 'key' in LLMConfig"- )- assert 'token' not in attr_name.lower() or 'tokens' in attr_name.lower(), (- f"Unexpected attribute '{attr_name}' contains 'token' in LLMConfig"- )-# Test OpenHandsConfigapp_config = OpenHandsConfig(- llms={'llm': llm_config},search_api_key='my_search_api_key',)@@ -413,25 +190,3 @@ max_budget_per_task = 4.7assert config.max_iterations == 42assert config.max_budget_per_task == 4.7---def test_get_llm_config_arg(temp_toml_file):- temp_toml = """-[core]-max_iterations = 100-max_budget_per_task = 4.0--[llm.gpt3]-model="gpt-3.5-turbo"-api_key="redacted"--[llm.gpt4o]-model="gpt-4o"-api_key="redacted"-"""-- with open(temp_toml_file, 'w') as f:- f.write(temp_toml)-- llm_config = get_llm_config_arg('gpt3', temp_toml_file)- assert llm_config.model == 'gpt-3.5-turbo'diff --git a/tests/unit/core/config/test_config_precedence.py b/tests/unit/core/config/test_config_precedence.pyindex 56c77e1758..5eb33db0c0 100644--- a/tests/unit/core/config/test_config_precedence.py+++ b/tests/unit/core/config/test_config_precedence.py@@ -1,164 +1,18 @@from unittest.mock import MagicMock, patch-import pytest-from openhands.core.config import (OH_DEFAULT_AGENT,OH_MAX_ITERATIONS,OpenHandsConfig,- get_llm_config_arg,setup_config_from_args,)-def default_config():- """Fixture to provide a default OpenHandsConfig instance."""- yield OpenHandsConfig()---def temp_config_files(tmp_path):- """Create temporary config files for testing precedence."""- # Create a directory structure mimicking ~/.openhands/- user_config_dir = tmp_path / 'home' / '.openhands'- user_config_dir.mkdir(parents=True, exist_ok=True)-- # Create ~/.openhands/config.toml- user_config_toml = user_config_dir / 'config.toml'- user_config_toml.write_text("""-[llm]-model = "user-home-model"-api_key = "user-home-api-key"--[llm.user-llm]-model = "user-specific-model"-api_key = "user-specific-api-key"-""")-- # Create ~/.openhands/settings.json- user_settings_json = user_config_dir / 'settings.json'- user_settings_json.write_text("""-{- "LLM_MODEL": "settings-json-model",- "LLM_API_KEY": "settings-json-api-key"-}-""")-- # Create current directory config.toml- current_dir_toml = tmp_path / 'current' / 'config.toml'- current_dir_toml.parent.mkdir(parents=True, exist_ok=True)- current_dir_toml.write_text("""-[llm]-model = "current-dir-model"-api_key = "current-dir-api-key"--[llm.current-dir-llm]-model = "current-dir-specific-model"-api_key = "current-dir-specific-api-key"-""")-- return {- 'user_config_toml': str(user_config_toml),- 'user_settings_json': str(user_settings_json),- 'current_dir_toml': str(current_dir_toml),- 'home_dir': str(user_config_dir.parent),- 'current_dir': str(current_dir_toml.parent),- }---@patch('openhands.core.config.utils.os.path.expanduser')-def test_llm_config_precedence_cli_highest(mock_expanduser, temp_config_files):- """Test that CLI parameters have the highest precedence."""- mock_expanduser.side_effect = lambda path: path.replace(- '~', temp_config_files['home_dir']- )-- # Create mock args with CLI parameters- mock_args = MagicMock()- mock_args.config_file = temp_config_files['current_dir_toml']- mock_args.llm_config = 'current-dir-llm' # Specify LLM via CLI- mock_args.agent_cls = None- mock_args.max_iterations = None- mock_args.max_budget_per_task = None- mock_args.selected_repo = None-- # Load config with CLI parameters- with patch('os.path.exists', return_value=True):- config = setup_config_from_args(mock_args)-- # Verify CLI parameter takes precedence- assert config.get_llm_config().model == 'current-dir-specific-model'- assert (- config.get_llm_config().api_key.get_secret_value()- == 'current-dir-specific-api-key'- )---@patch('openhands.core.config.utils.os.path.expanduser')-def test_current_dir_toml_precedence_over_user_config(- mock_expanduser, temp_config_files-):- """Test that config.toml in current directory has precedence over ~/.openhands/config.toml."""- mock_expanduser.side_effect = lambda path: path.replace(- '~', temp_config_files['home_dir']- )-- # Create mock args without CLI parameters- mock_args = MagicMock()- mock_args.config_file = temp_config_files['current_dir_toml']- mock_args.llm_config = None # No CLI parameter- mock_args.agent_cls = None- mock_args.max_iterations = None- mock_args.max_budget_per_task = None- mock_args.selected_repo = None-- # Load config without CLI parameters- with patch('os.path.exists', return_value=True):- config = setup_config_from_args(mock_args)-- # Verify current directory config.toml takes precedence over user config- assert config.get_llm_config().model == 'current-dir-model'- assert config.get_llm_config().api_key.get_secret_value() == 'current-dir-api-key'---@patch('openhands.core.config.utils.os.path.expanduser')-def test_get_llm_config_arg_precedence(mock_expanduser, temp_config_files):- """Test that get_llm_config_arg prioritizes the specified config file."""- mock_expanduser.side_effect = lambda path: path.replace(- '~', temp_config_files['home_dir']- )-- # First try to load from current directory config- with patch('os.path.exists', return_value=True):- llm_config = get_llm_config_arg(- 'current-dir-llm', temp_config_files['current_dir_toml']- )-- # Verify it loaded from current directory config- assert llm_config.model == 'current-dir-specific-model'- assert llm_config.api_key.get_secret_value() == 'current-dir-specific-api-key'-- # Now try to load a config that doesn't exist- # We need to patch setup_config_from_args to handle the fallback to user config- with patch(- 'os.path.exists',- return_value=False,- ):- llm_config = get_llm_config_arg(- 'user-llm', temp_config_files['current_dir_toml']- )-- # Verify it returns None when config not found (no automatic fallback)- assert llm_config is None--def test_default_values_applied_when_none():"""Test that default values are applied when config values are None."""# Create mock args with None values for agent_cls and max_iterationsmock_args = MagicMock()mock_args.config_file = None- mock_args.llm_config = Nonemock_args.agent_cls = Nonemock_args.max_iterations = None@@ -179,7 +33,6 @@ def test_cli_args_override_defaults():# Create mock args with custom valuesmock_args = MagicMock()mock_args.config_file = None- mock_args.llm_config = Nonemock_args.agent_cls = 'CustomAgent'mock_args.max_iterations = 50@@ -200,7 +53,6 @@ def test_cli_args_none_uses_config_toml_values():# Create mock args with None values for agent_cls and max_iterationsmock_args = MagicMock()mock_args.config_file = None- mock_args.llm_config = Nonemock_args.agent_cls = Nonemock_args.max_iterations = Nonediff --git a/tests/unit/core/config/test_llm_config.py b/tests/unit/core/config/test_llm_config.pydeleted file mode 100644index 501afe2296..0000000000--- a/tests/unit/core/config/test_llm_config.py+++ /dev/null@@ -1,256 +0,0 @@-import pathlib--import pytest--from openhands.core.config import OpenHandsConfig-from openhands.core.config.utils import load_from_toml---def default_config(monkeypatch):- # Fixture to provide a default OpenHandsConfig instance- yield OpenHandsConfig()---def generic_llm_toml(tmp_path: pathlib.Path) -> str:- """Fixture to create a generic LLM TOML configuration with all custom LLMs- providing mandatory 'model' and 'api_key', and testing fallback to the generic section values- for other attributes like 'num_retries'.- """- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "base-model"-api_key = "base-api-key"-num_retries = 3--[llm.custom1]-model = "custom-model-1"-api_key = "custom-api-key-1"-# 'num_retries' is not overridden and should fallback to the value from [llm]--[llm.custom2]-model = "custom-model-2"-api_key = "custom-api-key-2"-num_retries = 5 # Overridden value--[llm.custom3]-model = "custom-model-3"-api_key = "custom-api-key-3"-# No overrides for additional attributes- """- toml_file = tmp_path / 'llm_config.toml'- toml_file.write_text(toml_content)- return str(toml_file)---def test_load_from_toml_llm_with_fallback(- default_config: OpenHandsConfig, generic_llm_toml: str-) -> None:- """Test that custom LLM configurations fallback non-overridden attributes- like 'num_retries' from the generic [llm] section.- """- load_from_toml(default_config, generic_llm_toml)-- # Verify generic LLM configuration- generic_llm = default_config.get_llm_config('llm')- assert generic_llm.model == 'base-model'- assert generic_llm.api_key.get_secret_value() == 'base-api-key'- assert generic_llm.num_retries == 3-- # Verify custom1 LLM falls back 'num_retries' from base- custom1 = default_config.get_llm_config('custom1')- assert custom1.model == 'custom-model-1'- assert custom1.api_key.get_secret_value() == 'custom-api-key-1'- assert custom1.num_retries == 3 # from [llm]-- # Verify custom2 LLM overrides 'num_retries'- custom2 = default_config.get_llm_config('custom2')- assert custom2.model == 'custom-model-2'- assert custom2.api_key.get_secret_value() == 'custom-api-key-2'- assert custom2.num_retries == 5 # overridden value-- # Verify custom3 LLM inherits all attributes except 'model' and 'api_key'- custom3 = default_config.get_llm_config('custom3')- assert custom3.model == 'custom-model-3'- assert custom3.api_key.get_secret_value() == 'custom-api-key-3'- assert custom3.num_retries == 3 # from [llm]---def test_load_from_toml_llm_custom_overrides_all(- default_config: OpenHandsConfig, tmp_path: pathlib.Path-) -> None:- """Test that a custom LLM can fully override all attributes from the generic [llm] section."""- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "base-model"-api_key = "base-api-key"-num_retries = 3--[llm.custom_full]-model = "full-custom-model"-api_key = "full-custom-api-key"-num_retries = 10- """- toml_file = tmp_path / 'full_override_llm.toml'- toml_file.write_text(toml_content)-- load_from_toml(default_config, str(toml_file))-- # Verify generic LLM configuration remains unchanged- generic_llm = default_config.get_llm_config('llm')- assert generic_llm.model == 'base-model'- assert generic_llm.api_key.get_secret_value() == 'base-api-key'- assert generic_llm.num_retries == 3-- # Verify custom_full LLM overrides all attributes- custom_full = default_config.get_llm_config('custom_full')- assert custom_full.model == 'full-custom-model'- assert custom_full.api_key.get_secret_value() == 'full-custom-api-key'- assert custom_full.num_retries == 10 # overridden value---def test_load_from_toml_llm_custom_partial_override(- default_config: OpenHandsConfig, generic_llm_toml: str-) -> None:- """Test that custom LLM configurations can partially override attributes- from the generic [llm] section while inheriting others.- """- load_from_toml(default_config, generic_llm_toml)-- # Verify custom1 LLM overrides 'model' and 'api_key' but inherits 'num_retries'- custom1 = default_config.get_llm_config('custom1')- assert custom1.model == 'custom-model-1'- assert custom1.api_key.get_secret_value() == 'custom-api-key-1'- assert custom1.num_retries == 3 # from [llm]-- # Verify custom2 LLM overrides 'model', 'api_key', and 'num_retries'- custom2 = default_config.get_llm_config('custom2')- assert custom2.model == 'custom-model-2'- assert custom2.api_key.get_secret_value() == 'custom-api-key-2'- assert custom2.num_retries == 5 # Overridden value---def test_load_from_toml_llm_custom_no_override(- default_config: OpenHandsConfig, generic_llm_toml: str-) -> None:- """Test that custom LLM configurations with no additional overrides- inherit all non-specified attributes from the generic [llm] section.- """- load_from_toml(default_config, generic_llm_toml)-- # Verify custom3 LLM inherits 'num_retries' from generic- custom3 = default_config.get_llm_config('custom3')- assert custom3.model == 'custom-model-3'- assert custom3.api_key.get_secret_value() == 'custom-api-key-3'- assert custom3.num_retries == 3 # from [llm]---def test_load_from_toml_llm_missing_generic(- default_config: OpenHandsConfig, tmp_path: pathlib.Path-) -> None:- """Test that custom LLM configurations without a generic [llm] section- use only their own attributes and fallback to defaults for others.- """- toml_content = """-[core]-workspace_base = "./workspace"--[llm.custom_only]-model = "custom-only-model"-api_key = "custom-only-api-key"- """- toml_file = tmp_path / 'custom_only_llm.toml'- toml_file.write_text(toml_content)-- load_from_toml(default_config, str(toml_file))-- # Verify custom_only LLM uses its own attributes and defaults for others- custom_only = default_config.get_llm_config('custom_only')- assert custom_only.model == 'custom-only-model'- assert custom_only.api_key.get_secret_value() == 'custom-only-api-key'- assert custom_only.num_retries == 5 # default value---def test_load_from_toml_llm_invalid_config(- default_config: OpenHandsConfig, tmp_path: pathlib.Path-) -> None:- """Test that invalid custom LLM configurations do not override the generic- and raise appropriate warnings.- """- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "base-model"-api_key = "base-api-key"-num_retries = 3--[llm.invalid_custom]-unknown_attr = "should_not_exist"- """- toml_file = tmp_path / 'invalid_custom_llm.toml'- toml_file.write_text(toml_content)-- load_from_toml(default_config, str(toml_file))-- # Verify generic LLM is loaded correctly- generic_llm = default_config.get_llm_config('llm')- assert generic_llm.model == 'base-model'- assert generic_llm.api_key.get_secret_value() == 'base-api-key'- assert generic_llm.num_retries == 3-- # Verify invalid_custom LLM does not override generic attributes- custom_invalid = default_config.get_llm_config('invalid_custom')- assert custom_invalid.model == 'base-model'- assert custom_invalid.api_key.get_secret_value() == 'base-api-key'- assert custom_invalid.num_retries == 3 # default value---def test_azure_model_api_version(- default_config: OpenHandsConfig, tmp_path: pathlib.Path-) -> None:- """Test that Azure models get the correct API version by default."""- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "azure/o3-mini"-api_key = "test-api-key"- """- toml_file = tmp_path / 'azure_llm.toml'- toml_file.write_text(toml_content)-- load_from_toml(default_config, str(toml_file))-- # Verify Azure model gets default API version- azure_llm = default_config.get_llm_config('llm')- assert azure_llm.model == 'azure/o3-mini'- assert azure_llm.api_version == '2024-12-01-preview'-- # Test that non-Azure models don't get default API version- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "anthropic/claude-3-sonnet"-api_key = "test-api-key"- """- toml_file = tmp_path / 'non_azure_llm.toml'- toml_file.write_text(toml_content)-- load_from_toml(default_config, str(toml_file))-- # Verify non-Azure model doesn't get default API version- non_azure_llm = default_config.get_llm_config('llm')- assert non_azure_llm.model == 'anthropic/claude-3-sonnet'- assert non_azure_llm.api_version is Nonediff --git a/tests/unit/core/config/test_llm_draft_config.py b/tests/unit/core/config/test_llm_draft_config.pydeleted file mode 100644index b3070d02f6..0000000000--- a/tests/unit/core/config/test_llm_draft_config.py+++ /dev/null@@ -1,100 +0,0 @@-import pathlib--import pytest--from openhands.core.config import OpenHandsConfig-from openhands.core.config.utils import load_from_toml---def config_toml_without_draft_editor(tmp_path: pathlib.Path) -> str:- """This fixture provides a TOML config that DOES NOT contain [llm.draft_editor].- We'll use it to verify that the draft_editor LLM is not present in the config.- """- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "base-model"-api_key = "base-api-key"--[llm.custom1]-model = "custom-model-1"-api_key = "custom-api-key-1"- """- toml_file = tmp_path / 'no_draft_editor.toml'- toml_file.write_text(toml_content)- return str(toml_file)---def config_toml_with_draft_editor(tmp_path: pathlib.Path) -> str:- """This fixture provides a TOML config that DOES contain [llm.draft_editor].- We'll use it to verify that the draft_editor LLM is loaded as any other custom LLM.- """- toml_content = """-[core]-workspace_base = "./workspace"--[llm]-model = "base-model"-api_key = "base-api-key"-num_retries = 7--[llm.draft_editor]-model = "draft-model"-api_key = "draft-api-key"--[llm.custom2]-model = "custom-model-2"-api_key = "custom-api-key-2"- """- toml_file = tmp_path / 'yes_draft_editor.toml'- toml_file.write_text(toml_content)- return str(toml_file)---def test_no_draft_editor_in_config(config_toml_without_draft_editor):- """Test that draft_editor is simply not present if not declared in the TOML.- Previously, we tested fallback behavior. Now, it's simplified to not exist at all.- This docstring remains to illustrate that the old fallback logic is removed.- """- config = OpenHandsConfig()-- # Load config from TOML- load_from_toml(config, config_toml_without_draft_editor)-- # draft_editor should not appear in config.llms- assert 'draft_editor' not in config.llms---def test_draft_editor_as_named_llm(config_toml_with_draft_editor):- """Test that draft_editor is loaded if declared in the TOML under [llm.draft_editor].- This docstring references the simpler approach: if it exists, it's just another named LLM.- """- config = OpenHandsConfig()- load_from_toml(config, config_toml_with_draft_editor)-- # draft_editor should appear as a normal named LLM- assert 'draft_editor' in config.llms-- draft_llm = config.get_llm_config('draft_editor')- assert draft_llm is not None- assert draft_llm.model == 'draft-model'- assert draft_llm.api_key.get_secret_value() == 'draft-api-key'---def test_draft_editor_fallback(config_toml_with_draft_editor):- """Test that the draft_editor config does pick up fallbacks- normally set in LLMConfig class and from generic LLM.-- We expect the 'draft_editor' LLM to behave just like any custom LLM would.- """- config = OpenHandsConfig()- load_from_toml(config, config_toml_with_draft_editor)-- # Check that the normal default fields come from LLMConfig where not overridden- draft_editor_config = config.get_llm_config('draft_editor')- # num_retries is an example default from llm section- assert draft_editor_config.num_retries == 7diff --git a/tests/unit/core/logger/test_logging.py b/tests/unit/core/logger/test_logging.pyindex 984aca2784..7a31ce37ba 100644--- a/tests/unit/core/logger/test_logging.py+++ b/tests/unit/core/logger/test_logging.py@@ -11,7 +11,7 @@ from openhands.app_server.utils.logger import (json_log_handler,)from openhands.app_server.utils.logger import openhands_logger as openhands_logger-from openhands.core.config import LLMConfig, OpenHandsConfig+from openhands.core.config import OpenHandsConfig@pytest.fixture@@ -72,20 +72,6 @@ def test_anthropic_api_key_masking(test_handler):assert api_key not in log_output-def test_llm_config_attributes_masking(test_handler):- logger, stream = test_handler- llm_config = LLMConfig(- api_key='sk-abc123',- aws_access_key_id='AKIAIOSFODNN7EXAMPLE',- aws_secret_access_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',- )- logger.info(f'LLM Config: {llm_config}')- log_output = stream.getvalue()- assert 'sk-abc123' not in log_output- assert 'AKIAIOSFODNN7EXAMPLE' not in log_output- assert 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' not in log_output--def test_app_config_attributes_masking(test_handler):logger, stream = test_handlerapp_config = OpenHandsConfig(search_api_key='search-xyz789')