openhands.core.config.utils
load_from_env
def load_from_env(cfg: AppConfig,
env_or_toml_dict: dict | MutableMapping[str, str]) -> None
Sets config attributes from environment variables or TOML dictionary.
Reads environment-style variables and updates the config attributes accordingly. Supports configuration of LLM settings (e.g., LLM_BASE_URL), agent settings (e.g., AGENT_MEMORY_ENABLED), sandbox settings (e.g., SANDBOX_TIMEOUT), and more.
Arguments:
cfg
- The AppConfig object to set attributes on.env_or_toml_dict
- The environment variables or a config.toml dict.
load_from_toml
def load_from_toml(cfg: AppConfig, toml_file: str = 'config.toml') -> None
Load the config from the toml file. Supports both styles of config vars.
Arguments:
cfg
- The AppConfig object to update attributes of.toml_file
- The path to the toml file. Defaults to 'config.toml'.
See Also:
- config.template.toml for the full list of config options.
finalize_config
def finalize_config(cfg: AppConfig)
More tweaks to the config after it's been loaded.
get_agent_config_arg
def get_agent_config_arg(agent_config_arg: str,
toml_file: str = 'config.toml') -> AgentConfig | None
Get a group of agent settings from the config file.
A group in config.toml can look like this:
The user-defined group name, like "default", is the argument to this function. The function will load the AgentConfig object with the settings of this group, from the config file, and set it as the AgentConfig object for the app.
Note that the group must be under "agent" group, or in other words, the group name must start with "agent.".
[agent.default]
enable_prompt_extensions = false
Arguments:
agent_config_arg
- The group of agent settings to get from the config.toml file.toml_file
- Path to the configuration file to read from. Defaults to 'config.toml'.
Returns:
AgentConfig
- The AgentConfig object with the settings from the config file.
get_llm_config_arg
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:
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.".
[llm.gpt-3.5-for-eval]
model = 'gpt-3.5-turbo'
api_key = '...'
temperature = 0.5
num_retries = 8
...
Arguments:
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.
get_parser
def get_parser() -> argparse.ArgumentParser
Get the argument parser.
parse_arguments
def parse_arguments() -> argparse.Namespace
Parse command line arguments.
load_app_config
def load_app_config(set_logging_levels: bool = True,
config_file: str = 'config.toml') -> AppConfig
Load the configuration from the specified config file and environment variables.
Arguments:
set_logging_levels
- Whether to set the global variables for logging levels.config_file
- Path to the config file. Defaults to 'config.toml' in the current directory.
setup_config_from_args
def setup_config_from_args(args: argparse.Namespace) -> AppConfig
Load config from toml and override with command line arguments.
Common setup used by both CLI and main.py entry points.