Skip to content

Adding a simple debug agent to manually test actions #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TLSDC
Copy link
Collaborator

@TLSDC TLSDC commented Apr 22, 2025

Description by Korbit AI

What change is being made?

Add a new debug agent in debug_agent.py for manual testing of actions within the browser gym environment.

Why are these changes being made?

This change introduces a tool to facilitate the manual testing of actions, providing a way to interactively verify and debug the system's behavior using the DebugAgent, which outputs a text representation of the observation and takes input for actions. This supports developers in quickly testing environments without relying solely on automated frameworks.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Readability Redundant Commented Code ▹ view
Security Unsanitized User Input in Action Handling ▹ view
Readability Overcomplicated String Assignment ▹ view
Performance Redundant Observation Processing ▹ view
Error Handling Silent AttributeError Suppression ▹ view
Files scanned
File Path Reviewed
src/agentlab/agents/debug_agent.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X


def get_action(self, obs):

# print(obs["pruned_html"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant Commented Code category Readability

Tell me more
What is the issue?

Commented-out code that adds noise without value

Why this matters

Commented code creates uncertainty about whether it should be preserved and makes the code harder to maintain.

Suggested change ∙ Feature Preview

Remove the commented line entirely

Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.


# print(obs["pruned_html"])
print("\n")
action = input(obs["axtree_txt"] + "\n")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsanitized User Input in Action Handling category Security

Tell me more
What is the issue?

Raw input from user is accepted without any validation or sanitization in the get_action method

Why this matters

Malicious input could be injected that manipulates the action handling or triggers unexpected behavior. The input is directly used as an action without bounds checking or sanitization.

Suggested change ∙ Feature Preview
def get_action(self, obs):
    raw_action = input(obs["axtree_txt"] + "\n")
    # Validate input matches expected action format
    if raw_action not in self.action_set.valid_actions:
        raise ValueError("Invalid action provided")
    action = raw_action
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.


def __post_init__(self):
try: # some attributes might be temporarily args.CrossProd for hyperparameter generation
self.agent_name = f"debug".replace("/", "_")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overcomplicated String Assignment category Readability

Tell me more
What is the issue?

Unnecessary f-string and string manipulation for a static string

Why this matters

The code is overly complex for a simple string assignment. The f-string serves no purpose as there's no interpolation, and replace() is called on a string that can't contain '/'.

Suggested change ∙ Feature Preview
self.agent_name = "debug"
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Comment on lines +41 to +66
def obs_preprocessor(self, obs):
obs = deepcopy(obs)
obs["dom_txt"] = flatten_dom_to_str(
obs["dom_object"],
extra_properties=obs["extra_element_properties"],
with_visible=True,
with_clickable=True,
with_center_coords=True,
with_bounding_box_coords=True,
filter_visible_only=False,
filter_with_bid_only=False,
filter_som_only=False,
)
obs["axtree_txt"] = flatten_axtree_to_str(
obs["axtree_object"],
extra_properties=obs["extra_element_properties"],
with_visible=True,
with_clickable=True,
with_center_coords=True,
with_bounding_box_coords=True,
filter_visible_only=False,
filter_with_bid_only=False,
filter_som_only=False,
)
obs["pruned_html"] = prune_html(obs["dom_txt"])
obs["screenshot_som"] = overlay_som(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant Observation Processing category Performance

Tell me more
What is the issue?

The obs_preprocessor performs multiple expensive operations on every observation, including a deep copy of the entire observation and multiple string conversions, without any caching.

Why this matters

For debugging purposes, this creates unnecessary overhead as these transformations are recomputed even when the DOM hasn't changed, potentially slowing down the debugging process especially with rapid interactions.

Suggested change ∙ Feature Preview

Implement caching of processed observations based on a hash of the input DOM/axtree to avoid reprocessing identical states. Only process what's needed for the current debugging context. Example:

def obs_preprocessor(self, obs):
    # Only process what's actually being used in get_action
    obs = obs.copy()  # shallow copy is sufficient
    obs['axtree_txt'] = flatten_axtree_to_str(
        obs['axtree_object'],
        extra_properties=obs['extra_element_properties'],
        with_visible=True,
        with_clickable=True,
        with_center_coords=True,
        with_bounding_box_coords=True,
        filter_visible_only=False,
        filter_with_bid_only=False,
        filter_som_only=False,
    )
    return obs
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Comment on lines +19 to +22
try: # some attributes might be temporarily args.CrossProd for hyperparameter generation
self.agent_name = f"debug".replace("/", "_")
except AttributeError:
pass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent AttributeError Suppression category Error Handling

Tell me more
What is the issue?

Silent failure with empty except block that masks AttributeError without any logging or information preservation

Why this matters

When an AttributeError occurs, silently ignoring it makes debugging difficult as there's no way to know what caused the error or if it occurred at all

Suggested change ∙ Feature Preview

Add logging to capture the error information:

import logging

try:
    self.agent_name = f"debug".replace("/", "_")
except AttributeError as e:
    logging.debug(f"Skipping agent_name assignment during hyperparameter generation: {e}")
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant