Skip to content

Commit b9ddf11

Browse files
authored
style: Pass ruff check (#38)
1 parent 3b36289 commit b9ddf11

File tree

7 files changed

+58
-43
lines changed

7 files changed

+58
-43
lines changed

crab/agents/backend_models/gemini_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def call_api(self, request_messages: list):
117117
)
118118
except ResourceExhausted:
119119
print(
120-
"ResourceExhausted: 429 Resource has been exhausted. Please waiting..."
120+
"ResourceExhausted: 429 Resource has been exhausted.",
121+
" Please waiting...",
121122
)
122123
sleep(10)
123124
else:

crab/agents/policies/multi_agent_by_env.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,38 @@
2222

2323

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

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

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

5858
def __init__(
5959
self,
@@ -119,7 +119,10 @@ def chat(
119119
main_prompt.extend(observation[env])
120120
main_prompt.append(
121121
(
122-
f"Your target: {self.task_description}\nTell me the next step in each environment.",
122+
(
123+
f"Your target: {self.task_description}\n"
124+
"Tell me the next step in each environment."
125+
),
123126
MessageType.TEXT,
124127
)
125128
)

crab/agents/policies/multi_agent_by_func.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323

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

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

4141
def __init__(

crab/core/experiment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def execute_action(self, response: list[ActionOutput]) -> bool:
141141
return True
142142
print(
143143
"\033[92m"
144-
f'Action "{action.name}" in env "{action.env}" success. current evaluation results: {self.metrics}\n'
144+
f'Action "{action.name}" in env "{action.env}" success. '
145+
f"Current evaluation results: {self.metrics}\n"
145146
"\033[0m"
146147
)
147148
self.write_current_log_row(action)
@@ -193,7 +194,8 @@ def start_benchmark(self):
193194
env_descriptions=env_description,
194195
)
195196
print(
196-
f'Start benchmark "{self.benchmark.name}", task id "{self.task.id}": "{self.task.description}"'
197+
f'Start benchmark "{self.benchmark.name}", task id "{self.task.id}": '
198+
f'"{self.task.description}"'
197199
)
198200
self.init_log_dir()
199201
self.step_cnt = 0

test/agents/backend_models/test_claude_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def test_text_chat(claude_model_text):
6464
def test_action_chat(claude_model_text):
6565
claude_model_text.reset("You are a helpful assistant.", [add])
6666
message = (
67-
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
67+
(
68+
"I had 10 dollars. Miss Polaris gave me 15 dollars."
69+
" How many money do I have now."
70+
),
6871
0,
6972
)
7073
output = claude_model_text.chat(message)

test/agents/backend_models/test_gemini_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def test_text_chat(gemini_model_text):
6464
def test_action_chat(gemini_model_text):
6565
gemini_model_text.reset("You are a helpful assistant.", [add])
6666
message = (
67-
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
67+
(
68+
"I had 10 dollars. Miss Polaris gave me 15 dollars. "
69+
"How many money do I have now."
70+
),
6871
0,
6972
)
7073
output = gemini_model_text.chat(message)

test/agents/backend_models/test_openai_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ def test_text_chat(mock_create, openai_model_text):
145145
def test_action_chat(mock_create, openai_model_text):
146146
openai_model_text.reset("You are a helpful assistant.", [add])
147147
message = (
148-
"I had 10 dollars. Miss Polaris gave me 15 dollars. How many money do I have now.",
148+
(
149+
"I had 10 dollars. Miss Polaris gave me 15 dollars. "
150+
"How many money do I have now."
151+
),
149152
0,
150153
)
151154
output = openai_model_text.chat(message)

0 commit comments

Comments
 (0)