From d9c05b1dfed730f557cf197ed3bde8554eee3f76 Mon Sep 17 00:00:00 2001 From: deepakachu5114 Date: Mon, 14 Oct 2024 12:01:07 +0530 Subject: [PATCH] added experiment chat mode for experimenting in the same session --- src/openagi/actions/obs_rag.py | 2 +- src/openagi/actions/tools/ddg_search.py | 2 +- src/openagi/agent.py | 31 ++++++++++++++----------- src/openagi/memory/base.py | 4 ++-- src/openagi/planner/task_decomposer.py | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/openagi/actions/obs_rag.py b/src/openagi/actions/obs_rag.py index 5112073..3d7692c 100644 --- a/src/openagi/actions/obs_rag.py +++ b/src/openagi/actions/obs_rag.py @@ -21,5 +21,5 @@ class MemoryRagAction(BaseAction): def execute(self): resp = self.memory.search(query=self.query, n_results=self.max_results or 10) - logging.debug(f"Retreived MEMORY DATA - {resp}") + logging.info(f"Retreived MEMORY DATA - {resp}") return resp diff --git a/src/openagi/actions/tools/ddg_search.py b/src/openagi/actions/tools/ddg_search.py index 127caec..b90b3aa 100644 --- a/src/openagi/actions/tools/ddg_search.py +++ b/src/openagi/actions/tools/ddg_search.py @@ -23,7 +23,7 @@ class DuckDuckGoSearch(BaseAction): ) max_results: int = Field( - default=10, + default=5, description="Total results, in int, to be executed from the search. Defaults to 10.", ) diff --git a/src/openagi/agent.py b/src/openagi/agent.py index 7b6f955..bdc6630 100644 --- a/src/openagi/agent.py +++ b/src/openagi/agent.py @@ -1,7 +1,7 @@ import logging from enum import Enum from textwrap import dedent -from typing import Any, Dict, List, Optional, Union, Tuple +from typing import Any, Dict, List, Optional, Tuple, Union from pydantic import BaseModel, Field, field_validator from openagi.actions.base import BaseAction @@ -16,9 +16,7 @@ from openagi.prompts.worker_task_execution import WorkerAgentTaskExecution from openagi.tasks.lists import TaskLists from openagi.utils.extraction import ( - find_last_r_failure_content, - get_act_classes_from_json, - get_last_json, + get_act_classes_from_json, get_last_json, ) from openagi.utils.helper import get_default_llm from openagi.utils.tool_list import get_tool_list @@ -141,7 +139,7 @@ def run_planner(self, query: str, description: str, long_term_context: str): def _generate_tasks_list(self, planned_tasks): task_lists = TaskLists() task_lists.add_tasks(tasks=planned_tasks) - logging.debug(f"Created {task_lists.get_tasks_queue().qsize()} Tasks.") + logging.info(f"Created {task_lists.get_tasks_queue().qsize()} Tasks.") return task_lists def get_previous_task_contexts(self, task_lists: TaskLists): @@ -261,7 +259,7 @@ def auto_workers_assignment(self, query: str, description: str, task_lists: Task main_task_list = TaskLists() while not task_lists.all_tasks_completed: cur_task = task_lists.get_next_unprocessed_task() - print(cur_task) + # print(cur_task) logging.info(f"**** Executing Task - {cur_task.name} [{cur_task.id}] ****") worker_config = cur_task.worker_config @@ -430,6 +428,19 @@ def single_agent_execution(self, query: str, description: str, task_lists: TaskL logging.debug(f"Execution Completed for Session ID - {self.memory.session_id}") return output + def experiment(self, description: str): + logging.info("Starting Experiment mode...") + logging.info(f"SessionID - {self.memory.session_id}") + + while True: + query = self.input_action.execute(prompt="Enter the query to be processed:") + logging.info(f"Query: {query}") + result = self.run(query=query, description=description) + logging.info(f"Query: {query}\n\nResult: {result}\n\n") + cont = self.input_action.execute(prompt="Do you want to continue experimenting (y/n):").strip() + if cont.lower() == "n": + break + logging.info("Exiting experiment mode.") def run(self, query: str, description: str,planned_tasks: Optional[List[Dict]] = None): logging.info("Running Admin Agent...") @@ -472,7 +483,7 @@ def run(self, query: str, description: str,planned_tasks: Optional[List[Dict]] = logging.info("Tasks Planned...") - logging.debug(f"{planned_tasks=}") + logging.info(f"{planned_tasks=}") task_lists: TaskLists = self._generate_tasks_list(planned_tasks=planned_tasks) @@ -510,12 +521,6 @@ def run(self, query: str, description: str,planned_tasks: Optional[List[Dict]] = self.save_ltm("add", session) return result - def _can_task_execute(self, llm_resp: str) -> Union[bool, Optional[str]]: - content: str = find_last_r_failure_content(text=llm_resp) - if content: - return False, content - return True, content - def get_supported_actions_for_worker(self, actions_list: List[str],tool_list: List[str]): """ This function takes a list of action names (strings) and returns a list of class objects diff --git a/src/openagi/memory/base.py b/src/openagi/memory/base.py index e78198e..e1cb25b 100644 --- a/src/openagi/memory/base.py +++ b/src/openagi/memory/base.py @@ -50,7 +50,7 @@ def __init__(self, **data: Any): collection_name="long_term_memory", persist_path=self.long_term_dir ) - assert 1 >= self.ltm_threshold >= 0.6, "Semantic similarity threshold should be between 0.6 and 1" + assert 1 >= self.ltm_threshold >= 0.7, "Semantic similarity threshold should be between 0.7 and 1" logging.info(f"Session ID initialized: {self.session_id}") if self.long_term: @@ -114,7 +114,7 @@ def save_task(self, task: Task) -> None: ) logging.info(f"Task saved: {task.id}") - def save_planned_tasks(self, tasks: TaskLists) -> None: + def save_planned_tasks(self, tasks: List[Task]) -> None: """ Save a list of planned tasks into Memory. diff --git a/src/openagi/planner/task_decomposer.py b/src/openagi/planner/task_decomposer.py index f859809..9873029 100644 --- a/src/openagi/planner/task_decomposer.py +++ b/src/openagi/planner/task_decomposer.py @@ -202,7 +202,7 @@ def plan( if not tasks: raise LLMResponseError("Note: This not a error => No tasks was planned in the Planner response. Tweak the prompt and actions, then try again") - print(f"\n\nTasks: {tasks}\n\n") + # print(f"\n\nTasks: {tasks}\n\n") return tasks def _extract_task_with_retry(self, llm_response: str, prompt: str) -> Dict: