feat(classic): improve AutoGPT configuration and setup

Environment loading:
- Search for .env in multiple locations (cwd, ~/.autogpt, ~/.config/autogpt)
- Allows running autogpt from any directory
- Document search order in .env.template

Setup simplification:
- Remove interactive AI settings revision (was broken/unused)
- Simplify to just printing current settings
- Clean up unused imports

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nicholas Tindle
2026-01-18 18:52:38 -06:00
parent b9113bee02
commit cacc89790f
4 changed files with 57 additions and 125 deletions

View File

@@ -1,3 +1,18 @@
################################################################################
### AutoGPT - CONFIGURATION FILE
################################################################################
#
# AutoGPT searches for .env files in these locations (first found wins):
# 1. Current working directory (./.env)
# 2. User config directory (~/.autogpt/.env)
# 3. XDG config directory (~/.config/autogpt/.env)
# 4. Package installation directory
#
# For user-level configuration that works from any directory, copy this file to:
# ~/.autogpt/.env
#
################################################################################
################################################################################
### AutoGPT - GENERAL SETTINGS
################################################################################

View File

@@ -1,6 +1,31 @@
from pathlib import Path
from dotenv import load_dotenv
# Load the users .env file into environment variables
load_dotenv(verbose=True, override=True)
del load_dotenv
def _load_env_from_locations() -> None:
"""Load .env from multiple locations (first found wins).
This allows running autogpt from any directory while still finding credentials.
Search order:
1. Current working directory
2. User config (~/.autogpt/.env)
3. XDG config (~/.config/autogpt/.env)
4. Package installation directory
"""
env_locations = [
Path.cwd() / ".env",
Path.home() / ".autogpt" / ".env",
Path.home() / ".config" / "autogpt" / ".env",
Path(__file__).parent.parent.parent / ".env",
]
for env_path in env_locations:
if env_path.exists():
load_dotenv(env_path, verbose=True, override=True)
break
_load_env_from_locations()
del _load_env_from_locations, load_dotenv, Path

View File

@@ -19,8 +19,8 @@ logger = logging.getLogger(__name__)
AZURE_CONFIG_FILE = Path("azure.yaml")
GPT_4_MODEL = OpenAIModelName.GPT4
GPT_3_MODEL = OpenAIModelName.GPT3
GPT_4_MODEL = OpenAIModelName.GPT4_O
GPT_3_MODEL = OpenAIModelName.GPT4_O_MINI # Fallback model for when configured model is unavailable
class AppConfig(BaseConfig):

View File

@@ -8,8 +8,6 @@ from forge.logging.utils import print_attribute
from autogpt.app.config import AppConfig
from .input import clean_input
logger = logging.getLogger(__name__)
@@ -49,7 +47,7 @@ async def interactively_revise_ai_settings(
directives: AIDirectives,
app_config: AppConfig,
):
"""Interactively revise the AI settings.
"""Print AI settings and return them.
Args:
ai_profile (AIConfig): The current AI profile.
@@ -57,126 +55,20 @@ async def interactively_revise_ai_settings(
app_config (Config): The application configuration.
Returns:
AIConfig: The revised AI settings.
AIConfig: The AI settings.
"""
logger = logging.getLogger("revise_ai_profile")
revised = False
while True:
# Print the current AI configuration
print_ai_settings(
title="Current AI Settings" if not revised else "Revised AI Settings",
ai_profile=ai_profile,
directives=directives,
logger=logger,
)
if (
clean_input("Continue with these settings? [Y/n]").lower()
or app_config.authorise_key
) == app_config.authorise_key:
break
# Ask for revised ai_profile
ai_profile.ai_name = (
clean_input("Enter AI name (or press enter to keep current):")
or ai_profile.ai_name
)
ai_profile.ai_role = (
clean_input("Enter new AI role (or press enter to keep current):")
or ai_profile.ai_role
)
# Revise constraints
i = 0
while i < len(directives.constraints):
constraint = directives.constraints[i]
print_attribute(f"Constraint {i+1}:", f'"{constraint}"')
new_constraint = (
clean_input(
f"Enter new constraint {i+1}"
" (press enter to keep current, or '-' to remove):",
)
or constraint
)
if new_constraint == "-":
directives.constraints.remove(constraint)
continue
elif new_constraint:
directives.constraints[i] = new_constraint
i += 1
# Add new constraints
while True:
new_constraint = clean_input(
"Press enter to finish, or enter a constraint to add:",
)
if not new_constraint:
break
directives.constraints.append(new_constraint)
# Revise resources
i = 0
while i < len(directives.resources):
resource = directives.resources[i]
print_attribute(f"Resource {i+1}:", f'"{resource}"')
new_resource = (
clean_input(
f"Enter new resource {i+1}"
" (press enter to keep current, or '-' to remove):",
)
or resource
)
if new_resource == "-":
directives.resources.remove(resource)
continue
elif new_resource:
directives.resources[i] = new_resource
i += 1
# Add new resources
while True:
new_resource = clean_input(
"Press enter to finish, or enter a resource to add:",
)
if not new_resource:
break
directives.resources.append(new_resource)
# Revise best practices
i = 0
while i < len(directives.best_practices):
best_practice = directives.best_practices[i]
print_attribute(f"Best Practice {i+1}:", f'"{best_practice}"')
new_best_practice = (
clean_input(
f"Enter new best practice {i+1}"
" (press enter to keep current, or '-' to remove):",
)
or best_practice
)
if new_best_practice == "-":
directives.best_practices.remove(best_practice)
continue
elif new_best_practice:
directives.best_practices[i] = new_best_practice
i += 1
# Add new best practices
while True:
new_best_practice = clean_input(
"Press enter to finish, or add a best practice to add:",
)
if not new_best_practice:
break
directives.best_practices.append(new_best_practice)
revised = True
print_ai_settings(
title="AI Settings",
ai_profile=ai_profile,
directives=directives,
logger=logger,
)
logger.info(
"To customize, use CLI args: --ai-name, --ai-role, "
"--constraint, --resource, --best-practice"
)
return ai_profile, directives