Skip to content

Commit cd61c80

Browse files
authored
Fixing discussion object when adding images w/o detail (#128)
* switching to goal_object in xray * adding excpetion for when summary isnt available * fixing discussion w/ images
1 parent a7d6467 commit cd61c80

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/agentlab/analyze/agent_xray.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from agentlab.experiments.exp_utils import RESULTS_DIR
2222
from agentlab.experiments.study import get_most_recent_study
2323
from agentlab.llm.chat_api import make_system_message, make_user_message
24+
from agentlab.llm.llm_utils import BaseMessage as AgentLabBaseMessage
2425
from agentlab.llm.llm_utils import Discussion
2526

2627
select_dir_instructions = "Select Experiment Directory"
@@ -740,7 +741,7 @@ def get_episode_info(info: Info):
740741
steps_info = info.exp_result.steps_info
741742
step_info = steps_info[info.step]
742743
try:
743-
goal = step_info.obs["goal"]
744+
goal = step_info.obs["goal_object"]
744745
except KeyError:
745746
goal = None
746747
try:
@@ -757,7 +758,7 @@ def get_episode_info(info: Info):
757758
758759
**Goal:**
759760
760-
{code(goal)}
761+
{code(str(AgentLabBaseMessage('', goal)))}
761762
762763
**Task info:**
763764
@@ -992,20 +993,23 @@ def get_directory_contents(results_dir: Path):
992993
continue
993994

994995
exp_description = dir.name
995-
# get summary*.csv files and find the most recent
996-
summary_files = list(dir.glob("summary*.csv"))
997-
if len(summary_files) != 0:
998-
most_recent_summary = max(summary_files, key=os.path.getctime)
999-
summary_df = pd.read_csv(most_recent_summary)
1000-
1001-
# get row with max avg_reward
1002-
max_reward_row = summary_df.loc[summary_df["avg_reward"].idxmax()]
1003-
reward = max_reward_row["avg_reward"] * 100
1004-
completed = max_reward_row["n_completed"]
1005-
n_err = max_reward_row["n_err"]
1006-
exp_description += (
1007-
f" - avg-reward: {reward:.1f}% - completed: {completed} - errors: {n_err}"
1008-
)
996+
try:
997+
# get summary*.csv files and find the most recent
998+
summary_files = list(dir.glob("summary*.csv"))
999+
if len(summary_files) != 0:
1000+
most_recent_summary = max(summary_files, key=os.path.getctime)
1001+
summary_df = pd.read_csv(most_recent_summary)
1002+
1003+
# get row with max avg_reward
1004+
max_reward_row = summary_df.loc[summary_df["avg_reward"].idxmax()]
1005+
reward = max_reward_row["avg_reward"] * 100
1006+
completed = max_reward_row["n_completed"]
1007+
n_err = max_reward_row["n_err"]
1008+
exp_description += (
1009+
f" - avg-reward: {reward:.1f}% - completed: {completed} - errors: {n_err}"
1010+
)
1011+
except Exception as e:
1012+
print(f"Error while reading summary file: {e}")
10091013

10101014
exp_descriptions.append(exp_description)
10111015

src/agentlab/llm/llm_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import time
99
from copy import deepcopy
1010
from functools import cache
11-
from typing import TYPE_CHECKING
12-
from typing import Any, Union
11+
from typing import TYPE_CHECKING, Any, Union
1312
from warnings import warn
1413

1514
import numpy as np
@@ -356,7 +355,7 @@ def add_image(self, image: np.ndarray | Image.Image | str, detail: str = None):
356355
if detail:
357356
self.add_content("image_url", {"url": image_url, "detail": detail})
358357
else:
359-
self.add_content("image_url", image_url)
358+
self.add_content("image_url", {"url": image_url})
360359

361360
def to_markdown(self):
362361
if isinstance(self["content"], str):

0 commit comments

Comments
 (0)