Skip to content

Commit

Permalink
style: Pass ruff check (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandansamax authored Sep 11, 2024
1 parent 3b36289 commit b9ddf11
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 43 deletions.
3 changes: 2 additions & 1 deletion crab/agents/backend_models/gemini_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def call_api(self, request_messages: list):
)
except ResourceExhausted:
print(
"ResourceExhausted: 429 Resource has been exhausted. Please waiting..."
"ResourceExhausted: 429 Resource has been exhausted.",
" Please waiting...",
)
sleep(10)
else:
Expand Down
57 changes: 30 additions & 27 deletions crab/agents/policies/multi_agent_by_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,38 @@


class MultiAgentByEnvPolicy(AgentPolicy):
_main_agent_prompt = """You are a main agent, and your goal is to plan and give
instructions to sub-agents in each environment to complete the final task. Now you have
to do a task as described below: {task_description}.
The description of each given environment: {env_description}.
For each step, you are required to provide high-level instructions detailing the next
actions to be taken. Additionally, you must specify which sub-agent in the designated
environment should execute these instructions. If a sub-agent is not needed for a
particular step, you may instruct it to skip that step."""
_main_agent_prompt = """You are a main agent, and your goal is to plan and
give instructions to sub-agents in each environment to complete the final task. Now
you have to do a task as described below: {task_description}. The description of
each given environment: {env_description}. For each step, you are required to
provide high-level instructions detailing the next actions to be taken.
Additionally, you must specify which sub-agent in the designated environment should
execute these instructions. If a sub-agent is not needed for a particular step, you
may instruct it to skip that step."""

_env_agent_prompt = """You are a sub-agent responsible for the {environment} environment.
The description of the {environment} environment is: {env_description}.
Your goal is to assist the main agent in completing the final task by performing actions
in the {environment} environment according to the instructions from the main agent. The
final task is described below: {task_description}. A unit operation you can perform is called
action in a given environment. You can only execute action in the {environment}
environment. For the {environment} environment, you are given a limited action space as
function calls:
_env_agent_prompt = """You are a sub-agent responsible for the {environment}
environment. The description of the {environment} environment is:
{env_description}. Your goal is to assist the main agent in completing the final
task by performing actions in the {environment} environment according to the
instructions from the main agent. The final task is described below:
{task_description}. A unit operation you can perform is called action in a given
environment. You can only execute action in the {environment} environment. For the
{environment} environment, you are given a limited action space as function calls:
{action_descriptions}
The interactive UI elements on the screenshot are labeled with numeric tags starting
from 1. For each step, You will receive an instruction telling you what you need to do
next. After analyzing the instruction you received and the current {environment} system,
if you think you don't need to do anything in the current {environment} system, you should
choose SKIP action. Otherwise, you must state what actions to take, what the parameters
are, and you MUST provide in which environment to perform these actions. Your answer
must be function calls. Please do not output any other information. You must make sure
all function calls get their required parameters."""
from 1. For each step, You will receive an instruction telling you what you need to
do next. After analyzing the instruction you received and the current {environment}
system, if you think you don't need to do anything in the current {environment}
system, you should choose SKIP action. Otherwise, you must state what actions to
take, what the parameters are, and you MUST provide in which environment to perform
these actions. Your answer must be function calls. Please do not output any other
information. You must make sure all function calls get their required parameters."""

_root_agent_prompt = """You are a sub-agent responsible for the crab benchmark root
environment. Your goal is to assist the main agent in completing the whole task:
"{task_description}". You can only complete the task or submit the result when the main
agent tells you the whole task has been completed. Otherwise, you can only call SKIP.
"""
"{task_description}". You can only complete the task or submit the result when the
main agent tells you the whole task has been completed. Otherwise, you can only call
SKIP. """

def __init__(
self,
Expand Down Expand Up @@ -119,7 +119,10 @@ def chat(
main_prompt.extend(observation[env])
main_prompt.append(
(
f"Your target: {self.task_description}\nTell me the next step in each environment.",
(
f"Your target: {self.task_description}\n"
"Tell me the next step in each environment."
),
MessageType.TEXT,
)
)
Expand Down
20 changes: 10 additions & 10 deletions crab/agents/policies/multi_agent_by_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@

class MultiAgentByFuncPolicy(AgentPolicy):
_system_prompt = """You are a helpful assistant. Now you have to do a task as
described below: {task_description}. And this is the description of each given environment:
{env_description}. A unit operation you can perform is called action in a
given environment. For each environment, you are given a limited action space as
described below: {task_description}. And this is the description of each given
environment: {env_description}. A unit operation you can perform is called action in
a given environment. For each environment, you are given a limited action space as
function calls:
{action_descriptions}
You may receive a screenshot of the current system. The interactive UI elements on the
screenshot are labeled with numeric tags starting from 1. For each step, You must state
what actions to take, what the parameters are, and you MUST provide in which environment
to perform these actions. """
You may receive a screenshot of the current system. The interactive UI elements on
the screenshot are labeled with numeric tags starting from 1. For each step, You
must state what actions to take, what the parameters are, and you MUST provide in
which environment to perform these actions. """

_tool_prompt = """You are a helpful assistant in generating function calls. I will give
you a detailed description of what actions to take next, you should translate it into
function calls. please do not output any other information.
_tool_prompt = """You are a helpful assistant in generating function calls. I will
give you a detailed description of what actions to take next, you should translate
it into function calls. please do not output any other information.
"""

def __init__(
Expand Down
6 changes: 4 additions & 2 deletions crab/core/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def execute_action(self, response: list[ActionOutput]) -> bool:
return True
print(
"\033[92m"
f'Action "{action.name}" in env "{action.env}" success. current evaluation results: {self.metrics}\n'
f'Action "{action.name}" in env "{action.env}" success. '
f"Current evaluation results: {self.metrics}\n"
"\033[0m"
)
self.write_current_log_row(action)
Expand Down Expand Up @@ -193,7 +194,8 @@ def start_benchmark(self):
env_descriptions=env_description,
)
print(
f'Start benchmark "{self.benchmark.name}", task id "{self.task.id}": "{self.task.description}"'
f'Start benchmark "{self.benchmark.name}", task id "{self.task.id}": '
f'"{self.task.description}"'
)
self.init_log_dir()
self.step_cnt = 0
Expand Down
5 changes: 4 additions & 1 deletion test/agents/backend_models/test_claude_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def test_text_chat(claude_model_text):
def test_action_chat(claude_model_text):
claude_model_text.reset("You are a helpful assistant.", [add])
message = (
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
(
"I had 10 dollars. Miss Polaris gave me 15 dollars."
" How many money do I have now."
),
0,
)
output = claude_model_text.chat(message)
Expand Down
5 changes: 4 additions & 1 deletion test/agents/backend_models/test_gemini_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def test_text_chat(gemini_model_text):
def test_action_chat(gemini_model_text):
gemini_model_text.reset("You are a helpful assistant.", [add])
message = (
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
(
"I had 10 dollars. Miss Polaris gave me 15 dollars. "
"How many money do I have now."
),
0,
)
output = gemini_model_text.chat(message)
Expand Down
5 changes: 4 additions & 1 deletion test/agents/backend_models/test_openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def test_text_chat(mock_create, openai_model_text):
def test_action_chat(mock_create, openai_model_text):
openai_model_text.reset("You are a helpful assistant.", [add])
message = (
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
(
"I had 10 dollars. Miss Polaris gave me 15 dollars. "
"How many money do I have now."
),
0,
)
output = openai_model_text.chat(message)
Expand Down

0 comments on commit b9ddf11

Please sign in to comment.