Skip to content

Commit 0b3943f

Browse files
Add docstrings for function arguments and return types in agent_utils, tool_use_agent, loop, study, and llm_utils modules
1 parent c0bf32f commit 0b3943f

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

src/agentlab/agents/agent_utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ def draw_mouse_pointer(image: Image.Image, x: int, y: int) -> Image.Image:
9696
"""
9797
Draws a semi-transparent mouse pointer at (x, y) on the image.
9898
Returns a new image with the pointer drawn.
99+
100+
Args:
101+
image: The image to draw the mouse pointer on.
102+
x: The x coordinate for the mouse pointer.
103+
y: The y coordinate for the mouse pointer.
104+
105+
Returns:
106+
A new image with the mouse pointer drawn.
99107
"""
100108
pointer_size = 20 # Length of the pointer
101109
overlay = image.convert("RGBA").copy()
@@ -134,6 +142,14 @@ def draw_click_indicator(image: Image.Image, x: int, y: int) -> Image.Image:
134142
"""
135143
Draws a click indicator (+ shape with disconnected lines) at (x, y) on the image.
136144
Returns a new image with the click indicator drawn.
145+
146+
Args:
147+
image: The image to draw the click indicator on.
148+
x: The x coordinate for the click indicator.
149+
y: The y coordinate for the click indicator.
150+
151+
Returns:
152+
A new image with the click indicator drawn.
137153
"""
138154
line_length = 10 # Length of each line segment
139155
gap = 4 # Gap from center point
@@ -188,7 +204,13 @@ def zoom_webpage(page: Page, zoom_factor: float = 1.5):
188204
189205
Args:
190206
page: The Playwright Page object.
191-
zoom_factor: The zoom factor to apply (default is 1.0, which means no zoom).
207+
zoom_factor: The zoom factor to apply (default is 1.5).
208+
209+
Returns:
210+
Page: The modified Playwright Page object.
211+
212+
Raises:
213+
ValueError: If zoom_factor is less than or equal to 0.
192214
"""
193215

194216
if zoom_factor <= 0:

src/agentlab/agents/tool_use_agent/tool_use_agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ def _init(self):
4141
def make(self) -> "Block":
4242
"""Returns a copy so the init can start adding some stuff to `self` without changing the
4343
original datatclass that should only contain a config.
44-
The aim is avoid having 2 calss definition for each block, e.g. Block and BlockArgs."""
44+
The aim is avoid having 2 calss definition for each block, e.g. Block and BlockArgs.
45+
46+
Returns:
47+
Block: A copy of the current block instance with initialization applied.
48+
"""
4549
block = self.__class__(**asdict(self))
4650
block._init()
4751
return block

src/agentlab/experiments/loop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def make_env(
5555
action_mapping: overrides the action mapping of the environment.
5656
exp_dir: will set some environment parameters (e.g., record_video_dir) with respect to the directory where the experiment is running.
5757
exp_task_kwargs: use with caution! Will override task parameters to experiment-specific values. Useful to set different server configs for different experiments, or output file paths within the experiment's folder (e.g., assistantbench).
58+
use_raw_page_output: if True, the environment will also return raw page output in the observation.
5859
5960
Returns:
6061
env: the gym environment.

src/agentlab/experiments/study.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ def _convert_env_args(env_args_list):
729729
"""Return a list where every element is the *new* EnvArgs.
730730
731731
For backward compatibility, we need to convert the old EnvArgs to the new one.
732+
733+
Args:
734+
env_args_list (list): list of EnvArgs objects to convert
735+
736+
Returns:
737+
list: list of converted EnvArgs objects
738+
739+
Raises:
740+
TypeError: If an element in env_args_list is not of expected type.
732741
"""
733742
from bgym import EnvArgs as BGymEnvArgs
734743

src/agentlab/llm/llm_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ def generic_call_api_with_retries(
107107
Makes an API call with retries for transient failures, rate limiting,
108108
and responses deemed invalid by a custom validation function.
109109
(Refactored for improved readability with helper functions)
110+
111+
Args:
112+
client_function: The API client function to call.
113+
api_params: Parameters to pass to the client function.
114+
is_response_valid_fn: Function to validate if the response is valid.
115+
rate_limit_exceptions: Tuple of exception types for rate limiting.
116+
api_error_exceptions: Tuple of exception types for API errors.
117+
get_status_code_fn: Optional function to extract status code from exceptions.
118+
max_retries: Maximum number of retry attempts.
119+
initial_retry_delay_seconds: Initial delay between retries in seconds.
120+
max_retry_delay_seconds: Maximum delay between retries in seconds.
121+
122+
Returns:
123+
The API response if successful.
124+
125+
Raises:
126+
Exception: For unexpected errors that are immediately re-raised.
127+
RuntimeError: If API call fails after maximum retries.
110128
"""
111129

112130
def _calculate_delay(
@@ -231,6 +249,14 @@ def call_openai_api_with_retries(client_function, api_params, max_retries=10):
231249
Makes an OpenAI API call with retries for transient failures,
232250
rate limiting, and invalid or error-containing responses.
233251
(This is now a wrapper around generic_call_api_with_retries for OpenAI)
252+
253+
Args:
254+
client_function: The OpenAI API client function to call.
255+
api_params: Parameters to pass to the client function.
256+
max_retries: Maximum number of retry attempts.
257+
258+
Returns:
259+
The OpenAI API response if successful.
234260
"""
235261

236262
def is_openai_response_valid(response):
@@ -266,6 +292,14 @@ def call_anthropic_api_with_retries(client_function, api_params, max_retries=10)
266292
Makes an Anthropic API call with retries for transient failures,
267293
rate limiting, and invalid responses.
268294
(This is a wrapper around generic_call_api_with_retries for Anthropic)
295+
296+
Args:
297+
client_function: The Anthropic API client function to call.
298+
api_params: Parameters to pass to the client function.
299+
max_retries: Maximum number of retry attempts.
300+
301+
Returns:
302+
The Anthropic API response if successful.
269303
"""
270304

271305
def is_anthropic_response_valid(response):

0 commit comments

Comments
 (0)