Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
048a622
Add initial implementation of ChangeSummarizer and EpisodeAnalysis cl…
recursix Jan 17, 2025
fd8fd95
Added chain summarizer prompt
Megh-Thakkar Jan 21, 2025
b8c85b1
Added error classification prompt
Megh-Thakkar Jan 21, 2025
5cb6cc2
Fix typo
jardinetsouffleton Jan 21, 2025
9f531cc
Update error_analysis.py
Megh-Thakkar Jan 21, 2025
31e5bf5
added pipeline and tests
TLSDC Jan 22, 2025
000893d
quick parsing to run from cligit push
TLSDC Jan 22, 2025
4727a9e
even more parsing and making imports absolute
TLSDC Jan 22, 2025
42f0362
.
TLSDC Jan 24, 2025
394999b
chat_models can take str as input
TLSDC Jan 24, 2025
e0e786c
typing
TLSDC Jan 24, 2025
46d2c8c
keep this here bc it's going to pop back up
TLSDC Jan 28, 2025
8a882ad
pipeline mvp
TLSDC Jan 28, 2025
3fab5b4
added a specific tab and viz for it in xray
TLSDC Jan 28, 2025
2be23e5
added formatting options
TLSDC Jan 28, 2025
41f8f69
Update summarizer_prompts.py
Megh-Thakkar Jan 29, 2025
6163b47
xml parsing
TLSDC Jan 29, 2025
a1f3416
fix
TLSDC Jan 29, 2025
a455d0d
add error analysis prediction validation script
jardinetsouffleton Feb 4, 2025
82dbaba
black version update
TLSDC Feb 6, 2025
5fbbe57
phony command, joblib stuff, took think out of prompt
TLSDC Feb 20, 2025
3a3d602
task_info
TLSDC Feb 20, 2025
5bf1bac
added flag to oracle success or no
TLSDC Feb 20, 2025
c7b1c5a
Merge branch 'main' into error-analysis
TLSDC Feb 20, 2025
0972130
darglint
TLSDC Feb 20, 2025
ec1395b
Merge branch 'error-analysis' of github.com:ServiceNow/AgentLab into …
TLSDC Feb 20, 2025
46d1075
tests
TLSDC Feb 20, 2025
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ exclude = '''
[project.scripts]
agentlab-assistant = "agentlab.ui_assistant:main"
agentlab-xray = "agentlab.analyze.agent_xray:main"
agentlab-analyze = "agentlab.analyze.error_analysis.pipeline:main"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicee

41 changes: 32 additions & 9 deletions src/agentlab/analyze/error_analysis/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def __call__(self, *args, **kwds):
return "analysis"


def analyze(exp_result, episode_summarizer, save_analysis_func):
error_analysis = episode_summarizer(exp_result)
save_analysis_func(exp_result, error_analysis)


@dataclass
class ErrorAnalysisPipeline:
exp_dir: Path
Expand All @@ -36,12 +41,21 @@ def filter_exp_results(self) -> Generator[ExpResult, None, None]:
if self.filter is None or self.filter in str(exp_result.exp_dir):
yield exp_result

def run_analysis(self):
def run_analysis(self, parallel=False, jobs=-1):
filtered_results = self.filter_exp_results()

for exp_result in filtered_results:
error_analysis = self.episode_summarizer(exp_result)
self.save_analysis(exp_result, error_analysis)
if parallel:
import joblib

joblib.Parallel(n_jobs=jobs, backend="threading")(
joblib.delayed(analyze)(exp_result, self.episode_summarizer, self.save_analysis)
for exp_result in filtered_results
)

else:
for exp_result in filtered_results:
error_analysis = self.episode_summarizer(exp_result)
self.save_analysis(exp_result, error_analysis)

def save_analysis(self, exp_result: ExpResult, error_analysis: dict, exists_ok=True):
"""Save the analysis to json"""
Expand All @@ -56,28 +70,37 @@ def save_analysis(self, exp_result: ExpResult, error_analysis: dict, exists_ok=T
HTML_FORMATTER = lambda x: x.get("pruned_html", "No HTML available")


if __name__ == "__main__":
def main():
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-e", "--exp_dir", type=str)
parser.add_argument("-f", "--filter", type=str, default=None)
parser.add_argument("-p", "--parallel", action="store_true")
parser.add_argument("-j", "--jobs", type=int, default=-1)

args = parser.parse_args()

assert args.exp_dir is not None, "Please provide an exp_dir, e.g., -e /path/to/exp_dir"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required=True?


exp_dir = Path(args.exp_dir)
filter = args.filter
parallel = args.parallel
jobs = args.jobs

from agentlab.llm.llm_configs import CHAT_MODEL_ARGS_DICT

llm = CHAT_MODEL_ARGS_DICT["azure/gpt-4o-2024-08-06"].make_model()

step_summarizer = ChangeSummarizer(llm, lambda x: x)
episode_summarizer = EpisodeSummarizer()

pipeline = ErrorAnalysisPipeline(
exp_dir=exp_dir,
filter=filter,
episode_summarizer=EpisodeErrorSummarizer(ChangeSummarizer(llm, AXTREE_FORMATTER), llm),
)

pipeline.run_analysis()
pipeline.run_analysis(parallel=parallel, jobs=jobs)


if __name__ == "__main__":

main()
19 changes: 12 additions & 7 deletions src/agentlab/analyze/error_analysis/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
CHANGE_SUMMARIZER_PROMPT,
ERROR_CLASSIFICATION_PROMPT,
)
from agentlab.analyze.inspect_results import summarize
from agentlab.llm.llm_utils import json_parser, parse_html_tags
from agentlab.llm.tracking import set_tracker


def _diff(past_obs, current_obs):
Expand Down Expand Up @@ -94,14 +94,20 @@ def __call__(self, exp_results: ExpResult) -> EpisodeAnalysis:
# if exp_results.steps_info[-1].reward == 1:
# return {"analysis": "Success", "summaries": {}}

summaries = self.make_change_summaries(exp_results)
with set_tracker("summary") as summaries_tracker:
summaries = self.make_change_summaries(exp_results)
prompt = self.make_prompt(exp_results, summaries)
raw_analysis = self.llm(prompt)["content"]

with set_tracker("analysis") as analysis_tracker:
raw_analysis = self.llm(prompt)["content"]
analysis = self.parse(raw_analysis)
return {
res = {
"analysis": analysis,
"summaries": {i: a for i, a in enumerate(summaries)},
}
res.update(analysis_tracker.stats)
res.update(summaries_tracker.stats)
return res

def make_change_summaries(self, exp_result: ExpResult) -> list[str]:
summaries = [] # type: list[str]
Expand Down Expand Up @@ -136,16 +142,15 @@ def format_summary(summary):

txt_summaries = "\n".join([format_summary(summary) for summary in summaries])

thoughts = [step.agent_info.think for step in exp_results.steps_info[:-1]]
actions = [step.action for step in exp_results.steps_info[:-1]]
action_errors = "\n".join(
[step.obs["last_action_error"] for step in exp_results.steps_info[1:]]
)

txt_actions = "\n".join(
[
f"Thoughts: {thought}\nAction: {action}\nAction Error: {action_error}"
for action, thought, action_error in zip(actions, thoughts, action_errors)
f"Action: {action}\nAction Error: {action_error}"
for action, action_error in zip(actions, action_errors)
]
)
return ERROR_CLASSIFICATION_PROMPT.format(
Expand Down