Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions samples/python/agents/travel_planner_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def __init__(self):
try:
with open('config.json') as f:
config = json.load(f)
if not os.getenv(config['api_key']):
print(f'{config["api_key"]} environment variable not set.')
if not config['api_key']:
print('api_key configuration not set.')
sys.exit(1)
api_key = os.getenv(config['api_key'])
api_key = config['api_key']
Comment on lines +20 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The validation for api_key only checks for an empty value. The default config.json uses "API_KEY" as a placeholder. It would be more robust to also check for this placeholder value to prevent runtime errors and provide a clearer message to the user if they haven't configured their key.

Suggested change
if not config['api_key']:
print('api_key configuration not set.')
sys.exit(1)
api_key = os.getenv(config['api_key'])
api_key = config['api_key']
api_key = config['api_key']
if not api_key or api_key == 'API_KEY':
print('Error: The "api_key" in config.json is missing or is a placeholder. Please provide a valid API key.')
sys.exit(1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

For enhanced security, it's a best practice to avoid storing secrets like API keys in plaintext configuration files, as they can be accidentally committed to version control. Consider loading the key directly from an environment variable instead (e.g., api_key = os.getenv('OPENAI_API_KEY')). This is a suggestion for future improvement and doesn't block this PR.


self.model = ChatOpenAI(
model=config['model_name'] or 'gpt-4o',
Expand Down