-
Notifications
You must be signed in to change notification settings - Fork 45k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoGPT: Implement Agent Protocol (#5612)
- Loading branch information
Showing
101 changed files
with
3,723 additions
and
2,871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
{"workspace": {"input": "auto_gpt_workspace", "output":"auto_gpt_workspace" }, "entry_path": "agbenchmark.benchmarks"} | ||
{ | ||
"workspace": { | ||
"input": "agbenchmark_config/workspace", | ||
"output": "agbenchmark_config/workspace" | ||
}, | ||
"entry_path": "agbenchmark.benchmarks", | ||
"host": "http://localhost:8000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
import autogpt.app.cli | ||
|
||
if __name__ == "__main__": | ||
autogpt.app.cli.main() | ||
autogpt.app.cli.cli() |
116 changes: 116 additions & 0 deletions
116
autogpts/autogpt/autogpt/agent_factory/configurators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from typing import Optional | ||
|
||
from autogpt.agent_manager import AgentManager | ||
from autogpt.agents.agent import Agent, AgentConfiguration, AgentSettings | ||
from autogpt.commands import COMMAND_CATEGORIES | ||
from autogpt.config import AIDirectives, AIProfile, Config | ||
from autogpt.core.resource.model_providers import ChatModelProvider | ||
from autogpt.logs.config import configure_chat_plugins | ||
from autogpt.logs.helpers import print_attribute | ||
from autogpt.models.command_registry import CommandRegistry | ||
from autogpt.plugins import scan_plugins | ||
|
||
|
||
def create_agent( | ||
task: str, | ||
ai_profile: AIProfile, | ||
app_config: Config, | ||
llm_provider: ChatModelProvider, | ||
directives: Optional[AIDirectives] = None, | ||
) -> Agent: | ||
if not task: | ||
raise ValueError("No task specified for new agent") | ||
if not directives: | ||
directives = AIDirectives.from_file(app_config.prompt_settings_file) | ||
|
||
agent = _configure_agent( | ||
task=task, | ||
ai_profile=ai_profile, | ||
directives=directives, | ||
app_config=app_config, | ||
llm_provider=llm_provider, | ||
) | ||
|
||
agent.state.agent_id = AgentManager.generate_id(agent.ai_profile.ai_name) | ||
|
||
return agent | ||
|
||
|
||
def configure_agent_with_state( | ||
state: AgentSettings, | ||
app_config: Config, | ||
llm_provider: ChatModelProvider, | ||
) -> Agent: | ||
return _configure_agent( | ||
state=state, | ||
app_config=app_config, | ||
llm_provider=llm_provider, | ||
) | ||
|
||
|
||
def _configure_agent( | ||
app_config: Config, | ||
llm_provider: ChatModelProvider, | ||
task: str = "", | ||
ai_profile: Optional[AIProfile] = None, | ||
directives: Optional[AIDirectives] = None, | ||
state: Optional[AgentSettings] = None, | ||
) -> Agent: | ||
if not (state or task and ai_profile and directives): | ||
raise TypeError( | ||
"Either (state) or (task, ai_profile, directives) must be specified" | ||
) | ||
|
||
app_config.plugins = scan_plugins(app_config, app_config.debug_mode) | ||
configure_chat_plugins(app_config) | ||
|
||
# Create a CommandRegistry instance and scan default folder | ||
command_registry = CommandRegistry.with_command_modules( | ||
modules=COMMAND_CATEGORIES, | ||
config=app_config, | ||
) | ||
|
||
agent_state = state or create_agent_state( | ||
task=task, | ||
ai_profile=ai_profile, | ||
directives=directives, | ||
app_config=app_config, | ||
) | ||
|
||
# TODO: configure memory | ||
|
||
print_attribute("Configured Browser", app_config.selenium_web_browser) | ||
|
||
return Agent( | ||
settings=agent_state, | ||
llm_provider=llm_provider, | ||
command_registry=command_registry, | ||
legacy_config=app_config, | ||
) | ||
|
||
|
||
def create_agent_state( | ||
task: str, | ||
ai_profile: AIProfile, | ||
directives: AIDirectives, | ||
app_config: Config, | ||
) -> AgentSettings: | ||
agent_prompt_config = Agent.default_settings.prompt_config.copy(deep=True) | ||
agent_prompt_config.use_functions_api = app_config.openai_functions | ||
|
||
return AgentSettings( | ||
name=Agent.default_settings.name, | ||
description=Agent.default_settings.description, | ||
task=task, | ||
ai_profile=ai_profile, | ||
directives=directives, | ||
config=AgentConfiguration( | ||
fast_llm=app_config.fast_llm, | ||
smart_llm=app_config.smart_llm, | ||
allow_fs_access=not app_config.restrict_to_workspace, | ||
use_functions_api=app_config.openai_functions, | ||
plugins=app_config.plugins, | ||
), | ||
prompt_config=agent_prompt_config, | ||
history=Agent.default_settings.history.copy(deep=True), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from autogpt.agents.agent import Agent | ||
from autogpt.config import Config | ||
from autogpt.core.resource.model_providers.schema import ChatModelProvider | ||
|
||
from autogpt.config.ai_directives import AIDirectives | ||
|
||
from .configurators import _configure_agent | ||
from .profile_generator import generate_agent_profile_for_task | ||
|
||
|
||
async def generate_agent_for_task( | ||
task: str, | ||
app_config: "Config", | ||
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, | ||
llm_provider=llm_provider, | ||
) | ||
return _configure_agent( | ||
task=task, | ||
ai_profile=ai_profile, | ||
directives=base_directives + task_directives, | ||
app_config=app_config, | ||
llm_provider=llm_provider, | ||
) |
Oops, something went wrong.