mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
Use the active settings dictionary when scheduling MCP config updates so applying global MCP servers no longer references an undefined config variable. Add a focused regression test covering the settings apply path and document the deferred MCP update contract in settings.py DOX.
5.2 KiB
5.2 KiB
settings.py DOX
Purpose
- Own the
settings.pyhelper module. - This module defines settings models, defaults, validation, and serialization.
- Keep this file-level DOX profile synchronized with
settings.pybecause this directory is intentionally flat.
Ownership
settings.pyowns the runtime implementation.settings.py.dox.mdowns durable notes about responsibilities, contracts, side effects, and verification for that implementation.- Classes:
Settings(TypedDict)PartialSettings(Settings)FieldOption(TypedDict)SettingsField(TypedDict)SettingsSection(TypedDict)ModelProvider(ProvidersFO)SettingsOutputAdditional(TypedDict)SettingsOutput(TypedDict)- Top-level functions:
get_default_value(name: str, value: T) -> T: Load setting value from .env with A0_SET_ prefix, falling back to default._ensure_option_present(options: list[OptionT] | None, current_value: str | None) -> list[OptionT]: Ensure the currently selected value exists in a dropdown options list._is_valid_timezone(value: str) -> bool_normalize_timezone_setting(value: Any, default: str=...) -> str_normalize_time_format(value: Any, default: str=...) -> str_resolve_runtime_timezone(setting_value: str, browser_timezone: str | None=...) -> str_timezone_options() -> list[FieldOption]convert_out(settings: Settings) -> SettingsOutput_get_api_key_field(settings: Settings, provider: str, title: str) -> SettingsFieldconvert_in(settings: Settings) -> Settingsget_settings() -> Settingsreload_settings() -> Settingsset_runtime_settings_snapshot(settings: Settings) -> Noneset_settings(settings: Settings, apply: bool=..., browser_timezone: str | None=...)set_settings_delta(delta: dict, apply: bool=...)merge_settings(original: Settings, delta: dict) -> Settingsnormalize_settings(settings: Settings) -> Settings_adjust_to_version(settings: Settings, default: Settings)_load_sensitive_settings(settings: Settings)_read_settings_file() -> Settings | None_write_settings_file(settings: Settings)_remove_sensitive_settings(settings: Settings)_write_sensitive_settings(settings: Settings)get_default_settings() -> Settings_apply_timezone_setting(previous: Settings | None, browser_timezone: str | None=...) -> None_apply_settings(previous: Settings | None, browser_timezone: str | None=...)_env_to_dict(data: str)_dict_to_env(data_dict)set_root_password(password: str)get_runtime_config(set: Settings)- Notable constants/configuration names:
T,PASSWORD_PLACEHOLDER,API_KEY_PLACEHOLDER,TIMEZONE_AUTO,TIME_FORMAT_12H,TIME_FORMAT_24H,SETTINGS_FILE.
Runtime Contracts
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
- Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, network calls, subprocess/runtime control, model calls, WebSocket state, plugin state, settings/state persistence, secret handling, scheduler state.
- Imported dependency areas include:
base64,hashlib,helpers,helpers.notification,helpers.print_style,helpers.providers,helpers.secrets,json,models,os,pytz,re,subprocess,typing.
Key Concepts
- Important called helpers/classes observed in the source:
TypeVar,files.get_abs_path,dotenv.get_dotenv_value,opts.insert,str.strip,_is_valid_timezone,str.strip.lower,_normalize_timezone_setting,SettingsOutput,get_default_settings,_ensure_option_present,_resolve_runtime_timezone,get_default_secrets_manager,get_settings,normalize_settings,_load_sensitive_settings,settings.copy,_write_settings_file,reload_settings,set_settings,initialize_agent. - Applying settings refreshes active context configs while preserving each subordinate agent's own profile.
- Applying settings starts a deferred
MCPConfig.update(...)with the currentmcp_serversstring when global MCP server settings change. - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
Work Guidance
- Preserve public helper APIs used by core code and plugins unless every caller is updated.
- Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
- Prefer adding cohesive helper functions here only when behavior is reused across modules.
Verification
- Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
- Related tests observed by source search:
tests/test_browser_agent_regressions.pytests/test_document_query_plugin.pytests/test_download_toast_regressions.pytests/test_fasta2a_client.pytests/test_mcp_handler_multimodal.pytests/test_model_config_api_keys.pytests/test_model_config_project_presets.pytests/test_oauth_static.pytests/test_subagent_profiles.py
Child DOX Index
No child DOX files.