Skip to content

Python: [Bug]: Samples do not load environment variables correctly #4042

@TaoChenOSU

Description

@TaoChenOSU

Description

The samples no longer load environment variables correctly from a .env file in the project.
For example, running python .\samples\02-agents\providers\openai\openai_chat_client_basic.py gives agent_framework.exceptions.ServiceInitializationError: OpenAI API key is required. Set via 'api_key' parameter or 'OPENAI_API_KEY' environment variable. even if the key is already in a .env file under the root agent_framework/python.

Error Messages / Stack Traces

agent_framework.exceptions.ServiceInitializationError: OpenAI API key is required. Set via 'api_key' parameter or 'OPENAI_API_KEY' environment variable.

Package Versions

agent_framework

Python Version

No response

Additional Context

All samples should correctly load environment variables from a .env file if present, by running load_dotenv.

Metadata

Metadata

Labels

bugSomething isn't workingpython

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions