-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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("/", "_") | ||
| except AttributeError: | ||
| pass | ||
|
Comment on lines
+19
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent AttributeError Suppression
Tell me moreWhat is the issue?Silent failure with empty except block that masks AttributeError without any logging or information preservation Why this mattersWhen 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 PreviewAdd 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💬 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 | ||
TLSDC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
TLSDC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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, | ||
| ): | ||
TLSDC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.action_set = action_set_args.make_action_set() | ||
TLSDC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.
Sorry, something went wrong. |
||
| obs["screenshot"], extra_properties=obs["extra_element_properties"] | ||
| ) | ||
| return obs | ||
|
|
||
| def get_action(self, obs): | ||
|
|
||
| # print(obs["pruned_html"]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant Commented Code
Tell me moreWhat is the issue?Commented-out code that adds noise without value Why this mattersCommented code creates uncertainty about whether it should be preserved and makes the code harder to maintain. Suggested change ∙ Feature PreviewRemove the commented line entirely Provide feedback to improve future suggestions💬 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() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overcomplicated String Assignment
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
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.