Skip to content

Commit

Permalink
Merge branch 'master' into validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam97 committed Feb 14, 2024
2 parents ebcfb96 + 32a627e commit 9ee5abf
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 64 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/autogpt-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ defaults:
run:
working-directory: autogpts/autogpt

env:
TELEMETRY_ENVIRONMENT: autogpt-ci
TELEMETRY_OPT_IN: ${{ github.event_name == 'push' && github.ref_name == 'master' }}

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/autogpt-docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ env:
DEPLOY_IMAGE_NAME: ${{ secrets.DOCKER_USER }}/auto-gpt
DEV_IMAGE_TAG: latest-dev

TELEMETRY_ENVIRONMENT: autogpt-docker-ci
TELEMETRY_OPT_IN: ${{ github.event_name == 'push' && github.ref_name == 'master' }}

jobs:
build:
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/autogpts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ on:
- 'setup.py'
- '!**/*.md'

env:
TELEMETRY_ENVIRONMENT: autogpt-ci
TELEMETRY_OPT_IN: ${{ github.event_name == 'push' && github.ref_name == 'master' }}

jobs:
run-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -56,7 +60,7 @@ jobs:
run: |
./run agent start ${{ matrix.agent-name }}
cd autogpts/${{ matrix.agent-name }}
poetry run agbenchmark --mock
poetry run agbenchmark --mock --test=BasicRetrieval --test=Battleship --test=WebArenaTask_0
poetry run agbenchmark --test=WriteFile
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/benchmark-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:

env:
min-python-version: '3.10'
TELEMETRY_ENVIRONMENT: autogpt-benchmark-ci
TELEMETRY_OPT_IN: ${{ github.event_name == 'push' && github.ref_name == 'master' }}

jobs:
lint:
Expand Down
7 changes: 7 additions & 0 deletions autogpts/autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from forge.sdk.routes.agent_protocol import base_router
from hypercorn.asyncio import serve as hypercorn_serve
from hypercorn.config import Config as HypercornConfig
from sentry_sdk import set_user

from autogpt.agent_factory.configurators import configure_agent_with_state
from autogpt.agent_factory.generators import generate_agent_for_task
Expand Down Expand Up @@ -121,6 +122,9 @@ async def create_task(self, task_request: TaskRequestBody) -> Task:
"""
Create a task for the agent.
"""
if user_id := (task_request.additional_input or {}).get("user_id"):
set_user({"id": user_id})

task = await self.db.create_task(
input=task_request.input,
additional_input=task_request.additional_input,
Expand Down Expand Up @@ -180,6 +184,9 @@ async def execute_step(self, task_id: str, step_request: StepRequestBody) -> Ste
llm_provider=self._get_task_llm_provider(task),
)

if user_id := (task.additional_input or {}).get("user_id"):
set_user({"id": user_id})

# According to the Agent Protocol spec, the first execute_step request contains
# the same task input as the parent create_task request.
# To prevent this from interfering with the agent's process, we ignore the input
Expand Down
14 changes: 10 additions & 4 deletions autogpts/autogpt/autogpt/app/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from .utils import env_file_exists, set_env_config_value
from .utils import env_file_exists, get_git_user_email, set_env_config_value


def setup_telemetry() -> None:
Expand All @@ -16,9 +16,12 @@ def setup_telemetry() -> None:
allow_telemetry = click.prompt(
"❓ Do you want to enable telemetry? ❓\n"
"This means AutoGPT will send diagnostic data to the core development team "
"when something goes wrong, and will help us to diagnose and fix problems "
"earlier and faster.\n"
"Please enter 'yes' or 'no'",
"when something goes wrong,\nand will help us to diagnose and fix problems "
"earlier and faster.\n\n"
"By entering 'yes', you agree that you have read and agree to our Privacy"
" Policy available here:\n"
"https://www.notion.so/auto-gpt/Privacy-Policy-ab11c9c20dbd4de1a15dcffe84d77984"
"\n\nPlease enter 'yes' or 'no'",
type=bool,
)
set_env_config_value("TELEMETRY_OPT_IN", "true" if allow_telemetry else "false")
Expand All @@ -38,3 +41,6 @@ def _setup_sentry() -> None:
dsn="https://dc266f2f7a2381194d1c0fa36dff67d8@o4505260022104064.ingest.sentry.io/4506739844710400", # noqa
environment=os.getenv("TELEMETRY_ENVIRONMENT"),
)

# Allow Sentry to distinguish between users
sentry_sdk.set_user({"email": get_git_user_email(), "ip_address": "{{auto}}"})
8 changes: 8 additions & 0 deletions autogpts/autogpt/autogpt/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def get_current_git_branch() -> str:
return ""


def get_git_user_email() -> str:
try:
repo = Repo(search_parent_directories=True)
return repo.config_reader().get_value("user", "email", default="")
except InvalidGitRepositoryError:
return ""


def get_latest_bulletin() -> tuple[str, bool]:
exists = os.path.exists("data/CURRENT_BULLETIN.md")
current_bulletin = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ async def create_chat_completion(
tool_calls=(
[AssistantToolCall(**tc.dict()) for tc in _assistant_msg.tool_calls]
if _assistant_msg.tool_calls
else None
else list()
),
)
response = ChatModelResponse(
Expand Down Expand Up @@ -466,6 +466,7 @@ async def create_chat_completion(
extras={"assistant_msg": assistant_msg, "i_attempt": attempts},
)
if attempts < self._configuration.fix_failed_parse_tries:
model_prompt.append(assistant_msg)
model_prompt.append(
ChatMessage.system(f"ERROR PARSING YOUR RESPONSE:\n\n{e}")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ class Role(str, enum.Enum):
SYSTEM = "system"
ASSISTANT = "assistant"

TOOL = "tool"
"""May be used for the result of tool calls"""
FUNCTION = "function"
"""May be used for the return value of function calls"""

role: Role
content: str

@staticmethod
def assistant(content: str) -> "ChatMessage":
return ChatMessage(role=ChatMessage.Role.ASSISTANT, content=content)

@staticmethod
def user(content: str) -> "ChatMessage":
return ChatMessage(role=ChatMessage.Role.USER, content=content)
Expand Down Expand Up @@ -93,7 +91,7 @@ class AssistantToolCallDict(TypedDict):
class AssistantChatMessage(ChatMessage):
role: Literal["assistant"] = "assistant"
content: Optional[str]
tool_calls: Optional[list[AssistantToolCall]]
tool_calls: list[AssistantToolCall] = Field(default_factory=list)


class AssistantChatMessageDict(TypedDict, total=False):
Expand Down
10 changes: 5 additions & 5 deletions autogpts/autogpt/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion autogpts/autogpt/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serve = "autogpt.app.cli:serve"
python = "^3.10"
auto-gpt-plugin-template = {git = "https://github.com/Significant-Gravitas/Auto-GPT-Plugin-Template", rev = "0.1.0"}
# autogpt-forge = { path = "../forge" }
autogpt-forge = {git = "https://github.com/Significant-Gravitas/AutoGPT.git", rev = "6763196d78603808dcbb", subdirectory = "autogpts/forge"}
autogpt-forge = {git = "https://github.com/Significant-Gravitas/AutoGPT.git", rev = "ab05b7ae70754c063909", subdirectory = "autogpts/forge"}
beautifulsoup4 = "^4.12.2"
boto3 = "^1.33.6"
charset-normalizer = "^3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion autogpts/forge/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions benchmark/agbenchmark/agent_api_interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import time
from pathlib import Path
from typing import AsyncIterator, Optional
Expand All @@ -23,6 +22,8 @@ async def run_api_agent(
config: AgentBenchmarkConfig,
timeout: int,
artifacts_location: Optional[Path] = None,
*,
mock: bool = False,
) -> AsyncIterator[Step]:
configuration = Configuration(host=config.host)
async with ApiClient(configuration) as api_client:
Expand All @@ -36,26 +37,32 @@ async def run_api_agent(
task_id = response.task_id

if artifacts_location:
logger.debug("Uploading task input artifacts to agent...")
await upload_artifacts(
api_instance, artifacts_location, task_id, "artifacts_in"
)

logger.debug("Running agent until finished or timeout...")
while True:
step = await api_instance.execute_agent_task_step(task_id=task_id)
yield step

if time.time() - start_time > timeout:
raise TimeoutError("Time limit exceeded")
if step and mock:
step.is_last = True
if not step or step.is_last:
break

if artifacts_location:
# In "mock" mode, we cheat by giving the correct artifacts to pass the test
if os.getenv("IS_MOCK"):
if mock:
logger.debug("Uploading mock artifacts to agent...")
await upload_artifacts(
api_instance, artifacts_location, task_id, "artifacts_out"
)

logger.debug("Downloading agent artifacts...")
await download_agent_artifacts_into_folder(
api_instance, task_id, config.temp_folder
)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/agbenchmark/challenges/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_method(

@classmethod
async def run_challenge(
cls, config: AgentBenchmarkConfig, timeout: int
cls, config: AgentBenchmarkConfig, timeout: int, *, mock: bool = False
) -> AsyncIterator[Step]:
"""
Runs the challenge on the subject agent with the specified timeout.
Expand Down Expand Up @@ -89,7 +89,7 @@ async def run_challenge(
logger.debug(f"Starting {cls.info.name} challenge run")
i = 0
async for step in run_api_agent(
cls.info.task, config, timeout, cls.info.task_artifacts_dir
cls.info.task, config, timeout, cls.info.task_artifacts_dir, mock=mock
):
i += 1
print(f"[{cls.info.name}] - step {step.name} ({i}. request)")
Expand Down

0 comments on commit 9ee5abf

Please sign in to comment.