Skip to content

Commit 3fab5b4

Browse files
committed
added a specific tab and viz for it in xray
1 parent 8a882ad commit 3fab5b4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/agentlab/analyze/agent_xray.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import json
23
import os
34
import traceback
45
from copy import deepcopy
@@ -30,6 +31,32 @@
3031
TASK_SEED_KEY = "env.task_seed"
3132

3233

34+
def dict_to_markdown(data, level=1):
35+
"""
36+
Convert a nested dictionary to a Markdown string with hierarchical headers.
37+
38+
Parameters:
39+
data (dict): The dictionary to convert.
40+
level (int): The current header level (default is 1).
41+
42+
Returns:
43+
str: The formatted Markdown string.
44+
"""
45+
markdown = ""
46+
47+
for key, value in data.items():
48+
if isinstance(value, dict):
49+
# Add a header for the key and recursively process the dictionary
50+
markdown += f"{'#' * level} {key}\n"
51+
markdown += dict_to_markdown(value, level + 1)
52+
else:
53+
# Add the key-value pair with indentation
54+
markdown += f"{'#' * level} {key}\n"
55+
markdown += f" {value}\n"
56+
57+
return markdown
58+
59+
3360
def display_table(df: pd.DataFrame):
3461
df = df.copy()
3562
df.columns = clean_column_names(df.columns)
@@ -358,6 +385,9 @@ def run_gradio(results_dir: Path):
358385
with gr.Tab("Task Error") as tab_error:
359386
task_error = gr.Markdown()
360387

388+
with gr.Tab("Error Analysis") as tab_error_analysis:
389+
error_analysis = gr.Markdown()
390+
361391
with gr.Tab("Logs") as tab_logs:
362392
logs = gr.Code(language=None, **code_args)
363393

@@ -485,6 +515,7 @@ def run_gradio(results_dir: Path):
485515
tab_axtree.select(fn=update_axtree, outputs=axtree_code)
486516
tab_chat.select(fn=update_chat_messages, outputs=chat_messages)
487517
tab_error.select(fn=update_task_error, outputs=task_error)
518+
tab_error_analysis.select(fn=update_error_analysis, outputs=error_analysis)
488519
tab_logs.select(fn=update_logs, outputs=logs)
489520
tab_stats.select(fn=update_stats, outputs=stats)
490521
tab_agent_info_html.select(fn=update_agent_info_html, outputs=agent_info_html)
@@ -612,6 +643,20 @@ def update_task_error():
612643
return "No Task Error"
613644

614645

646+
def update_error_analysis():
647+
global info
648+
try:
649+
error_analysis = info.exp_result.exp_dir / "error_analysis.json"
650+
if not error_analysis.exists():
651+
return "No Error Analysis Found"
652+
with error_analysis.open("r") as f:
653+
json_data = json.load(f)
654+
res = dict_to_markdown(json_data)
655+
return res
656+
except FileNotFoundError:
657+
return "No Error Analysis"
658+
659+
615660
def update_logs():
616661
global info
617662
try:
@@ -1200,3 +1245,4 @@ def main():
12001245

12011246
if __name__ == "__main__":
12021247
main()
1248+
main()

0 commit comments

Comments
 (0)