mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
This incremental re-architecture unifies Agent code and plugins, so everything is component-based. ## Breaking changes - Removed command categories and `DISABLED_COMMAND_CATEGORIES` environment variable. Use `DISABLED_COMMANDS` environment variable to disable individual commands. - Changed `command` decorator; old-style commands are no longer supported. Implement `CommandProvider` on components instead. - Removed `CommandRegistry`, now all commands are provided by components implementing `CommandProvider`. - Removed `prompt_config` from `AgentSettings`. - Removed plugin support: old plugins will no longer be loaded and executed. - Removed `PromptScratchpad`, it was used by plugins and is no longer needed. - Changed `ThoughtProcessOutput` from tuple to pydantic `BaseModel`. ## Other changes - Created `AgentComponent`, protocols and logic to execute them. - `BaseAgent` and `Agent` is now composed of components. - Moved some logic from `BaseAgent` to `Agent`. - Moved agent features and commands to components. - Removed check if the same operation is about to be executed twice in a row. - Removed file logging from `FileManagerComponent` (formerly `AgentFileManagerMixin`) - Updated tests - Added docs See [Introduction](https://github.com/kcze/AutoGPT/blob/kpczerwinski/open-440-modular-agents/docs/content/AutoGPT/component%20agent/introduction.md) for more information.
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
from pathlib import Path
|
|
from typing import Iterator
|
|
|
|
from git.repo import Repo
|
|
|
|
from autogpt.agents.protocols import CommandProvider
|
|
from autogpt.command_decorator import command
|
|
from autogpt.config.config import Config
|
|
from autogpt.core.utils.json_schema import JSONSchema
|
|
from autogpt.models.command import Command
|
|
from autogpt.url_utils.validators import validate_url
|
|
from autogpt.utils.exceptions import CommandExecutionError
|
|
|
|
|
|
class GitOperationsComponent(CommandProvider):
|
|
"""Provides commands to perform Git operations."""
|
|
|
|
def __init__(self, config: Config):
|
|
self._enabled = bool(config.github_username and config.github_api_key)
|
|
self._disabled_reason = "Configure github_username and github_api_key."
|
|
self.legacy_config = config
|
|
|
|
def get_commands(self) -> Iterator[Command]:
|
|
yield self.clone_repository
|
|
|
|
@command(
|
|
parameters={
|
|
"url": JSONSchema(
|
|
type=JSONSchema.Type.STRING,
|
|
description="The URL of the repository to clone",
|
|
required=True,
|
|
),
|
|
"clone_path": JSONSchema(
|
|
type=JSONSchema.Type.STRING,
|
|
description="The path to clone the repository to",
|
|
required=True,
|
|
),
|
|
},
|
|
)
|
|
@validate_url
|
|
def clone_repository(self, url: str, clone_path: Path) -> str:
|
|
"""Clone a GitHub repository locally.
|
|
|
|
Args:
|
|
url (str): The URL of the repository to clone.
|
|
clone_path (Path): The path to clone the repository to.
|
|
|
|
Returns:
|
|
str: The result of the clone operation.
|
|
"""
|
|
split_url = url.split("//")
|
|
auth_repo_url = (
|
|
f"//{self.legacy_config.github_username}:"
|
|
f"{self.legacy_config.github_api_key}@".join(split_url)
|
|
)
|
|
try:
|
|
Repo.clone_from(url=auth_repo_url, to_path=clone_path)
|
|
except Exception as e:
|
|
raise CommandExecutionError(f"Could not clone repo: {e}")
|
|
|
|
return f"""Cloned {url} to {clone_path}"""
|