Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions src/agentlab/agents/debug_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from copy import deepcopy
from dataclasses import asdict, dataclass
from functools import partial

import bgym
from browsergym.experiments.agent import Agent, AgentInfo
from browsergym.utils.obs import flatten_axtree_to_str, flatten_dom_to_str, overlay_som, prune_html

from agentlab.agents.agent_args import AgentArgs
from agentlab.llm.chat_api import BaseModelArgs
from agentlab.llm.llm_utils import ParseError, image_to_png_base64_url, parse_html_tags_raise, retry
from agentlab.llm.tracking import cost_tracker_decorator


@dataclass
class DebugAgentArgs(AgentArgs):

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.

except AttributeError:
pass
Comment on lines +19 to +22
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.

self.action_set_args = bgym.DEFAULT_BENCHMARKS[
"miniwob_tiny_test"
]().high_level_action_set_args
self.use_html = False

def set_benchmark(self, benchmark: bgym.Benchmark, demo_mode):
if benchmark.name.startswith("miniwob"):
self.use_html = True
self.action_set_args = benchmark.high_level_action_set_args

def make_agent(self):
return DebugAgent(self.action_set_args, use_html=self.use_html)


class DebugAgent(Agent):
def __init__(
self,
action_set_args,
use_html=False,
):
self.action_set = action_set_args.make_action_set()
self.use_html = use_html

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(
Comment on lines +46 to +71

This comment was marked as resolved.

obs["screenshot"], extra_properties=obs["extra_element_properties"]
)
return obs

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("\n")
observation = obs["pruned_html"] if self.use_html else obs["axtree_txt"]
action = input(observation + "\n")
agent_info = AgentInfo(
think="nope",
chat_messages=[],
stats={},
)
return action, agent_info


DEBUG_AGENT = DebugAgentArgs()