Skip to content

Commit 8f76587

Browse files
anushkumarvneubig
andauthored
docs: updated docstrings using ruff's autofix feature (OpenHands#2923)
* Updated documentation using ruff's autofix feature * Updated pyproject.toml to include docstring validations * Updated documentation using ruff's autofix feature * Updated pyproject.toml to include docstring validations * Updated docstrings using ruff's autfix feature * Deleted opendevin/runtime/utils/soource.py, Keeping in sync with main --------- Co-authored-by: Graham Neubig <[email protected]>
1 parent 149dac8 commit 8f76587

64 files changed

Lines changed: 224 additions & 472 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agenthub/browsing_agent/browsing_agent.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def __init__(
9999
self,
100100
llm: LLM,
101101
) -> None:
102-
"""
103-
Initializes a new instance of the BrowsingAgent class.
102+
"""Initializes a new instance of the BrowsingAgent class.
104103
105104
Parameters:
106105
- llm (LLM): The llm to be used by this agent
@@ -120,16 +119,13 @@ def __init__(
120119
self.reset()
121120

122121
def reset(self) -> None:
123-
"""
124-
Resets the Browsing Agent.
125-
"""
122+
"""Resets the Browsing Agent."""
126123
super().reset()
127124
self.cost_accumulator = 0
128125
self.error_accumulator = 0
129126

130127
def step(self, state: State) -> Action:
131-
"""
132-
Performs one step using the Browsing Agent.
128+
"""Performs one step using the Browsing Agent.
133129
This includes gathering information on previous steps and prompting the model to make a browsing command to execute.
134130
135131
Parameters:

agenthub/browsing_agent/prompt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class PromptElement:
7575
Prompt elements are used to build the prompt. Use flags to control which
7676
prompt elements are visible. We use class attributes as a convenient way
7777
to implement static prompts, but feel free to override them with instance
78-
attributes or @property decorator."""
78+
attributes or @property decorator.
79+
"""
7980

8081
_prompt = ''
8182
_abstract_ex = ''
@@ -200,11 +201,10 @@ def fit_tokens(
200201
model_name : str, optional
201202
The name of the model used when tokenizing.
202203
203-
Returns
204+
Returns:
204205
-------
205206
str : the prompt after shrinking.
206207
"""
207-
208208
if max_prompt_chars is None:
209209
return shrinkable.prompt
210210

@@ -579,8 +579,8 @@ def _parse_answer(self, text_answer):
579579
def diff(previous, new):
580580
"""Return a string showing the difference between original and new.
581581
582-
If the difference is above diff_threshold, return the diff string."""
583-
582+
If the difference is above diff_threshold, return the diff string.
583+
"""
584584
if previous == new:
585585
return 'Identical', []
586586

agenthub/browsing_agent/response_parser.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def parse_action(self, action_str: str) -> Action:
3737

3838

3939
class BrowsingActionParserMessage(ActionParser):
40-
"""
41-
Parser action:
42-
- BrowseInteractiveAction(browser_actions) - unexpected response format, message back to user
40+
"""Parser action:
41+
- BrowseInteractiveAction(browser_actions) - unexpected response format, message back to user
4342
"""
4443

4544
def __init__(
@@ -60,9 +59,8 @@ def parse(self, action_str: str) -> Action:
6059

6160

6261
class BrowsingActionParserBrowseInteractive(ActionParser):
63-
"""
64-
Parser action:
65-
- BrowseInteractiveAction(browser_actions) - handle send message to user function call in BrowserGym
62+
"""Parser action:
63+
- BrowseInteractiveAction(browser_actions) - handle send message to user function call in BrowserGym
6664
"""
6765

6866
def __init__(

agenthub/browsing_agent/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
def yaml_parser(message):
99
"""Parse a yaml message for the retry function."""
10-
1110
# saves gpt-3.5 from some yaml parsing errors
1211
message = re.sub(r':\s*\n(?=\S|\n)', ': ', message)
1312

@@ -47,7 +46,6 @@ def _compress_chunks(text, identifier, skip_list, split_regex='\n\n+'):
4746

4847
def compress_string(text):
4948
"""Compress a string by replacing redundant paragraphs and lines with identifiers."""
50-
5149
# Perform paragraph-level compression
5250
def_dict, compressed_text = _compress_chunks(
5351
text, identifier='§', skip_list=[], split_regex='\n\n+'
@@ -79,12 +77,12 @@ def extract_html_tags(text, keys):
7977
keys : list of str
8078
The HTML tags to extract the content from.
8179
82-
Returns
80+
Returns:
8381
-------
8482
dict
8583
A dictionary mapping each key to a list of subset in `text` that match the key.
8684
87-
Notes
85+
Notes:
8886
-----
8987
All text and keys will be converted to lowercase before matching.
9088
@@ -126,7 +124,7 @@ def parse_html_tags(text, keys=(), optional_keys=(), merge_multiple=False):
126124
optional_keys : list of str
127125
The HTML tags to extract the content from, but are optional.
128126
129-
Returns
127+
Returns:
130128
-------
131129
dict
132130
A dictionary mapping each key to subset of `text` that match the key.

agenthub/codeact_agent/action_parser.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212

1313

1414
class CodeActResponseParser(ResponseParser):
15-
"""
16-
Parser action:
17-
- CmdRunAction(command) - bash command to run
18-
- IPythonRunCellAction(code) - IPython code to run
19-
- AgentDelegateAction(agent, inputs) - delegate action for (sub)task
20-
- MessageAction(content) - Message action to run (e.g. ask for clarification)
21-
- AgentFinishAction() - end the interaction
15+
"""Parser action:
16+
- CmdRunAction(command) - bash command to run
17+
- IPythonRunCellAction(code) - IPython code to run
18+
- AgentDelegateAction(agent, inputs) - delegate action for (sub)task
19+
- MessageAction(content) - Message action to run (e.g. ask for clarification)
20+
- AgentFinishAction() - end the interaction
2221
"""
2322

2423
def __init__(self):
@@ -53,9 +52,8 @@ def parse_action(self, action_str: str) -> Action:
5352

5453

5554
class CodeActActionParserFinish(ActionParser):
56-
"""
57-
Parser action:
58-
- AgentFinishAction() - end the interaction
55+
"""Parser action:
56+
- AgentFinishAction() - end the interaction
5957
"""
6058

6159
def __init__(
@@ -76,10 +74,9 @@ def parse(self, action_str: str) -> Action:
7674

7775

7876
class CodeActActionParserCmdRun(ActionParser):
79-
"""
80-
Parser action:
81-
- CmdRunAction(command) - bash command to run
82-
- AgentFinishAction() - end the interaction
77+
"""Parser action:
78+
- CmdRunAction(command) - bash command to run
79+
- AgentFinishAction() - end the interaction
8380
"""
8481

8582
def __init__(
@@ -106,9 +103,8 @@ def parse(self, action_str: str) -> Action:
106103

107104

108105
class CodeActActionParserIPythonRunCell(ActionParser):
109-
"""
110-
Parser action:
111-
- IPythonRunCellAction(code) - IPython code to run
106+
"""Parser action:
107+
- IPythonRunCellAction(code) - IPython code to run
112108
"""
113109

114110
def __init__(
@@ -137,9 +133,8 @@ def parse(self, action_str: str) -> Action:
137133

138134

139135
class CodeActActionParserAgentDelegate(ActionParser):
140-
"""
141-
Parser action:
142-
- AgentDelegateAction(agent, inputs) - delegate action for (sub)task
136+
"""Parser action:
137+
- AgentDelegateAction(agent, inputs) - delegate action for (sub)task
143138
"""
144139

145140
def __init__(
@@ -164,9 +159,8 @@ def parse(self, action_str: str) -> Action:
164159

165160

166161
class CodeActActionParserMessage(ActionParser):
167-
"""
168-
Parser action:
169-
- MessageAction(content) - Message action to run (e.g. ask for clarification)
162+
"""Parser action:
163+
- MessageAction(content) - Message action to run (e.g. ask for clarification)
170164
"""
171165

172166
def __init__(

agenthub/codeact_agent/codeact_agent.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ def __init__(
158158
self,
159159
llm: LLM,
160160
) -> None:
161-
"""
162-
Initializes a new instance of the CodeActAgent class.
161+
"""Initializes a new instance of the CodeActAgent class.
163162
164163
Parameters:
165164
- llm (LLM): The llm to be used by this agent
@@ -168,14 +167,11 @@ def __init__(
168167
self.reset()
169168

170169
def reset(self) -> None:
171-
"""
172-
Resets the CodeAct Agent.
173-
"""
170+
"""Resets the CodeAct Agent."""
174171
super().reset()
175172

176173
def step(self, state: State) -> Action:
177-
"""
178-
Performs one step using the CodeAct Agent.
174+
"""Performs one step using the CodeAct Agent.
179175
This includes gathering info on previous steps and prompting the model to make a command to execute.
180176
181177
Parameters:
@@ -188,7 +184,6 @@ def step(self, state: State) -> Action:
188184
- MessageAction(content) - Message action to run (e.g. ask for clarification)
189185
- AgentFinishAction() - end the interaction
190186
"""
191-
192187
# if we're done, go back
193188
latest_user_message = state.history.get_last_user_message()
194189
if latest_user_message and latest_user_message.strip() == '/exit':

agenthub/codeact_swe_agent/action_parser.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212

1313
class CodeActSWEActionParserFinish(ActionParser):
14-
"""
15-
Parser action:
16-
- AgentFinishAction() - end the interaction
14+
"""Parser action:
15+
- AgentFinishAction() - end the interaction
1716
"""
1817

1918
def __init__(
@@ -34,10 +33,9 @@ def parse(self, action_str: str) -> Action:
3433

3534

3635
class CodeActSWEActionParserCmdRun(ActionParser):
37-
"""
38-
Parser action:
39-
- CmdRunAction(command) - bash command to run
40-
- AgentFinishAction() - end the interaction
36+
"""Parser action:
37+
- CmdRunAction(command) - bash command to run
38+
- AgentFinishAction() - end the interaction
4139
"""
4240

4341
def __init__(
@@ -64,9 +62,8 @@ def parse(self, action_str: str) -> Action:
6462

6563

6664
class CodeActSWEActionParserIPythonRunCell(ActionParser):
67-
"""
68-
Parser action:
69-
- IPythonRunCellAction(code) - IPython code to run
65+
"""Parser action:
66+
- IPythonRunCellAction(code) - IPython code to run
7067
"""
7168

7269
def __init__(
@@ -95,9 +92,8 @@ def parse(self, action_str: str) -> Action:
9592

9693

9794
class CodeActSWEActionParserMessage(ActionParser):
98-
"""
99-
Parser action:
100-
- MessageAction(content) - Message action to run (e.g. ask for clarification)
95+
"""Parser action:
96+
- MessageAction(content) - Message action to run (e.g. ask for clarification)
10197
"""
10298

10399
def __init__(

agenthub/codeact_swe_agent/codeact_swe_agent.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def __init__(
113113
self,
114114
llm: LLM,
115115
) -> None:
116-
"""
117-
Initializes a new instance of the CodeActAgent class.
116+
"""Initializes a new instance of the CodeActAgent class.
118117
119118
Parameters:
120119
- llm (LLM): The llm to be used by this agent
@@ -123,14 +122,11 @@ def __init__(
123122
self.reset()
124123

125124
def reset(self) -> None:
126-
"""
127-
Resets the CodeAct Agent.
128-
"""
125+
"""Resets the CodeAct Agent."""
129126
super().reset()
130127

131128
def step(self, state: State) -> Action:
132-
"""
133-
Performs one step using the CodeAct Agent.
129+
"""Performs one step using the CodeAct Agent.
134130
This includes gathering info on previous steps and prompting the model to make a command to execute.
135131
136132
Parameters:
@@ -142,7 +138,6 @@ def step(self, state: State) -> Action:
142138
- MessageAction(content) - Message action to run (e.g. ask for clarification)
143139
- AgentFinishAction() - end the interaction
144140
"""
145-
146141
# if we're done, go back
147142
latest_user_message = state.history.get_last_user_message()
148143
if latest_user_message and latest_user_message.strip() == '/exit':

agenthub/codeact_swe_agent/response_parser.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010

1111
class CodeActSWEResponseParser(ResponseParser):
12-
"""
13-
Parser action:
14-
- CmdRunAction(command) - bash command to run
15-
- IPythonRunCellAction(code) - IPython code to run
16-
- MessageAction(content) - Message action to run (e.g. ask for clarification)
17-
- AgentFinishAction() - end the interaction
12+
"""Parser action:
13+
- CmdRunAction(command) - bash command to run
14+
- IPythonRunCellAction(code) - IPython code to run
15+
- MessageAction(content) - Message action to run (e.g. ask for clarification)
16+
- AgentFinishAction() - end the interaction
1817
"""
1918

2019
def __init__(self):

agenthub/delegator_agent/agent.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ class DelegatorAgent(Agent):
1414
current_delegate: str = ''
1515

1616
def __init__(self, llm: LLM):
17-
"""
18-
Initialize the Delegator Agent with an LLM
17+
"""Initialize the Delegator Agent with an LLM
1918
2019
Parameters:
2120
- llm (LLM): The llm to be used by this agent
2221
"""
2322
super().__init__(llm)
2423

2524
def step(self, state: State) -> Action:
26-
"""
27-
Checks to see if current step is completed, returns AgentFinishAction if True.
25+
"""Checks to see if current step is completed, returns AgentFinishAction if True.
2826
Otherwise, delegates the task to the next agent in the pipeline.
2927
3028
Parameters:

0 commit comments

Comments
 (0)