Fix KeyError: 'key_name' in agent.py #1613
Closed
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
When running crewai run, a KeyError: 'key_name' occurs if the key_name attribute is missing in the environment variables.
Solution:
Added a conditional check in agent.py to skip processing key_name unless it exists. This prevents the error and ensures compatibility for setups where key_name is not required.
Proposed Fix: A conditional check can be added in agent.py to skip processing key_name unless it's present and valid:
if "key_name" in env_var and env_var["key_name"] in unnacepted_attributes:
continue
This ensures the error doesn’t occur when key_name is absent but unnecessary for the task.
Environment:
Files Modified:
Testing:
Validated the fix without setting key_name as environment variable.
To test: