From 63e7852fbef40adb6ded00ea48bd1bb23d3bee40 Mon Sep 17 00:00:00 2001 From: wuyiqunLu Date: Mon, 20 May 2024 18:09:56 +0800 Subject: [PATCH 1/5] feat: log pregress for vision agent v2 --- vision_agent/agent/vision_agent_v2.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/vision_agent/agent/vision_agent_v2.py b/vision_agent/agent/vision_agent_v2.py index a20afcee..750940c9 100644 --- a/vision_agent/agent/vision_agent_v2.py +++ b/vision_agent/agent/vision_agent_v2.py @@ -167,6 +167,7 @@ def write_and_exec_code( retrieved_ltm: str, max_retry: int = 3, verbosity: int = 0, + log_progress: Callable[..., str] = None, ) -> Tuple[bool, str, str, Dict[str, List[str]]]: success = False counter = 0 @@ -178,6 +179,7 @@ def write_and_exec_code( success, result = exec.run_isolation(code) if verbosity == 2: _CONSOLE.print(Syntax(code, "python", theme="gruvbox-dark", line_numbers=True)) + log_progress(f"\tCode success: {success}\n\tResult: {str(result)}", code) _LOGGER.info(f"\tCode success: {success}, result: {str(result)}") working_memory: Dict[str, List[str]] = {} while not success and counter < max_retry: @@ -204,6 +206,7 @@ def write_and_exec_code( _CONSOLE.print( Syntax(code, "python", theme="gruvbox-dark", line_numbers=True) ) + log_progress(f"\tDebugging reflection: {reflection}\n\tResult: {result}") _LOGGER.info(f"\tDebugging reflection: {reflection}, result: {result}") if success: @@ -226,6 +229,7 @@ def run_plan( tool_recommender: Sim, long_term_memory: Optional[Sim] = None, verbosity: int = 0, + log_progress: Callable[..., str] = None, ) -> Tuple[str, str, List[Dict[str, Any]], Dict[str, List[str]]]: active_plan = [e for e in plan if "success" not in e or not e["success"]] current_code = code @@ -234,6 +238,10 @@ def run_plan( working_memory: Dict[str, List[str]] = {} for task in active_plan: + log_progress( + f"""Going to run the following task(s) in sequence: +{tabulate(tabular_data=[task], headers="keys", tablefmt="mixed_grid", maxcolwidths=_MAX_TABULATE_COL_WIDTH)}""" + ) _LOGGER.info( f""" {tabulate(tabular_data=[task], headers="keys", tablefmt="mixed_grid", maxcolwidths=_MAX_TABULATE_COL_WIDTH)}""" @@ -242,6 +250,7 @@ def run_plan( tool_info = "\n".join([e["doc"] for e in tools]) if verbosity == 2: + log_progress(f"Tools retrieved: {[e['desc'] for e in tools]}") _LOGGER.info(f"Tools retrieved: {[e['desc'] for e in tools]}") if long_term_memory is not None: @@ -259,6 +268,7 @@ def run_plan( exec, retrieved_ltm, verbosity=verbosity, + log_progress=log_progress, ) if task["type"] == "code": current_code = code @@ -271,6 +281,8 @@ def run_plan( _CONSOLE.print( Syntax(code, "python", theme="gruvbox-dark", line_numbers=True) ) + + log_progress(f"\tCode success: {success}\n\tResult: {str(result)}") _LOGGER.info(f"\tCode success: {success} result: {str(result)}") task["success"] = success @@ -308,10 +320,12 @@ def __init__( tool_recommender: Optional[Sim] = None, long_term_memory: Optional[Sim] = None, verbosity: int = 0, + report_progress_callback: Optional[Callable[..., Any]] = None, ) -> None: self.planner = OpenAILLM(temperature=0.0, json_mode=True) self.coder = OpenAILLM(temperature=0.0) self.exec = Execute(timeout=timeout) + self.report_progress_callback = report_progress_callback if tool_recommender is None: self.tool_recommender = Sim(TOOLS_DF, sim_key="desc") else: @@ -361,6 +375,10 @@ def chat_with_workflow( working_code = task["code"] user_req, plan = write_plan(chat, plan, TOOL_DESCRIPTIONS, self.planner) + self.log_progress( + f"""Plan: +{tabulate(tabular_data=plan, headers="keys", tablefmt="mixed_grid", maxcolwidths=_MAX_TABULATE_COL_WIDTH)}""" + ) _LOGGER.info( f"""Plan: {tabulate(tabular_data=plan, headers="keys", tablefmt="mixed_grid", maxcolwidths=_MAX_TABULATE_COL_WIDTH)}""" @@ -381,6 +399,7 @@ def chat_with_workflow( self.tool_recommender, self.long_term_memory, self.verbosity, + self.log_progress, ) success = all( task["success"] if "success" in task else False for task in plan @@ -393,6 +412,9 @@ def chat_with_workflow( retries += 1 + self.log_progress(f"The Vision Agent V2 has concluded this chat.") + self.log_progress(f"Plan success: {success}") + return { "code": working_code, "test": working_test, @@ -401,5 +423,7 @@ def chat_with_workflow( "plan": plan, } - def log_progress(self, description: str) -> None: + def log_progress(self, description: str, code: Optional[str] = "") -> None: + if self.report_progress_callback is not None: + self.report_progress_callback(description, code) pass From d0eb5c3d1851093c2e6af3924cf5fe74bda74282 Mon Sep 17 00:00:00 2001 From: wuyiqunLu Date: Mon, 20 May 2024 18:17:52 +0800 Subject: [PATCH 2/5] fix lint --- vision_agent/agent/vision_agent_v2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vision_agent/agent/vision_agent_v2.py b/vision_agent/agent/vision_agent_v2.py index 750940c9..38f4a8a9 100644 --- a/vision_agent/agent/vision_agent_v2.py +++ b/vision_agent/agent/vision_agent_v2.py @@ -412,7 +412,9 @@ def chat_with_workflow( retries += 1 - self.log_progress(f"The Vision Agent V2 has concluded this chat.") + self.log_progress( + "The Vision Agent V2 has concluded this chat." + ) self.log_progress(f"Plan success: {success}") return { From 1e5cdd003d8daaf67948af2fc2893ea2bbb0179a Mon Sep 17 00:00:00 2001 From: wuyiqunLu Date: Mon, 20 May 2024 23:18:58 +0800 Subject: [PATCH 3/5] fix lint --- vision_agent/agent/vision_agent_v2.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vision_agent/agent/vision_agent_v2.py b/vision_agent/agent/vision_agent_v2.py index 38f4a8a9..3bfbc637 100644 --- a/vision_agent/agent/vision_agent_v2.py +++ b/vision_agent/agent/vision_agent_v2.py @@ -412,9 +412,7 @@ def chat_with_workflow( retries += 1 - self.log_progress( - "The Vision Agent V2 has concluded this chat." - ) + self.log_progress("The Vision Agent V2 has concluded this chat.") self.log_progress(f"Plan success: {success}") return { From 3932bf3873fa57a16d2040d99872952395a63187 Mon Sep 17 00:00:00 2001 From: wuyiqunLu Date: Mon, 20 May 2024 23:49:32 +0800 Subject: [PATCH 4/5] fix lint --- vision_agent/agent/vision_agent_v2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vision_agent/agent/vision_agent_v2.py b/vision_agent/agent/vision_agent_v2.py index 3bfbc637..ef00bc85 100644 --- a/vision_agent/agent/vision_agent_v2.py +++ b/vision_agent/agent/vision_agent_v2.py @@ -165,9 +165,9 @@ def write_and_exec_code( tool_info: str, exec: Execute, retrieved_ltm: str, + log_progress: Callable[..., str], max_retry: int = 3, verbosity: int = 0, - log_progress: Callable[..., str] = None, ) -> Tuple[bool, str, str, Dict[str, List[str]]]: success = False counter = 0 @@ -227,9 +227,9 @@ def run_plan( exec: Execute, code: str, tool_recommender: Sim, + log_progress: Callable[..., str], long_term_memory: Optional[Sim] = None, verbosity: int = 0, - log_progress: Callable[..., str] = None, ) -> Tuple[str, str, List[Dict[str, Any]], Dict[str, List[str]]]: active_plan = [e for e in plan if "success" not in e or not e["success"]] current_code = code From 3aed2308ad2b44786d1623f29109217c4faa9ccc Mon Sep 17 00:00:00 2001 From: wuyiqunLu Date: Tue, 21 May 2024 00:29:08 +0800 Subject: [PATCH 5/5] fix lint --- vision_agent/agent/vision_agent_v2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vision_agent/agent/vision_agent_v2.py b/vision_agent/agent/vision_agent_v2.py index ef00bc85..5d2be898 100644 --- a/vision_agent/agent/vision_agent_v2.py +++ b/vision_agent/agent/vision_agent_v2.py @@ -267,8 +267,8 @@ def run_plan( tool_info, exec, retrieved_ltm, + log_progress, verbosity=verbosity, - log_progress=log_progress, ) if task["type"] == "code": current_code = code @@ -397,9 +397,9 @@ def chat_with_workflow( self.exec, working_code, self.tool_recommender, + self.log_progress, self.long_term_memory, self.verbosity, - self.log_progress, ) success = all( task["success"] if "success" in task else False for task in plan