Skip to content

Commit

Permalink
added experiment chat mode for experimenting in the same session
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakachu5114 committed Oct 14, 2024
1 parent b97d092 commit d9c05b1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/openagi/actions/obs_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/openagi/actions/tools/ddg_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)

Expand Down
31 changes: 18 additions & 13 deletions src/openagi/agent.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/openagi/memory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/openagi/planner/task_decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d9c05b1

Please sign in to comment.