mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-12 10:44:31 +01:00
* Add categories to command registry * Fix tests * Clean up prompt generation * Rename Performance Evaluations to Best Practices * Move specification of response format from system prompt to Agent.construct_base_prompt * Clean up PromptGenerator class * Add debug logging to AIConfig autogeneration * Clarify prompting and add support for multiple thought processes to Agent * WIP: PlanningAgent * Disable message history by default on BaseAgent * Add CommandOutput and ThoughtProcessOutput type aliases * Fix interrupts in main.py * Use custom exceptions and clean up exception/error handling * Remove duplicate agent_history.py * Update PlanningAgent from upstream * WIP: Support for dynamic in-prompt context * WIP: response formats for PlanningAgent three-stage cycle * Remove browsing overlay & separate browsing from extraction code * Fix human feedback * Fix tests * Include history in Agent prompt generation * Code improvements in agent.py * Add ask_user command and revise system prompt
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any, Callable, Optional
|
|
|
|
if TYPE_CHECKING:
|
|
from autogpt.config import Config
|
|
|
|
from .command_parameter import CommandParameter
|
|
from .context_item import ContextItem
|
|
|
|
CommandReturnValue = Any
|
|
CommandOutput = CommandReturnValue | tuple[CommandReturnValue, ContextItem]
|
|
|
|
|
|
class Command:
|
|
"""A class representing a command.
|
|
|
|
Attributes:
|
|
name (str): The name of the command.
|
|
description (str): A brief description of what the command does.
|
|
parameters (list): The parameters of the function that the command executes.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
description: str,
|
|
method: Callable[..., CommandOutput],
|
|
parameters: list[CommandParameter],
|
|
enabled: bool | Callable[[Config], bool] = True,
|
|
disabled_reason: Optional[str] = None,
|
|
aliases: list[str] = [],
|
|
):
|
|
self.name = name
|
|
self.description = description
|
|
self.method = method
|
|
self.parameters = parameters
|
|
self.enabled = enabled
|
|
self.disabled_reason = disabled_reason
|
|
self.aliases = aliases
|
|
|
|
def __call__(self, *args, **kwargs) -> Any:
|
|
if hasattr(kwargs, "config") and callable(self.enabled):
|
|
self.enabled = self.enabled(kwargs["config"])
|
|
if not self.enabled:
|
|
if self.disabled_reason:
|
|
return f"Command '{self.name}' is disabled: {self.disabled_reason}"
|
|
return f"Command '{self.name}' is disabled"
|
|
return self.method(*args, **kwargs)
|
|
|
|
def __str__(self) -> str:
|
|
params = [
|
|
f"{param.name}: {param.type if param.required else f'Optional[{param.type}]'}"
|
|
for param in self.parameters
|
|
]
|
|
return f"{self.name}: {self.description}, params: ({', '.join(params)})"
|