MCPcopy Create free account
hub / github.com/google/adk-python / load_dotenv_for_agent

Function load_dotenv_for_agent

src/google/adk/cli/utils/envs.py:53–90  ·  view source on GitHub ↗

Loads the `.env` file for the agent module. Explicit environment variables (present before the first `.env` load) are preserved, while values loaded from `.env` may be overridden by later `.env` loads.

(
    agent_name: str, agent_parent_folder: str, filename: str = '.env'
)

Source from the content-addressed store, hash-verified

51
52
53def load_dotenv_for_agent(
54 agent_name: str, agent_parent_folder: str, filename: str = '.env'
55):
56 """Loads the `.env` file for the agent module.
57
58 Explicit environment variables (present before the first `.env` load) are
59 preserved, while values loaded from `.env` may be overridden by later `.env`
60 loads.
61 """
62 if is_env_enabled(_ADK_DISABLE_LOAD_DOTENV_ENV_VAR):
63 logger.info(
64 'Skipping %s loading because %s is enabled.',
65 filename,
66 _ADK_DISABLE_LOAD_DOTENV_ENV_VAR,
67 )
68 return
69
70 # Gets the folder of agent_module as starting_folder
71 starting_folder = os.path.abspath(
72 os.path.join(agent_parent_folder, agent_name)
73 )
74 dotenv_file_path = _walk_to_root_until_found(starting_folder, filename)
75 if dotenv_file_path:
76 explicit_env_keys = _get_explicit_env_keys()
77 explicit_env = {
78 key: os.environ[key] for key in explicit_env_keys if key in os.environ
79 }
80
81 load_dotenv(dotenv_file_path, override=True, verbose=True)
82 os.environ.update(explicit_env)
83 logger.info(
84 'Loaded %s file for %s at %s',
85 filename,
86 agent_name,
87 dotenv_file_path,
88 )
89 else:
90 logger.info('No %s file found for %s', filename, agent_name)

Callers

nothing calls this directly

Calls 5

is_env_enabledFunction · 0.85
_get_explicit_env_keysFunction · 0.85
joinMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected