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

feat(forge): Implement a very very bad, but "functional" agent by default #7021

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f8e9582
fix: remove json_encoders. FastAPI does that by default
ntindle Mar 17, 2024
26b902d
fix: typing and return objects
ntindle Mar 17, 2024
177d62f
fix: type fixes on the parameters
ntindle Mar 17, 2024
d22762c
fix: windows won't load actions
ntindle Mar 17, 2024
a655ebf
fix: remove swifty's paths
ntindle Mar 17, 2024
2f394d3
fix: type hinting
ntindle Mar 17, 2024
7090ca7
feat: add note about execute_step in the sdk
ntindle Mar 17, 2024
a00f65e
fix: remove circular import
ntindle Mar 17, 2024
a8741db
fix: abilities -> Actions
ntindle Mar 17, 2024
5dff243
fix: windows compatibility
ntindle Mar 17, 2024
3604484
feat: basic agent rather than just returning washington dc
ntindle Mar 17, 2024
be4f0d5
fix: uncommented line
ntindle Mar 17, 2024
fe966c8
Merge branch 'master' into forge/fixes
ntindle Apr 3, 2024
fb60162
Merge branch 'master' into forge/fixes
ntindle Apr 19, 2024
ef6cc4a
fix: linting error
ntindle Apr 20, 2024
aed8f0e
fix: pull request changes
ntindle Apr 20, 2024
2899e60
fix: isort
ntindle Apr 22, 2024
87eabfd
Merge branch 'forge/fixes' of https://github.com/Significant-Gravitas…
ntindle Apr 22, 2024
4fc9735
fix: isort after merge
ntindle Apr 22, 2024
b215505
fix: incorrectly refactored param template-> template_name
ntindle Apr 22, 2024
36d66c6
fix: docstring
ntindle Apr 22, 2024
94962df
Merge branch 'master' into forge/fixes
ntindle Apr 22, 2024
960fe39
Merge branch 'master' into forge/fixes
ntindle Apr 22, 2024
9d7672f
Merge branch 'master' into forge/fixes
ntindle Apr 27, 2024
1d50476
Merge branch 'master' into forge/fixes
ntindle Apr 29, 2024
9728fec
Merge branch 'master' into forge/fixes
ntindle Apr 30, 2024
2af3724
Merge branch 'master' into forge/fixes
ntindle May 1, 2024
45b6867
Merge branch 'master' into forge/fixes
ntindle May 2, 2024
26b582c
Merge branch 'master' into forge/fixes
ntindle May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions autogpts/forge/forge/__main__.py
Expand Up @@ -17,9 +17,9 @@
d88P 888 888 888 888 888 888 888 888 888 888
d8888888888 Y88b 888 Y88b. Y88..88P Y88b d88P 888 888
d88P 888 "Y88888 "Y888 "Y88P" "Y8888P88 888 888
8888888888
888
888
Expand Down
58 changes: 30 additions & 28 deletions autogpts/forge/forge/actions/file_system/files.py
@@ -1,22 +1,24 @@
from typing import List

from ..registry import action
from forge.sdk.agent import Agent

from ..registry import ActionParameter, action


@action(
name="list_files",
description="List files in a directory",
parameters=[
{
"name": "path",
"description": "Path to the directory",
"type": "string",
"required": True,
}
ActionParameter(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type fix

name="path",
description="Path to the directory",
type="string",
required=True,
)
],
output_type="list[str]",
)
async def list_files(agent, task_id: str, path: str) -> List[str]:
async def list_files(agent: Agent, task_id: str, path: str) -> List[str]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hint

"""
List files in a workspace directory
"""
Expand All @@ -27,22 +29,22 @@ async def list_files(agent, task_id: str, path: str) -> List[str]:
name="write_file",
description="Write data to a file",
parameters=[
{
"name": "file_path",
"description": "Path to the file",
"type": "string",
"required": True,
},
{
"name": "data",
"description": "Data to write to the file",
"type": "bytes",
"required": True,
},
ActionParameter(
name="file_path",
description="Path to the file",
type="string",
required=True,
),
ActionParameter(
name="data",
description="Data to write to the file",
type="bytes",
required=True,
),
],
output_type="None",
)
async def write_file(agent, task_id: str, file_path: str, data: bytes):
async def write_file(agent: Agent, task_id: str, file_path: str, data: bytes):
"""
Write data to a file
"""
Expand All @@ -62,16 +64,16 @@ async def write_file(agent, task_id: str, file_path: str, data: bytes):
name="read_file",
description="Read data from a file",
parameters=[
{
"name": "file_path",
"description": "Path to the file",
"type": "string",
"required": True,
},
ActionParameter(
name="file_path",
description="Path to the file",
type="string",
required=True,
)
],
output_type="bytes",
)
async def read_file(agent, task_id: str, file_path: str) -> bytes:
async def read_file(agent: Agent, task_id: str, file_path: str) -> bytes:
"""
Read data from a file
"""
Expand Down
18 changes: 10 additions & 8 deletions autogpts/forge/forge/actions/finish.py
@@ -1,6 +1,7 @@
from forge.sdk.agent import Agent
from forge.sdk.forge_log import ForgeLogger

from .registry import action
from .registry import ActionParameter, action

logger = ForgeLogger(__name__)

Expand All @@ -11,17 +12,17 @@
" or when there are insurmountable problems that make it impossible"
" for you to finish your task.",
parameters=[
{
"name": "reason",
"description": "A summary to the user of how the goals were accomplished",
"type": "string",
"required": True,
}
ActionParameter(
name="reason",
description="A summary to the user of how the goals were accomplished",
type="string",
required=True,
)
],
output_type="None",
)
async def finish(
agent,
agent: Agent,
task_id: str,
reason: str,
) -> str:
Expand All @@ -34,5 +35,6 @@ async def finish(
A result string from create chat completion. A list of suggestions to
improve the code.
"""

logger.info(reason, extra={"title": "Shutting down...\n"})
return reason
19 changes: 12 additions & 7 deletions autogpts/forge/forge/actions/registry.py
Expand Up @@ -112,9 +112,11 @@ def register_abilities(self) -> None:
"__init__.py",
"registry.py",
]:
action = os.path.relpath(
action_path, os.path.dirname(__file__)
).replace("/", ".")
action = (
os.path.relpath(action_path, os.path.dirname(__file__))
.replace("\\", "/")
.replace("/", ".")
)
try:
module = importlib.import_module(
f".{action[:-3]}", package="forge.actions"
Expand Down Expand Up @@ -185,9 +187,12 @@ async def run_action(


if __name__ == "__main__":
import asyncio
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swifty removal and replacement with more amenable action to not actually having an agent seeded. list_files requires a full agent to be able to be pulled in to actually work

import sys

sys.path.append("/Users/swifty/dev/forge/forge")
register = ActionRegister(agent=None)
print(register.abilities_description())
print(register.run_action("abc", "list_files", "/Users/swifty/dev/forge/forge"))
async def run():
register = ActionRegister(agent=None)
print(register.abilities_description())
print(await register.run_action("abc", "finish", "./registry.py"))

asyncio.run(run())
18 changes: 10 additions & 8 deletions autogpts/forge/forge/actions/web/web_search.py
Expand Up @@ -5,7 +5,9 @@

from duckduckgo_search import DDGS

from ..registry import action
from forge.sdk.agent import Agent

from ..registry import ActionParameter, action

DUCKDUCKGO_MAX_ATTEMPTS = 3

Expand All @@ -14,16 +16,16 @@
name="web_search",
description="Searches the web",
parameters=[
{
"name": "query",
"description": "The search query",
"type": "string",
"required": True,
}
ActionParameter(
name="query",
description="The search query",
type="string",
required=True,
)
],
output_type="list[str]",
)
async def web_search(agent, task_id: str, query: str) -> str:
async def web_search(agent: Agent, task_id: str, query: str) -> str:
"""Return the results of a Google search
Args:
Expand Down
44 changes: 25 additions & 19 deletions autogpts/forge/forge/actions/web/web_selenium.py
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from forge.sdk.agent import Agent

COMMAND_CATEGORY = "web_browse"
COMMAND_CATEGORY_TITLE = "Web Browsing"

Expand Down Expand Up @@ -38,7 +40,7 @@

from forge.sdk.errors import CommandExecutionError

from ..registry import action
from ..registry import ActionParameter, action


def extract_hyperlinks(soup: BeautifulSoup, base_url: str) -> list[tuple[str, str]]:
Expand Down Expand Up @@ -185,25 +187,25 @@ class BrowsingError(CommandExecutionError):
name="read_webpage",
description="Read a webpage, and extract specific information from it if a question is specified. If you are looking to extract specific information from the webpage, you should specify a question.",
parameters=[
{
"name": "url",
"description": "The URL to visit",
"type": "string",
"required": True,
},
{
"name": "question",
"description": "A question that you want to answer using the content of the webpage.",
"type": "string",
"required": False,
},
ActionParameter(
name="url",
description="The URL to visit",
type="string",
required=True,
),
ActionParameter(
name="question",
description="A question that you want to answer using the content of the webpage.",
type="string",
required=False,
),
],
output_type="string",
)
@validate_url
async def read_webpage(
agent, task_id: str, url: str, question: str = ""
) -> Tuple(str, List[str]):
agent: Agent, task_id: str, url: str, question: str = ""
) -> Tuple(str, list[str]):
"""Browse a website and return the answer and links to the user

Args:
Expand Down Expand Up @@ -231,7 +233,9 @@ async def read_webpage(
except WebDriverException as e:
# These errors are often quite long and include lots of context.
# Just grab the first line.
msg = e.msg.split("\n")[0]
msg = "An error occurred while trying to load the page"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type fix

if e.msg:
msg = e.msg.split("\n")[0]
if "net::" in msg:
raise BrowsingError(
f"A networking error occurred while trying to load the page: "
Expand Down Expand Up @@ -340,9 +344,11 @@ def open_page_in_browser(url: str) -> WebDriver:
chromium_driver_path = Path("/usr/bin/chromedriver")

driver = ChromeDriver(
service=ChromeDriverService(str(chromium_driver_path))
if chromium_driver_path.exists()
else ChromeDriverService(ChromeDriverManager().install()),
service=(
ChromeDriverService(str(chromium_driver_path))
if chromium_driver_path.exists()
else ChromeDriverService(ChromeDriverManager().install())
),
options=options,
)
driver.get(url)
Expand Down