Skip to content

Commit

Permalink
refactor(forge): Clean forge (#7117)
Browse files Browse the repository at this point in the history
Remove unused `forge` code and improve structure of `forge`.

* Put all Agent Protocol stuff together in `forge.agent_protocol`
  * ... including `forge.agent_protocol.database` (was `forge.db`)
* Remove duplicate/unused parts from `forge`
  * `forge.actions`, containing old commands; replaced by `forge.components` from `autogpt`
  * `forge/agent.py` (the old one, `ForgeAgent`)
  * `forge/app.py`, which was used to serve and run the `ForgeAgent`
  * `forge/db.py` (`ForgeDatabase`), which was used for `ForgeAgent`
  * `forge/llm.py`, which has been replaced by new `forge.llm` module which was ported from `autogpt.core.resource.model_providers`
  * `forge.memory`, which is not in use and not being maintained
  * `forge.sdk`, much of which was moved into other modules and the rest is deprecated
  * `AccessDeniedError`: unused
  * `forge_log.py`: replaced with `logging`
  * `validate_yaml_file`: not needed
  * `ai_settings_file` and associated loading logic and env var `AI_SETTINGS_FILE`: unused
  * `prompt_settings_file` and associated loading logic and env var `PROMPT_SETTINGS_FILE`: default directives are now provided by the `SystemComponent`
    * `request_user_double_check`, which was only used in `AIDirectives.load`
  * `TypingConsoleHandler`: not used
  • Loading branch information
kcze committed May 21, 2024
1 parent 2cca4fa commit bcc5282
Show file tree
Hide file tree
Showing 76 changed files with 305 additions and 2,776 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ auto_gpt_workspace/*
*.mpeg
.env
azure.yaml
ai_settings.yaml
last_run_ai_settings.yaml
.vscode
.idea/*
auto-gpt.json
Expand Down
1 change: 0 additions & 1 deletion autogpts/autogpt/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*.template
*.yaml
*.yml
!prompt_settings.yaml

data/*
logs/*
Expand Down
6 changes: 0 additions & 6 deletions autogpts/autogpt/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
## USER_AGENT - Define the user-agent used by the requests library to browse website (string)
# USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"

## AI_SETTINGS_FILE - Specifies which AI Settings file to use, relative to the AutoGPT root directory. (defaults to ai_settings.yaml)
# AI_SETTINGS_FILE=ai_settings.yaml

## PROMPT_SETTINGS_FILE - Specifies which Prompt Settings file to use, relative to the AutoGPT root directory. (defaults to prompt_settings.yaml)
# PROMPT_SETTINGS_FILE=prompt_settings.yaml

## AUTHORISE COMMAND KEY - Key to authorise commands
# AUTHORISE_COMMAND_KEY=y

Expand Down
2 changes: 0 additions & 2 deletions autogpts/autogpt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ autogpt/*.json
*.mpeg
.env
azure.yaml
ai_settings.yaml
last_run_ai_settings.yaml
.vscode
.idea/*
auto-gpt.json
Expand Down
1 change: 0 additions & 1 deletion autogpts/autogpt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ RUN poetry install --no-cache --no-root --without dev \
ONBUILD COPY autogpt/ ./autogpt
ONBUILD COPY scripts/ ./scripts
ONBUILD COPY plugins/ ./plugins
ONBUILD COPY prompt_settings.yaml ./prompt_settings.yaml
ONBUILD COPY README.md ./README.md
ONBUILD RUN mkdir ./data

Expand Down
7 changes: 0 additions & 7 deletions autogpts/autogpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ Options:
-c, --continuous Enable Continuous Mode
-y, --skip-reprompt Skips the re-prompting messages at the
beginning of the script
-C, --ai-settings FILE Specifies which ai_settings.yaml file to
use, relative to the AutoGPT root directory.
Will also automatically skip the re-prompt.
-P, --prompt-settings FILE Specifies which prompt_settings.yaml file to
use.
-l, --continuous-limit INTEGER Defines the number of times to run in
continuous mode
--speak Enable Speak Mode
Expand Down Expand Up @@ -118,8 +113,6 @@ Usage: python -m autogpt serve [OPTIONS]
agent for every task.
Options:
-P, --prompt-settings FILE Specifies which prompt_settings.yaml file to
use.
--debug Enable Debug Mode
--gpt3only Enable GPT3.5 Only Mode
--gpt4only Enable GPT4 Only Mode
Expand Down
3 changes: 1 addition & 2 deletions autogpts/autogpt/autogpt/agent_factory/configurators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def create_agent(
) -> Agent:
if not task:
raise ValueError("No task specified for new agent")
if not directives:
directives = AIDirectives.from_file(app_config.prompt_settings_file)
directives = directives or AIDirectives()

agent = _configure_agent(
agent_id=agent_id,
Expand Down
4 changes: 1 addition & 3 deletions autogpts/autogpt/autogpt/agent_factory/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import TYPE_CHECKING

from forge.config.ai_directives import AIDirectives
from forge.file_storage.base import FileStorage

if TYPE_CHECKING:
Expand All @@ -21,7 +20,6 @@ async def generate_agent_for_task(
file_storage: FileStorage,
llm_provider: ChatModelProvider,
) -> Agent:
base_directives = AIDirectives.from_file(app_config.prompt_settings_file)
ai_profile, task_directives = await generate_agent_profile_for_task(
task=task,
app_config=app_config,
Expand All @@ -31,7 +29,7 @@ async def generate_agent_for_task(
agent_id=agent_id,
task=task,
ai_profile=ai_profile,
directives=base_directives + task_directives,
directives=task_directives,
app_config=app_config,
file_storage=file_storage,
llm_provider=llm_provider,
Expand Down
18 changes: 9 additions & 9 deletions autogpts/autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse, StreamingResponse
from fastapi.staticfiles import StaticFiles
from forge.config.config import Config
from forge.file_storage import FileStorage
from forge.llm.providers import ChatModelProvider, ModelProviderBudget
from forge.models.action import ActionErrorResult, ActionSuccessResult
from forge.sdk.db import AgentDB
from forge.sdk.middlewares import AgentMiddleware
from forge.sdk.model import (
from forge.agent_protocol.api_router import base_router
from forge.agent_protocol.database import AgentDB
from forge.agent_protocol.middlewares import AgentMiddleware
from forge.agent_protocol.models import (
Artifact,
Step,
StepRequestBody,
Expand All @@ -26,7 +23,10 @@
TaskRequestBody,
TaskStepsListResponse,
)
from forge.sdk.routes.agent_protocol import base_router
from forge.config.config import Config
from forge.file_storage import FileStorage
from forge.llm.providers import ChatModelProvider, ModelProviderBudget
from forge.models.action import ActionErrorResult, ActionSuccessResult
from forge.utils.const import ASK_COMMAND, FINISH_COMMAND
from forge.utils.exceptions import AgentFinished, NotFoundError
from hypercorn.asyncio import serve as hypercorn_serve
Expand Down Expand Up @@ -123,7 +123,7 @@ async def root():
config.bind = [f"0.0.0.0:{port}"]

logger.info(f"AutoGPT server starting on http://localhost:{port}")
await hypercorn_serve(app, config)
await hypercorn_serve(app, config) # type: ignore

async def create_task(self, task_request: TaskRequestBody) -> Task:
"""
Expand Down
27 changes: 0 additions & 27 deletions autogpts/autogpt/autogpt/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ def cli(ctx: click.Context):
is_flag=True,
help="Skips the re-prompting messages at the beginning of the script",
)
@click.option(
"--ai-settings",
"-C",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
help=(
"Specifies which ai_settings.yaml file to use, relative to the AutoGPT"
" root directory. Will also automatically skip the re-prompt."
),
)
@click.option(
"--ai-name",
type=str,
Expand All @@ -83,12 +74,6 @@ def cli(ctx: click.Context):
type=str,
help="AI role override",
)
@click.option(
"--prompt-settings",
"-P",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
help="Specifies which prompt_settings.yaml file to use.",
)
@click.option(
"--constraint",
type=str,
Expand Down Expand Up @@ -157,10 +142,8 @@ def run(
install_plugin_deps: bool,
skip_news: bool,
skip_reprompt: bool,
ai_settings: Optional[Path],
ai_name: Optional[str],
ai_role: Optional[str],
prompt_settings: Optional[Path],
resource: tuple[str],
constraint: tuple[str],
best_practice: tuple[str],
Expand All @@ -180,8 +163,6 @@ def run(
run_auto_gpt(
continuous=continuous,
continuous_limit=continuous_limit,
ai_settings=ai_settings,
prompt_settings=prompt_settings,
skip_reprompt=skip_reprompt,
speak=speak,
debug=debug,
Expand All @@ -205,12 +186,6 @@ def run(


@cli.command()
@click.option(
"--prompt-settings",
"-P",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
help="Specifies which prompt_settings.yaml file to use.",
)
@click.option("--gpt3only", is_flag=True, help="Enable GPT3.5 Only Mode")
@click.option("--gpt4only", is_flag=True, help="Enable GPT4 Only Mode")
@click.option(
Expand Down Expand Up @@ -250,7 +225,6 @@ def run(
type=click.Choice([i.value for i in LogFormatName]),
)
def serve(
prompt_settings: Optional[Path],
gpt3only: bool,
gpt4only: bool,
browser_name: Optional[str],
Expand All @@ -269,7 +243,6 @@ def serve(
from autogpt.app.main import run_auto_gpt_server

run_auto_gpt_server(
prompt_settings=prompt_settings,
debug=debug,
log_level=log_level,
log_format=log_format,
Expand Down
32 changes: 0 additions & 32 deletions autogpts/autogpt/autogpt/app/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
from __future__ import annotations

import logging
from pathlib import Path
from typing import Literal, Optional

import click
from colorama import Back, Fore, Style
from forge.config.config import GPT_3_MODEL, GPT_4_MODEL, Config
from forge.llm.providers import ModelName, MultiProvider
from forge.logging.helpers import request_user_double_check
from forge.utils.yaml_validator import validate_yaml_file

from autogpt.memory.vector import get_supported_memory_backends

Expand All @@ -21,8 +18,6 @@ async def apply_overrides_to_config(
config: Config,
continuous: bool = False,
continuous_limit: Optional[int] = None,
ai_settings_file: Optional[Path] = None,
prompt_settings_file: Optional[Path] = None,
skip_reprompt: bool = False,
gpt3only: bool = False,
gpt4only: bool = False,
Expand All @@ -37,8 +32,6 @@ async def apply_overrides_to_config(
config (Config): The config object to update.
continuous (bool): Whether to run in continuous mode.
continuous_limit (int): The number of times to run in continuous mode.
ai_settings_file (Path): The path to the ai_settings.yaml file.
prompt_settings_file (Path): The path to the prompt_settings.yaml file.
skip_reprompt (bool): Whether to skip the re-prompting messages on start.
speak (bool): Whether to enable speak mode.
debug (bool): Whether to enable debug mode.
Expand Down Expand Up @@ -102,31 +95,6 @@ async def apply_overrides_to_config(
if skip_reprompt:
config.skip_reprompt = True

if ai_settings_file:
file = ai_settings_file

# Validate file
(validated, message) = validate_yaml_file(file)
if not validated:
logger.fatal(extra={"title": "FAILED FILE VALIDATION:"}, msg=message)
request_user_double_check()
exit(1)

config.ai_settings_file = config.project_root / file
config.skip_reprompt = True

if prompt_settings_file:
file = prompt_settings_file

# Validate file
(validated, message) = validate_yaml_file(file)
if not validated:
logger.fatal(extra={"title": "FAILED FILE VALIDATION:"}, msg=message)
request_user_double_check()
exit(1)

config.prompt_settings_file = config.project_root / file

if browser_name:
config.selenium_web_browser = browser_name

Expand Down
21 changes: 4 additions & 17 deletions autogpts/autogpt/autogpt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
from typing import TYPE_CHECKING, Optional

from colorama import Fore, Style
from forge.agent_protocol.database import AgentDB
from forge.components.code_executor import (
is_docker_available,
we_are_running_in_a_docker_container,
)
from forge.config.ai_directives import AIDirectives
from forge.config.ai_profile import AIProfile
from forge.config.config import Config, ConfigBuilder, assert_config_has_openai_api_key
from forge.db import AgentDB
from forge.file_storage import FileStorageBackendName, get_storage
from forge.llm.providers import MultiProvider
from forge.logging.config import configure_logging
from forge.logging.helpers import print_attribute, speak
from forge.logging.utils import print_attribute, speak
from forge.models.action import ActionInterruptedByHuman, ActionProposal
from forge.models.utils import ModelWithSummary
from forge.utils.const import FINISH_COMMAND
Expand Down Expand Up @@ -57,8 +56,6 @@
async def run_auto_gpt(
continuous: bool = False,
continuous_limit: Optional[int] = None,
ai_settings: Optional[Path] = None,
prompt_settings: Optional[Path] = None,
skip_reprompt: bool = False,
speak: bool = False,
debug: bool = False,
Expand Down Expand Up @@ -108,8 +105,6 @@ async def run_auto_gpt(
config=config,
continuous=continuous,
continuous_limit=continuous_limit,
ai_settings_file=ai_settings,
prompt_settings_file=prompt_settings,
skip_reprompt=skip_reprompt,
gpt3only=gpt3only,
gpt4only=gpt4only,
Expand All @@ -134,7 +129,7 @@ async def run_auto_gpt(
)

if not config.skip_news:
print_motd(config, logger)
print_motd(logger)
print_git_branch_info(logger)
print_python_version_info(logger)
print_attribute("Smart LLM", config.smart_llm)
Expand All @@ -146,10 +141,6 @@ async def run_auto_gpt(
print_attribute("Continuous Limit", config.continuous_limit)
if config.tts_config.speak_mode:
print_attribute("Speak Mode", "ENABLED")
if ai_settings:
print_attribute("Using AI Settings File", ai_settings)
if prompt_settings:
print_attribute("Using Prompt Settings File", prompt_settings)
if config.allow_downloads:
print_attribute("Native Downloading", "ENABLED")
if we_are_running_in_a_docker_container() or is_docker_available():
Expand Down Expand Up @@ -267,14 +258,12 @@ async def run_auto_gpt(
" with as much detail as possible:",
)

base_ai_directives = AIDirectives.from_file(config.prompt_settings_file)

ai_profile, task_oriented_ai_directives = await generate_agent_profile_for_task(
task,
app_config=config,
llm_provider=llm_provider,
)
ai_directives = base_ai_directives + task_oriented_ai_directives
ai_directives = task_oriented_ai_directives
apply_overrides_to_ai_settings(
ai_profile=ai_profile,
directives=ai_directives,
Expand Down Expand Up @@ -347,7 +336,6 @@ async def run_auto_gpt(

@coroutine
async def run_auto_gpt_server(
prompt_settings: Optional[Path] = None,
debug: bool = False,
log_level: Optional[str] = None,
log_format: Optional[str] = None,
Expand Down Expand Up @@ -384,7 +372,6 @@ async def run_auto_gpt_server(

await apply_overrides_to_config(
config=config,
prompt_settings_file=prompt_settings,
gpt3only=gpt3only,
gpt4only=gpt4only,
browser_name=browser_name,
Expand Down
2 changes: 1 addition & 1 deletion autogpts/autogpt/autogpt/app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from forge.config.ai_directives import AIDirectives
from forge.config.ai_profile import AIProfile
from forge.config.config import Config
from forge.logging.helpers import print_attribute
from forge.logging.utils import print_attribute

from .input import clean_input

Expand Down
Loading

0 comments on commit bcc5282

Please sign in to comment.