Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-arch hello world #3969

Merged
merged 163 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
d3462ae
Setup new library and testing directory structure for application core
collijk May 2, 2023
516e950
proposed abstract Configuration class definition (#3805)
dwrtz May 5, 2023
9304528
Update Planner Interface (#3790)
rihp May 5, 2023
434230f
Set up the workspace base class (#3795)
collijk May 5, 2023
7bcdc5f
Add language model base and work out interactions with planning manag…
collijk May 7, 2023
3e81d22
Rearch: logging interface (#3853)
rihp May 7, 2023
3180641
Updated docstrings for consistency and conciseness
collijk May 7, 2023
2afe06a
Initial base.py for message broker agent-state-encapsulation (#3831)
rihp May 7, 2023
bd67082
Checkpoint
collijk May 7, 2023
57c4c30
Finish sketching out rough application loop
collijk May 7, 2023
b203de7
re-arch: Initial BudgetManager impl (#3919)
richbeales May 7, 2023
6017090
Command Base Class Interface (#3824)
DarylRodrigo May 7, 2023
3c3d420
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 7, 2023
2a803b0
Revise message broker interface
collijk May 7, 2023
1208e88
Pull in revised message broker
collijk May 7, 2023
5f2d54e
Resolve merge weirdness
collijk May 7, 2023
c47f826
Add emitter
collijk May 8, 2023
6063d80
Add emitter
collijk May 8, 2023
543c637
Merge branch 'revise-message-broker-interface' of github.com:collijk/…
collijk May 8, 2023
87fe2f1
Work out more of the message broker details. In good shape now, I think
collijk May 8, 2023
6d29213
This is the last change for a bit, I think
collijk May 8, 2023
f185833
Merge branch 'revise-message-broker-interface' of github.com:collijk/…
collijk May 8, 2023
989a2e1
Sketch out concrete simple budget manager
collijk May 8, 2023
a7b377b
This is the last change for a bit, I think
collijk May 8, 2023
5f6799d
Checkpoint
collijk May 8, 2023
74170c2
Finish sketching out agent provisioning
collijk May 8, 2023
b55d3ff
Added in a click entry point and status report (#4005)
Swiftyos May 9, 2023
b2ffa0a
Revise message broker interface (#3986)
collijk May 9, 2023
3c45505
Merge in upstream
collijk May 9, 2023
2c20cbf
Re-arch: plugins base (#3995)
ntindle May 9, 2023
31fae50
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 9, 2023
be87a5a
Work out provisional plugin interface and think through usage in the …
collijk May 9, 2023
935428b
Sketch out a better client/server relationship with an application se…
collijk May 10, 2023
437b448
More work on app server
collijk May 10, 2023
d00f5eb
Put together basic plugin service
collijk May 10, 2023
646a36d
Revise budget manager to work in hello world application (#4040)
collijk May 10, 2023
c5cec44
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 10, 2023
6d71656
Some status updates
collijk May 10, 2023
6f741cb
Sketch out objective prompt implementation
collijk May 10, 2023
8340852
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk May 10, 2023
4e5370e
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 10, 2023
3156404
Revise the initial implementation of the plugin manager interface to …
collijk May 10, 2023
790b113
Merge in plugin base revisions
collijk May 10, 2023
b871227
Can't set attrs on str
collijk May 10, 2023
645ce95
Respond to feedback
collijk May 11, 2023
411e9ce
Refactor llm subpackage
collijk May 11, 2023
1e0a37e
Merge in upstream
collijk May 11, 2023
e7dea81
Update language model init and status
collijk May 11, 2023
d7d2f0a
UPdate plugins
collijk May 11, 2023
b4190fb
Status note update for plugins after discussion with Nick
collijk May 11, 2023
d52b88a
Add credentials manager
collijk May 11, 2023
3960971
Language model for generating initial prompt
collijk May 11, 2023
0271c2f
Add base abstraction for credentials manager
collijk May 11, 2023
3f08acd
Clean up abstract inits
collijk May 11, 2023
d48bdad
Async def everything so far
collijk May 11, 2023
3b9b3b0
A bunch of clean up and organization
collijk May 12, 2023
997c376
Add chat parsing to language model
collijk May 12, 2023
51c3c1c
Workspace setup
collijk May 12, 2023
48a184e
Finish up bootstrapping loop
collijk May 12, 2023
1a48399
Build contexts for agent and agent factory, started working on agent …
collijk May 12, 2023
4627ee9
Fix broken import
collijk May 12, 2023
5eda16b
Re arch/http server (#4152)
dwrtz May 13, 2023
ed2b299
Re arch/cli stuff (#4154)
dwrtz May 13, 2023
0932090
Figure out right abstraction boundaries for model provider, language/…
collijk May 13, 2023
df58089
update status
collijk May 13, 2023
64bc1c7
Clean up model to use pydantic instead of dataclasses
collijk May 14, 2023
a703418
Add credentials service to plugin manager
collijk May 14, 2023
a87c623
Organize model imports
collijk May 14, 2023
cdab9be
Checkpoint
collijk May 14, 2023
e1a4b03
Formatting
collijk May 14, 2023
bcec593
Swap to pydantic in workspace
collijk May 15, 2023
75d79ef
Set up configuration objects with pydantic
collijk May 15, 2023
250cffa
Swap to pydantic in planner
collijk May 15, 2023
5c68db6
Swap to pydantic in model
collijk May 15, 2023
020ef1a
So much model fiddling, but cleaner lines now
collijk May 15, 2023
ff48d2e
Configuration properties should be system settins
collijk May 15, 2023
8563eea
Rework budget and interaction with providers
collijk May 15, 2023
2cf41fe
Reorganize to make resources a primary concern
collijk May 15, 2023
a27c4e8
Change config to agent settings
collijk May 15, 2023
23a32c2
Okay, back to trying to run through as the main test mechanism
collijk May 15, 2023
233f8ea
Configuration compilation works!
collijk May 15, 2023
1260d72
Export openai settings
collijk May 15, 2023
985f149
Setup cli command to write default settings
collijk May 16, 2023
d99bf40
Create default path and thread through
collijk May 16, 2023
c6238dc
Working up through getting the agent goals
collijk May 16, 2023
6c52744
Figure out how to set some configuration as user configurable and hav…
collijk May 16, 2023
77206ef
Fix credentialing
collijk May 16, 2023
94e2df7
Provision an agent
collijk May 16, 2023
2004c5e
app_lib -> client_lib
collijk May 16, 2023
83ef3f7
Clean up cli_web_app
collijk May 16, 2023
f272de5
webserver stuff working again
collijk May 16, 2023
01925d6
Agent loading successfully!
collijk May 16, 2023
a45850d
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk May 16, 2023
99f9d2d
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 16, 2023
6693007
Status updates
collijk May 16, 2023
a98ceab
Incorporate the language model into the planner directly
collijk May 17, 2023
d368b43
Formatting
collijk May 17, 2023
e9321b0
Do some work on planning
collijk May 18, 2023
c25414c
Start thinking seriously about commands
collijk May 21, 2023
62ded6a
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk May 21, 2023
dfe2d86
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk May 21, 2023
32d25ee
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 21, 2023
4cc3f22
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk May 30, 2023
6859008
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk May 30, 2023
39f2f36
Get system running again
collijk May 30, 2023
b66b8c2
Merge branch 'master' of github.com:collijk/Auto-GPT into agent-state…
collijk Jun 1, 2023
24f241d
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk Jun 1, 2023
4e6abeb
New planning strategies
collijk Jun 17, 2023
b01ede0
Remove bad null byte
collijk Jun 17, 2023
1bf04d0
Start sketching abilities
collijk Jun 17, 2023
2a6733a
Some logging
collijk Jun 17, 2023
276885f
Split up planning strategies
collijk Jun 17, 2023
1ed2136
Show logs
collijk Jun 17, 2023
667291a
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk Jun 17, 2023
6601d86
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk Jun 17, 2023
08634a3
Update abilities to use gpt function format
collijk Jun 18, 2023
6334ce8
Remove unused imports
collijk Jun 18, 2023
714f524
Remove dead import
collijk Jun 18, 2023
cc0eb5b
Update credentials and models
collijk Jun 18, 2023
2b72667
Name and goals working with new function calling api
collijk Jun 20, 2023
a53ac06
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk Jun 20, 2023
e4b151b
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk Jun 20, 2023
2675fe9
sketch remaining create chat completion command
collijk Jun 20, 2023
afff585
Work through ability registry
collijk Jun 20, 2023
209fa44
Formatting
collijk Jun 20, 2023
e85c211
load abilities into the registry
collijk Jun 20, 2023
09384fd
Work through initial plan
collijk Jun 20, 2023
1ddc335
Parse initial plan into tasks
collijk Jun 20, 2023
e315612
Make task context
collijk Jun 20, 2023
0930121
Up to choose next ability
collijk Jun 21, 2023
561d494
Determine next ability
collijk Jun 21, 2023
4f621aa
Work through task execution
collijk Jun 21, 2023
985399f
Add shape for task evaluation
collijk Jun 21, 2023
8d5a4f0
Update task cycle count
collijk Jun 21, 2023
f54e41c
Update task cycle count
collijk Jun 21, 2023
ca70305
Add ability skeleton to create new abilities
collijk Jun 21, 2023
9463bc1
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk Jun 21, 2023
d21e4a6
Merge branch 'agent-state-encapsulation' of github.com:Significant-Gr…
collijk Jun 21, 2023
d184792
[re-arch] Ability: Write File (#4787)
ntindle Jun 24, 2023
ed82cfd
Cleanup
collijk Jul 1, 2023
348e42b
Merge branch 'master' of github.com:Significant-Gravitas/Auto-GPT int…
collijk Jul 1, 2023
ff2cdfd
Merge in upstream
collijk Jul 1, 2023
ca09875
Merge branch 're-arch/hello-world' of github.com:Significant-Gravitas…
collijk Jul 1, 2023
3722eb1
Update existing abilities to return all fields in the AbilityResult (…
collijk Jul 2, 2023
a78b3a3
Simplify model provider credentials
collijk Jul 2, 2023
f111958
Fix bad changes to CI files
collijk Jul 4, 2023
f75c625
Delete unused packages
collijk Jul 4, 2023
55b9ac3
Ditch status code
collijk Jul 4, 2023
68089ca
Formatting
collijk Jul 4, 2023
3a01a4d
Autoflake
collijk Jul 4, 2023
cdb79c5
More formatting
collijk Jul 4, 2023
59ca5b9
Update name to default_settings
collijk Jul 4, 2023
e012a35
Fixes to config usage
collijk Jul 4, 2023
99e71dd
Formatting
collijk Jul 4, 2023
0deb658
Merge branch 'master' into re-arch/hello-world
collijk Jul 4, 2023
cc7ec30
Revert change in message history
collijk Jul 4, 2023
8c74069
Make configurable a generic class
collijk Jul 4, 2023
dd26b9a
Merge branch 're-arch/hello-world' of github.com:Significant-Gravitas…
collijk Jul 4, 2023
66c8947
Formatting
collijk Jul 4, 2023
5958f64
Merge branch 'master' into re-arch/hello-world
collijk Jul 4, 2023
c482fba
Add readme with run instructions
collijk Jul 5, 2023
72e2bc6
Merge branch 're-arch/hello-world' of github.com:Significant-Gravitas…
collijk Jul 5, 2023
81a81ca
Merge branch 'master' into re-arch/hello-world
collijk Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions autogpt/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from autogpt.core.agent import Agent
from autogpt.core.budget import BudgetManager
from autogpt.core.command import Command, CommandRegistry
from autogpt.core.configuration import Configuration
from autogpt.core.llm import LanguageModel
from autogpt.core.logging import Logger
from autogpt.core.memory import MemoryBackend
from autogpt.core.messaging import Message, MessageBroker
from autogpt.core.planning import Planner
from autogpt.core.plugin import Plugin, PluginManager
from autogpt.core.workspace import Workspace
2 changes: 2 additions & 0 deletions autogpt/core/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""The Agent is an autonomouos entity guided by a LLM provider."""
from autogpt.core.agent.base import Agent
107 changes: 107 additions & 0 deletions autogpt/core/agent/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from __future__ import annotations

import abc
import logging
from importlib import import_module
from typing import List, Tuple, Type

from autogpt.core.budget import BudgetManager
from autogpt.core.command import CommandRegistry
from autogpt.core.configuration import Configuration
from autogpt.core.llm import LanguageModel
from autogpt.core.logging import Logger
from autogpt.core.memory import MemoryBackend
from autogpt.core.messaging import MessageBroker
from autogpt.core.planning import Planner
from autogpt.core.plugin import PluginManager
from autogpt.core.workspace import Workspace


class Agent(abc.ABC):
def __init__(
self,
configuration: Configuration,
logger: Logger,
budget_manager: BudgetManager,
command_registry: CommandRegistry,
language_model: LanguageModel,
memory_backend: MemoryBackend,
message_broker: MessageBroker,
planner: Planner,
plugin_manager: PluginManager,
workspace: Workspace,
):
self.configuration = configuration
self.logger = logger

self.budget_manager = budget_manager
self.command_registry = command_registry
self.language_model = language_model
self.memory_backend = memory_backend
self.message_broker = message_broker
self.planner = planner
self.plugin_manager = plugin_manager
self.workspace = workspace


@classmethod
@abc.abstractmethod
def from_workspace(cls, workpace_path: Workspace, message_broker: MessageBroker) -> Agent:
pass


@abc.abstractmethod
def run(self):
pass


class AgentFactory:

configuration_defaults = {
# Which subsystems to use. These must be subclasses of the base classes,
# but could come from plugins.
'system': {
'budget_manager': 'autogpt.core.budget.BudgetManager',
'command_registry': 'autogpt.core.command.CommandRegistry',
'language_model': 'autogpt.core.llm.LanguageModel',
'memory_backend': 'autogpt.core.memory.MemoryBackend',
'planner': 'autogpt.core.planning.Planner',
}
}

def __init__(self, logger: logging.Logger):
self._logger = logger

def compile_configuration(self, user_configuration: dict) -> Tuple[Configuration, List[str]]:
"""Compile the user's configuration with the defaults."""

configuration_dict = self.configuration_defaults
# Copy so we're not mutating the data structure we're looping over.
system_defaults = self.configuration_defaults['system'].copy()
# Build up default configuration
for system_name in system_defaults:
system_class = self.get_system_class(system_name, user_configuration)
configuration_dict.update(system_class.configuration_defaults)

# Apply user overrides
configuration_dict.update(user_configuration)

# TODO: Validate the user configuration and compile errors.
agent_configuration = Configuration(configuration_dict)
configuration_errors = []
return agent_configuration, configuration_errors

def get_system_class(self, system_name, configuration: dict | Configuration):
"""Get the system class for the given configuration."""
if isinstance(configuration, Configuration):
configuration = configuration.to_dict()

default_system_import_path = self.configuration_defaults['system'][system_name]
system_import_path = configuration['system'].get(system_name, default_system_import_path)

module_path, _, class_name = system_import_path.rpartition(".")
module = import_module(module_path)
system_class = getattr(module, class_name)

return system_class

Empty file.
87 changes: 87 additions & 0 deletions autogpt/core/app_sketch/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import logging

from autogpt.core.app_sketch.server import bootstrap_agent, launch_agent
from autogpt.core.messaging.simple import SimpleMessageBroker


def configure_application_logging(
application_logger: logging.Logger,
file_based_configuration: dict,
command_line_arguments: dict,
):
application_logger.setLevel(logging.DEBUG)


def start_message_broker(application_logger) -> SimpleMessageBroker:
# This can take a lot of different forms. E.g. if I'm building an app that connects
# to an existing agent on a server, I might just need to connect to a websocket.
# If I'm launching a bunch of agents on a cluster, I might need to stand up a
# message broker process like redis and launch an Agent factory process.
# We're going to do some in-process setup for now by wiring up a simple message
# broker and registering a listener for the user_objective message.

message_broker = SimpleMessageBroker(application_logger)

# This would happen on the "server" side, but hook here because we're
# doing everything in-process.
# FIXME: I'm misuing message channels here. Message broker needs to be set up
# so that register_listener can subscribe to a channel and filter messages
# based on their metadata.
message_broker.register_listener(
"user_objective",
bootstrap_agent,
)
message_broker.register_listener(
"launch_agent",
launch_agent,
)

message_broker.register_listener(
"agent_setup",
lambda message: application_logger.info(message.content["message"]),
)
message_broker.register_listener(
"agent_setup_complete",
lambda x: None,
)

return message_broker


def run_auto_gpt(
file_based_configuration: dict, # Need to figure out what's in here
command_line_arguments: dict, # Need to figure out what's in here
):
# Configure logging before we do anything else.
# Application logs need a place to live.
application_logger = logging.getLogger("autogpt")
configure_application_logging(
application_logger,
file_based_configuration,
command_line_arguments,
)

message_broker = start_message_broker(application_logger)

# This application either starts an existing agent or builds a new one.
if command_line_arguments['agent_name'] is None:
# Find out the user's objective for the new agent.
user_objective = input(...)
# Construct a message to send to the agent. Real format TBD.
user_objective_message = {
# This might be like a websocket, (hostname, port) tuple, or something else.
"message_broker": message_broker,
# These will need structures with some strongly-enforced fields to be
# interpreted by the bootstrapping system.
# Command line arguments override file-based configuration.
"user_configuration": file_based_configuration.update(command_line_arguments),
"user_objective": user_objective,
}
message_broker.send_message("user_objective", user_objective_message)

launch_agent_message = {
"message_broker": message_broker,
"agent": command_line_arguments['agent_name'],
}
message_broker.send_message("launch_agent", launch_agent_message)

112 changes: 112 additions & 0 deletions autogpt/core/app_sketch/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import logging

from autogpt.core.agent.base import AgentFactory, Agent
from autogpt.core.messaging.base import Message


def configure_agent_factory_logging(
agent_factory_logger: logging.Logger,
):
agent_factory_logger.setLevel(logging.DEBUG)


def get_agent_factory():
# Configure logging before we do anything else.
# Factory logs need a place to live.
agent_factory_logger = logging.getLogger("autogpt_agent_factory")
configure_agent_factory_logging(
agent_factory_logger,
)
return AgentFactory(agent_factory_logger)


def bootstrap_agent(
message: Message,
):
"""Provision a new agent by getting an objective from the user and setting up agent resources."""
# TODO: this could be an already running process we communicate with via the
# message broker. For now, we'll just do it in-process.
agent_factory = get_agent_factory()

message_content = message.content
message_broker = message_content["message_broker"]
user_configuration = message_content["user_configuration"]
user_objective = message_content["user_objective"]

message_broker.send_message(
"agent_setup",
{"message": "Startup request received, Setting up agent..."},
)

# Either need to do validation as we're building the configuration, or shortly
# after.
configuration, configuration_errors = agent_factory.compile_configuration(
user_configuration,
)
if configuration_errors:
message_broker.send_message(
"agent_setup",
{"message": "Configuration errors encountered, aborting agent setup.",
"errors": configuration_errors},
)
return

message_broker.send_message(
"agent_setup",
{"message": "Agent configuration compiled. Constructing initial agent plan from user objective.",
"configuration": configuration},
)

agent_planner = agent_factory.get_system_class('planner', configuration)
# TODO: is this a class method? Or do we have the planner be partially initialized
# without access to any resources since this precedes Agent creation?
objective_prompt = agent_planner.construct_objective_prompt_from_user_input(
user_objective,
)

message_broker.send_message(
"agent_setup",
{"message": "Translated user input into objective prompt.",
"user_objective": user_objective,
"objective_prompt": objective_prompt},
)

language_model = agent_factory.get_system_class('language_model', configuration)
# TODO: is this a class method? Or do we have the language model be
# partially initialized without access to any resources since this precedes
# Agent creation?
model_response = language_model.construct_objective_from_prompt(objective_prompt)
# This should be parsed into a standard format already
agent_objective = model_response.content

message_broker.send_message(
"agent_setup",
{"message": "Translated objective prompt into objective.",
"objective_prompt": objective_prompt,
"objective": agent_objective},
)
# ...Update API budget, etc. ...

# TODO: Set up workspace
# TODO: Provision memory backend

message_broker.send_message(
"agent_setup_complete",
{"message": "Agent setup complete."}
)


def _get_workspace_path_from_agent_name(agent_name: str) -> str:
# FIXME: Very much a stand-in for later logic. This could be a whole agent registry
# system and probably lives on the client side instead of here
return f"~/autogpt_workspace/{agent_name}"


def launch_agent(message: Message):
message_content = message.content
message_broker = message_content["message_broker"]
agent_name = message_content["agent_name"]
workspace_path = _get_workspace_path_from_agent_name(agent_name)

agent = Agent.from_workspace(workspace_path, message_broker)
agent.run()
2 changes: 2 additions & 0 deletions autogpt/core/budget/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""The budget subsystem manages resource limits for the Agent."""
from autogpt.core.budget.base import BudgetManager
5 changes: 5 additions & 0 deletions autogpt/core/budget/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import abc


class BudgetManager(abc.ABC):
pass
2 changes: 2 additions & 0 deletions autogpt/core/command/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""The command system provides a way to extend the functionality of the AI agent."""
from autogpt.core.command.base import Command, CommandRegistry
9 changes: 9 additions & 0 deletions autogpt/core/command/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import abc


class Command(abc.ABC):
pass


class CommandRegistry(abc.ABC):
pass
2 changes: 2 additions & 0 deletions autogpt/core/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""The configuration encapsulates settings for all Agent subsystems."""
from autogpt.core.configuration.base import Configuration
Loading