Skip to content

Commit

Permalink
Merge pull request #26 from ShoggothAI/rename-task-recipe
Browse files Browse the repository at this point in the history
MOTLEYDEV-43: rename TaskRecipe to Task and Task to TaskUnit
  • Loading branch information
whimo authored May 19, 2024
2 parents ee66c35 + a0c76f6 commit 1ea0e5c
Show file tree
Hide file tree
Showing 63 changed files with 455 additions and 446 deletions.
24 changes: 24 additions & 0 deletions examples/MotleyTool for AutoGen agents.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions examples/_test_single_llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from motleycrew import MotleyCrew
from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.common.utils import configure_logging
from motleycrew.tasks import SimpleTaskRecipe
from motleycrew.tasks import SimpleTask


def main():
Expand All @@ -23,7 +23,7 @@ def main():
crew = MotleyCrew()

# Create tasks for your agents
task = SimpleTaskRecipe(
task = SimpleTask(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Expand Down
4 changes: 2 additions & 2 deletions examples/_test_single_openai_tools_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from motleycrew.agents.langchain.openai_tools_react import ReactOpenAIToolsAgent
from motleycrew.agents.langchain.react import ReactMotleyAgent
from motleycrew.common.utils import configure_logging
from motleycrew.tasks import SimpleTaskRecipe
from motleycrew.tasks import SimpleTask
from motleycrew.caching import enable_cache


Expand All @@ -21,7 +21,7 @@ def main():

for r in [researcher, researcher2]:
crew = MotleyCrew()
task = SimpleTaskRecipe(
task = SimpleTask(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Expand Down
4 changes: 2 additions & 2 deletions examples/blog_post/blog_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from motleycrew.agents.langchain.react import ReactMotleyAgent

from motleycrew.tools.llm_tool import LLMTool
from motleycrew import MotleyCrew, TaskRecipe
from motleycrew import MotleyCrew, Task

from .blog_post_input import text

Expand Down Expand Up @@ -110,7 +110,7 @@

# Create tasks for your agents
crew = MotleyCrew()
task1 = TaskRecipe(
task1 = Task(
crew=crew,
name="Write a blog post from the provided information",
description=f"""Write a blog post of at most {max_words} words and at least {min_words}
Expand Down
8 changes: 4 additions & 4 deletions examples/delegation_crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.agents.langchain.react import ReactMotleyAgent
from motleycrew.common.utils import configure_logging
from motleycrew.tasks import SimpleTaskRecipe
from motleycrew.tasks import SimpleTask

WORKING_DIR = Path(os.path.realpath("."))

Expand Down Expand Up @@ -55,7 +55,7 @@ def main():

# Create tasks for your agents

analysis_report_task = SimpleTaskRecipe(
analysis_report_task = SimpleTask(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Expand All @@ -64,7 +64,7 @@ def main():
agent=researcher,
)

literature_summary_task = SimpleTaskRecipe(
literature_summary_task = SimpleTask(
crew=crew,
name="provide a literature summary of recent papers on AI",
description="""Conduct a comprehensive literature review of the latest advancements in AI in 2024.
Expand All @@ -73,7 +73,7 @@ def main():
agent=researcher,
)

blog_post_task = SimpleTaskRecipe(
blog_post_task = SimpleTask(
crew=crew,
name="produce blog post on AI advancements",
description="""Using the insights provided by a thorough web search, develop an engaging blog
Expand Down
6 changes: 3 additions & 3 deletions examples/delegation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent
from motleycrew.tools.image_generation import DallEImageGeneratorTool
from motleycrew.common.utils import configure_logging
from motleycrew.tasks import SimpleTaskRecipe
from motleycrew.tasks import SimpleTask

WORKING_DIR = Path(os.path.realpath("."))

Expand Down Expand Up @@ -68,7 +68,7 @@ def main():
tools=[DallEImageGeneratorTool(os.path.realpath("./images"))],
)

blog_post_task = SimpleTaskRecipe(
blog_post_task = SimpleTask(
crew=crew,
name="produce blog post on AI advancements",
description="""Using the insights provided by a thorough web search, develop an engaging blog
Expand All @@ -79,7 +79,7 @@ def main():
agent=writer,
)

illustration_task = SimpleTaskRecipe(
illustration_task = SimpleTask(
crew=crew,
name="create an illustration for the blog post",
description="""Create beautiful and insightful illustrations to accompany the blog post on AI advancements.
Expand Down
2 changes: 1 addition & 1 deletion examples/image_generation_crewai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import load_dotenv

from motleycrew import MotleyCrew, TaskRecipe
from motleycrew import MotleyCrew, Task
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.tools.image_generation import DallEImageGeneratorTool
from motleycrew.common.utils import configure_logging
Expand Down
2 changes: 1 addition & 1 deletion examples/math_crewai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import load_dotenv

from motleycrew import MotleyCrew, TaskRecipe
from motleycrew import MotleyCrew, Task
from motleycrew.agents.crewai import CrewAIMotleyAgent
from motleycrew.tools.python_repl import create_repl_tool
from motleycrew.common.utils import configure_logging
Expand Down
10 changes: 5 additions & 5 deletions examples/research_agent/research_agent_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from motleycrew import MotleyCrew
from motleycrew.storage import MotleyKuzuGraphStore
from motleycrew.common.utils import configure_logging
from motleycrew.applications.research_agent.question_task_recipe import QuestionTaskRecipe
from motleycrew.applications.research_agent.answer_task_recipe import AnswerTaskRecipe
from motleycrew.applications.research_agent.question_task import QuestionTask
from motleycrew.applications.research_agent.answer_task import AnswerTask

from motleycrew.tools.simple_retriever_tool import SimpleRetrieverTool

Expand Down Expand Up @@ -42,12 +42,12 @@ def main():
graph_store = MotleyKuzuGraphStore(db)
crew = MotleyCrew(graph_store=graph_store)

question_recipe = QuestionTaskRecipe(
question_task = QuestionTask(
crew=crew, question=QUESTION, query_tool=query_tool, max_iter=MAX_ITER
)
answer_recipe = AnswerTaskRecipe(answer_length=ANSWER_LENGTH, crew=crew)
answer_task = AnswerTask(answer_length=ANSWER_LENGTH, crew=crew)

question_recipe >> answer_recipe
question_task >> answer_task

done_tasks = crew.run()

Expand Down
2 changes: 1 addition & 1 deletion motleycrew/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .crew import MotleyCrew
from .tasks import TaskRecipe
from .tasks import Task
2 changes: 1 addition & 1 deletion motleycrew/agents/llama_index/llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from motleycrew.agents.parent import MotleyAgentParent
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.tasks import Task
from motleycrew.tasks import TaskUnit
from motleycrew.common import MotleySupportedTool
from motleycrew.common import MotleyAgentFactory
from motleycrew.common.utils import ensure_module_is_installed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

from motleycrew.crew import MotleyCrew
from motleycrew.tools import MotleyTool
from motleycrew.tasks import TaskRecipe
from motleycrew.tasks.task import TaskType
from motleycrew.tasks import Task
from motleycrew.applications.research_agent.question import Question, QuestionAnsweringTask
from motleycrew.tasks.task_unit import TaskUnitType
from motleycrew.tasks import TaskUnit
from motleycrew.applications.research_agent.question import Question, QuestionAnsweringTaskUnit
from motleycrew.applications.research_agent.question_answerer import AnswerSubQuestionTool
from motleycrew.storage import MotleyGraphStore


class AnswerTaskRecipe(TaskRecipe):
class AnswerTask(Task):
def __init__(
self,
crew: MotleyCrew,
answer_length: int = 1000,
):
super().__init__("AnswerTaskRecipe", crew)
super().__init__("AnswerTask", crew)
self.answer_length = answer_length
self.answerer = AnswerSubQuestionTool(
graph=self.graph_store, answer_length=self.answer_length
)

def get_next_task(self) -> QuestionAnsweringTask | None:
def get_next_unit(self) -> QuestionAnsweringTaskUnit | None:
query = (
"MATCH (n1:{}) "
"WHERE n1.answer IS NULL AND n1.context IS NOT NULL "
Expand All @@ -38,7 +38,7 @@ def get_next_task(self) -> QuestionAnsweringTask | None:
if not query_result:
return None
else:
return QuestionAnsweringTask(question=query_result[0])
return QuestionAnsweringTaskUnit(question=query_result[0])

def get_worker(self, tools: Optional[List[MotleyTool]]) -> Runnable:
return self.answerer
6 changes: 3 additions & 3 deletions motleycrew/applications/research_agent/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from motleycrew.storage.graph_node import MotleyGraphNode
from motleycrew.tasks import Task
from motleycrew.tasks import TaskUnit

REPR_CONTEXT_LENGTH_LIMIT = 30

Expand All @@ -28,9 +28,9 @@ def __repr__(self):
)


class QuestionGenerationTask(Task):
class QuestionGenerationTaskUnit(TaskUnit):
question: Question


class QuestionAnsweringTask(Task):
class QuestionAnsweringTaskUnit(TaskUnit):
question: Question
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from motleycrew.storage import MotleyGraphStore
from motleycrew.common.utils import print_passthrough

from motleycrew.applications.research_agent.question import Question, QuestionAnsweringTask
from motleycrew.applications.research_agent.question import Question, QuestionAnsweringTaskUnit


_default_prompt = PromptTemplate.from_template(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from motleycrew.storage import MotleyGraphStore


from motleycrew.applications.research_agent.question import Question, QuestionGenerationTask
from motleycrew.applications.research_agent.question import Question, QuestionGenerationTaskUnit

IS_SUBQUESTION_PREDICATE = "is_subquestion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

from langchain_core.runnables import Runnable

from motleycrew.tasks import TaskRecipe
from ...tasks.task import TaskType
from motleycrew.tasks import Task
from ...tasks.task_unit import TaskUnitType
from motleycrew.tools import MotleyTool
from motleycrew.crew import MotleyCrew
from .question import Question, QuestionGenerationTask
from .question import Question, QuestionGenerationTaskUnit
from .question_generator import QuestionGeneratorTool
from .question_prioritizer import QuestionPrioritizerTool


class QuestionTaskRecipe(TaskRecipe):
class QuestionTask(Task):
def __init__(
self,
question: str,
query_tool: MotleyTool,
crew: MotleyCrew,
max_iter: int = 10,
name: str = "QuestionTaskRecipe",
name: str = "QuestionTask",
):
# Need to supply the crew already at this stage
# because need to use the graph store in constructor
Expand All @@ -34,7 +34,7 @@ def __init__(
query_tool=query_tool, graph=self.graph_store
)

def get_next_task(self) -> QuestionGenerationTask | None:
def get_next_unit(self) -> QuestionGenerationTaskUnit | None:
if self.done:
return None

Expand All @@ -51,9 +51,9 @@ def get_next_task(self) -> QuestionGenerationTask | None:
}
)
logging.info("Most pertinent question according to the tool: %s", most_pertinent_question)
return QuestionGenerationTask(question=most_pertinent_question)
return QuestionGenerationTaskUnit(question=most_pertinent_question)

def register_completed_task(self, task: TaskType) -> None:
def register_completed_unit(self, task: TaskUnitType) -> None:
logging.info("==== Completed iteration %s of %s ====", self.n_iter + 1, self.max_iter)
self.n_iter += 1
if self.n_iter >= self.max_iter:
Expand Down
2 changes: 1 addition & 1 deletion motleycrew/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .enums import LLMFamily
from .enums import LLMFramework
from .enums import GraphStoreType
from .enums import TaskStatus
from .enums import TaskUnitStatus
from .enums import LunaryRunType
from .enums import LunaryEventName

Expand Down
2 changes: 1 addition & 1 deletion motleycrew/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GraphStoreType:
KUZU = "kuzu"


class TaskStatus:
class TaskUnitStatus:
PENDING = "pending"
RUNNING = "running"
DONE = "done"
Expand Down
Loading

0 comments on commit 1ea0e5c

Please sign in to comment.