Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 4 additions & 8 deletions src/agentlab/agents/generic_agent/generic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,14 @@ def _check_flag_constancy(self):
flags = self.flags
if flags.obs.use_som:
if not flags.obs.use_screenshot:
warn(
"""
Warning: use_som=True requires use_screenshot=True. Disabling use_som."""
)
warn("""
Warning: use_som=True requires use_screenshot=True. Disabling use_som.""")
flags.obs.use_som = False
if flags.obs.use_screenshot:
if not self.chat_model_args.vision_support:
warn(
"""
warn("""
Warning: use_screenshot is set to True, but the chat model \
does not support vision. Disabling use_screenshot."""
)
does not support vision. Disabling use_screenshot.""")
flags.obs.use_screenshot = False
return flags

Expand Down
18 changes: 6 additions & 12 deletions src/agentlab/agents/generic_agent/generic_agent_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def time_for_caution():
@property
def _prompt(self) -> HumanMessage:
prompt = HumanMessage(self.instructions.prompt)
prompt.add_text(
f"""\
prompt.add_text(f"""\
{self.obs.prompt}\
{self.history.prompt}\
{self.action_prompt.prompt}\
Expand All @@ -114,12 +113,10 @@ def _prompt(self) -> HumanMessage:
{self.plan.prompt}\
{self.memory.prompt}\
{self.criticise.prompt}\
"""
)
""")

if self.flags.use_abstract_example:
prompt.add_text(
f"""
prompt.add_text(f"""
# Abstract Example

Here is an abstract version of the answer with description of the content of
Expand All @@ -130,12 +127,10 @@ def _prompt(self) -> HumanMessage:
{self.memory.abstract_ex}\
{self.criticise.abstract_ex}\
{self.action_prompt.abstract_ex}\
"""
)
""")

if self.flags.use_concrete_example:
prompt.add_text(
f"""
prompt.add_text(f"""
# Concrete Example

Here is a concrete example of how to format your answer.
Expand All @@ -145,8 +140,7 @@ def _prompt(self) -> HumanMessage:
{self.memory.concrete_ex}\
{self.criticise.concrete_ex}\
{self.action_prompt.concrete_ex}\
"""
)
""")
return self.obs.add_screenshot(prompt)

def shrink(self):
Expand Down
14 changes: 4 additions & 10 deletions src/agentlab/agents/most_basic_agent/most_basic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def __init__(
@cost_tracker_decorator
def get_action(self, obs: Any) -> tuple[str, dict]:
messages = Discussion(SystemMessage("You are a web assistant."))
messages.append(
HumanMessage(
f"""
messages.append(HumanMessage(f"""
You are helping a user to accomplish the following goal on a website:

{obs["goal"]}
Expand All @@ -85,15 +83,11 @@ def get_action(self, obs: Any) -> tuple[str, dict]:

Please provide a single action at a time and wait for the next observation. Provide only a single action per step.
Focus on the bid that are given in the html, and use them to perform the actions.
"""
)
)
"""))
if self.use_chain_of_thought:
messages.add_text(
f"""
messages.add_text(f"""
Provide a chain of thoughts reasoning to decompose the task into smaller steps. And execute only the next step.
"""
)
""")

def parser(response: str) -> tuple[dict, bool, str]:
blocks = extract_code_blocks(response)
Expand Down
24 changes: 8 additions & 16 deletions src/agentlab/agents/visual_agent/visual_agent_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ def __init__(self, actions, thoughts) -> None:
super().__init__()
prompt_elements = []
for i, (action, thought) in enumerate(zip(actions, thoughts)):
prompt_elements.append(
f"""
prompt_elements.append(f"""
## Step {i}
### Thoughts:
{thought}
### Action:
{action}
"""
)
""")
self._prompt = "\n".join(prompt_elements) + "\n"


Expand Down Expand Up @@ -143,39 +141,33 @@ def __init__(
@property
def _prompt(self) -> HumanMessage:
prompt = HumanMessage(self.instructions.prompt)
prompt.add_text(
f"""\
prompt.add_text(f"""\
{self.obs.prompt}\
{self.history.prompt}\
{self.action_prompt.prompt}\
{self.think.prompt}\
"""
)
""")

if self.flags.use_abstract_example:
prompt.add_text(
f"""
prompt.add_text(f"""
# Abstract Example

Here is an abstract version of the answer with description of the content of
each tag. Make sure you follow this structure, but replace the content with your
answer:
{self.think.abstract_ex}\
{self.action_prompt.abstract_ex}\
"""
)
""")

if self.flags.use_concrete_example:
prompt.add_text(
f"""
prompt.add_text(f"""
# Concrete Example

Here is a concrete example of how to format your answer.
Make sure to follow the template with proper tags:
{self.think.concrete_ex}\
{self.action_prompt.concrete_ex}\
"""
)
""")
return self.obs.add_screenshot(prompt)

def _parse_answer(self, text_answer):
Expand Down
76 changes: 25 additions & 51 deletions src/agentlab/analyze/agent_xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run_gradio(results_dir: Path):
global info
info.results_dir = results_dir

with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
with gr.Blocks() as demo:
agent_id = gr.State(value=None)
episode_id = gr.State(value=EpisodeId())
agent_task_id = gr.State(value=None)
Expand All @@ -186,8 +186,7 @@ def run_gradio(results_dir: Path):
hidden_key_input = gr.Textbox(visible=False, elem_id="key_capture")

with gr.Accordion("Help", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
# Agent X-Ray

1. **Select your experiment directory**. You may refresh the list of directories by
Expand All @@ -208,8 +207,7 @@ def run_gradio(results_dir: Path):
information on the corresponding step.

4. **Select a tab**: You can select different visualization by clicking on the tabs.
"""
)
""")
with gr.Row():
exp_dir_choice = gr.Dropdown(
choices=get_directory_contents(results_dir),
Expand All @@ -225,27 +223,23 @@ def run_gradio(results_dir: Path):
with gr.Tabs():
with gr.Tab("Select Agent"):
with gr.Accordion("Agent Selector (click for help)", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
Click on a row to select an agent. It will trigger the update of other
fields.

The update mechanism is somewhat flacky, please help figure out why (or is it just gradio?).
"""
)
""")
agent_table = gr.DataFrame(max_height=500, show_label=False, interactive=False)
with gr.Tab("Select Task and Seed", id="Select Task"):
with gr.Row():
with gr.Column(scale=4):
with gr.Row(): # combining the title (help) and the refresh button
with gr.Accordion("Task Selector (click for help)", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
Click on a row to select a task. It will trigger the update of other fields.

The update mechanism is somewhat flacky, please help figure out why (or is it just gradio?).
"""
)
""")
refresh_results_button = gr.Button("↺", scale=0, size="sm")

task_table = gr.DataFrame(
Expand All @@ -257,13 +251,11 @@ def run_gradio(results_dir: Path):

with gr.Column(scale=2):
with gr.Accordion("Seed Selector (click for help)", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
Click on a row to select a seed. It will trigger the update of other fields.

The update mechanism is somewhat flacky, please help figure out why (or is it just gradio?).
"""
)
""")

seed_table = gr.DataFrame(
max_height=500,
Expand All @@ -276,50 +268,42 @@ def run_gradio(results_dir: Path):
with gr.Row():
with gr.Column(scale=2):
with gr.Accordion("Constants", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
Constants are the parameters that are the same for **all** episodes of
**all** agents. They are displayed as a table with the name and value of the
constant."""
)
constant.""")
constants = gr.DataFrame(
max_height=500, show_label=False, interactive=False
)
with gr.Column(scale=2):
with gr.Accordion("Variables", open=False):
gr.Markdown(
"""\
gr.Markdown("""\
Variables are the parameters that can change between episodes of an agent.
They are displayed as a table with the name, value and count of unique
values. A maximum of 3 different values are displayed."""
)
values. A maximum of 3 different values are displayed.""")
variables = gr.DataFrame(
max_height=500, show_label=False, interactive=False
)
with gr.Tab("Global Stats"):
global_stats = gr.DataFrame(max_height=500, show_label=False, interactive=False)

with gr.Tab("Error Report"):
error_report = gr.Markdown(elem_classes="error-report", show_copy_button=True)
error_report = gr.Markdown(elem_classes="error-report", buttons=["copy"])
with gr.Row():
episode_info = gr.Markdown(label="Episode Info", elem_classes="my-markdown")
action_info = gr.Markdown(label="Action Info", elem_classes="my-markdown")
state_error = gr.Markdown(label="Next Step Error", elem_classes="my-markdown")

profiling_gr = gr.Image(
label="Profiling", show_label=False, interactive=False, show_download_button=False
)
profiling_gr = gr.Image(label="Profiling", show_label=False, interactive=False, buttons=[])

gr.HTML(
"""
gr.HTML("""
<style>
.code-container {
height: 700px; /* Set the desired height */
overflow: auto; /* Enable scrolling */
}
</style>
"""
)
""")
with gr.Tabs() as tabs:
code_args = dict(interactive=False, elem_classes=["code-container"], show_label=False)
with gr.Tab("Screenshot") as tab_screenshot:
Expand All @@ -332,22 +316,16 @@ def run_gradio(results_dir: Path):
interactive=True,
scale=0,
)
screenshot = gr.Image(
show_label=False, interactive=False, show_download_button=False
)
screenshot = gr.Image(show_label=False, interactive=False, buttons=[])

with gr.Tab("Screenshot Pair") as tab_screenshot_pair:
with gr.Row():
screenshot1 = gr.Image(
show_label=False, interactive=False, show_download_button=False
)
screenshot2 = gr.Image(
show_label=False, interactive=False, show_download_button=False
)
screenshot1 = gr.Image(show_label=False, interactive=False, buttons=[])
screenshot2 = gr.Image(show_label=False, interactive=False, buttons=[])
with gr.Tab("Screenshot Gallery") as tab_screenshot_gallery:
screenshot_gallery = gr.Gallery(
columns=2,
show_download_button=False,
buttons=[],
show_label=False,
object_fit="contain",
preview=True,
Expand Down Expand Up @@ -379,12 +357,8 @@ def run_gradio(results_dir: Path):

with gr.Tab("Agent Info HTML") as tab_agent_info_html:
with gr.Row():
screenshot1_agent = gr.Image(
show_label=False, interactive=False, show_download_button=False
)
screenshot2_agent = gr.Image(
show_label=False, interactive=False, show_download_button=False
)
screenshot1_agent = gr.Image(show_label=False, interactive=False, buttons=[])
screenshot2_agent = gr.Image(show_label=False, interactive=False, buttons=[])
agent_info_html = gr.HTML()

with gr.Tab("Agent Info MD") as tab_agent_info_md:
Expand Down Expand Up @@ -547,7 +521,7 @@ def run_gradio(results_dir: Path):
port = os.getenv("AGENTXRAY_APP_PORT", None)
if isinstance(port, str):
port = int(port)
demo.launch(server_port=port, share=do_share)
demo.launch(server_port=port, share=do_share, theme=gr.themes.Soft(), css=css)


def handle_key_event(key_event, step_id: StepId):
Expand Down Expand Up @@ -643,7 +617,7 @@ def update_screenshot_gallery(som_or_not: str):
gallery = gr.Gallery(
value=screenshots_and_label,
columns=2,
show_download_button=False,
buttons=[],
show_label=False,
object_fit="contain",
preview=True,
Expand Down
Loading
Loading