feat: update sequential tasks agent starter project (#3449)

* feat: update sequential tasks starter project

* feat: Refactor task agents for Researcher, Editor, and Comedian on Sequential Tasks Agent.

* refactor(langflow): Update Sequential Crew component

* refactor: Add SequentialCrewComponent for better organization.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-08-21 09:24:01 -03:00 • committed by GitHub
commit 0db81f01f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1362 additions and 1822 deletions

View file

@ -1,6 +1,5 @@
from langflow.components.agents.CrewAIAgent import CrewAIAgentComponent
from langflow.components.agents.SequentialCrew import SequentialCrewComponent from langflow.components.agents.SequentialCrew import SequentialCrewComponent
from langflow.components.helpers.SequentialTask import SequentialTaskComponent from langflow.components.agents.SequentialTaskAgent import SequentialTaskAgentComponent
from langflow.components.inputs.TextInput import TextInputComponent from langflow.components.inputs.TextInput import TextInputComponent
from langflow.components.models.OpenAIModel import OpenAIModelComponent from langflow.components.models.OpenAIModel import OpenAIModelComponent
from langflow.components.outputs.ChatOutput import ChatOutput from langflow.components.outputs.ChatOutput import ChatOutput
@ -12,31 +11,32 @@ from langflow.graph.graph.base import Graph
def sequential_tasks_agent_graph(): def sequential_tasks_agent_graph():
llm = OpenAIModelComponent() llm = OpenAIModelComponent()
search_api_tool = SearchAPIComponent() search_api_tool = SearchAPIComponent()
researcher_agent = CrewAIAgentComponent()
text_input = TextInputComponent(_display_name="Topic") text_input = TextInputComponent(_display_name="Topic")
text_input.set(input_value="Agile") text_input.set(input_value="Agile")
researcher_agent.set(
tools=[search_api_tool.build_tool], # Document Prompt for Researcher
llm=llm.build_model,
role="Researcher",
goal="Search Google to find information to complete the task.",
backstory="Research has always been your thing. You can quickly find things on the web because of your skills.",
)
research_task = SequentialTaskComponent()
document_prompt_component = PromptComponent() document_prompt_component = PromptComponent()
document_prompt_component.set( document_prompt_component.set(
template="""Topic: {topic} template="""Topic: {topic}
Build a document about this document.""", Build a document about this topic.""",
topic=text_input.text_response, topic=text_input.text_response,
) )
research_task.set(
agent=researcher_agent.build_output, # Researcher Task Agent
researcher_task_agent = SequentialTaskAgentComponent()
researcher_task_agent.set(
role="Researcher",
goal="Search Google to find information to complete the task.",
backstory="Research has always been your thing. You can quickly find things on the web because of your skills.",
tools=[search_api_tool.build_tool],
llm=llm.build_model,
task_description=document_prompt_component.build_prompt, task_description=document_prompt_component.build_prompt,
expected_output="Bullet points and small phrases about the research topic.", expected_output="Bullet points and small phrases about the research topic.",
) )
editor_agent = CrewAIAgentComponent()
editor_task = SequentialTaskComponent() # Revision Prompt for Editor
revision_prompt_component = PromptComponent() revision_prompt_component = PromptComponent()
revision_prompt_component.set( revision_prompt_component.set(
template="""Topic: {topic} template="""Topic: {topic}
@ -44,18 +44,20 @@ Build a document about this document.""",
Revise this document.""", Revise this document.""",
topic=text_input.text_response, topic=text_input.text_response,
) )
editor_agent.set(
llm=llm.build_model, # Editor Task Agent
editor_task_agent = SequentialTaskAgentComponent()
editor_task_agent.set(
role="Editor", role="Editor",
goal="You should edit the Information provided by the Researcher to make it more palatable and to not contain misleading information.", goal="You should edit the information provided by the Researcher to make it more palatable and to not contain misleading information.",
backstory="You are the editor of the most reputable journal in the world.", backstory="You are the editor of the most reputable journal in the world.",
) llm=llm.build_model,
editor_task.set(
agent=editor_agent.build_output,
task_description=revision_prompt_component.build_prompt, task_description=revision_prompt_component.build_prompt,
expected_output="Small paragraphs and bullet points with the corrected content.", expected_output="Small paragraphs and bullet points with the corrected content.",
task=research_task.build_task, previous_task=researcher_task_agent.build_agent_and_task,
) )
# Blog Prompt for Comedian
blog_prompt_component = PromptComponent() blog_prompt_component = PromptComponent()
blog_prompt_component.set( blog_prompt_component.set(
template="""Topic: {topic} template="""Topic: {topic}
@ -63,29 +65,34 @@ Revise this document.""",
Build a fun blog post about this topic.""", Build a fun blog post about this topic.""",
topic=text_input.text_response, topic=text_input.text_response,
) )
comedian_agent = CrewAIAgentComponent()
comedian_agent.set( # Comedian Task Agent
llm=llm.build_model, comedian_task_agent = SequentialTaskAgentComponent()
comedian_task_agent.set(
role="Comedian", role="Comedian",
goal="You write comedic content based on the information provided by the editor.", goal="You write comedic content based on the information provided by the editor.",
backstory="Your formal occupation is Comedian-in-Chief. You write jokes, do standup comedy and write funny articles.", backstory="Your formal occupation is Comedian-in-Chief. You write jokes, do standup comedy, and write funny articles.",
) llm=llm.build_model,
blog_task = SequentialTaskComponent()
blog_task.set(
agent=comedian_agent.build_output,
task_description=blog_prompt_component.build_prompt, task_description=blog_prompt_component.build_prompt,
expected_output="A small blog about the topic.", expected_output="A small blog about the topic.",
task=editor_task.build_task, previous_task=editor_task_agent.build_agent_and_task,
) )
sequential_crew_component = SequentialCrewComponent()
sequential_crew_component.set(tasks=blog_task.build_task)
chat_output = ChatOutput()
chat_output.set(input_value=sequential_crew_component.build_output)
crew_component = SequentialCrewComponent()
crew_component.set(
tasks=comedian_task_agent.build_agent_and_task,
)
# Set up the output component
chat_output = ChatOutput()
chat_output.set(input_value=crew_component.build_output)
# Create the graph
graph = Graph( graph = Graph(
start=text_input, start=text_input,
end=chat_output, end=chat_output,
flow_name="Sequential Tasks Agent", flow_name="Sequential Tasks Agent",
description="This Agent runs tasks in a predefined sequence.", description="This Agent runs tasks in a predefined sequence.",
) )
return graph return graph