crew异步任务入门

来自官方文档

import os
from crewai import Agent, Task, Crew
import ChatGLM
from langchain.agents import Tool
from langchain_community.tools import DuckDuckGoSearchRun
llm = ChatGLM.ChatGLM_LLM()
research_agent = Agent(
    llm =llm,
    role='Researcher',
    goal='Find and summarize the latest AI news',
    backstory="""You're a researcher at a large company.
    You're responsible for analyzing data and providing insights
    to the business.""",
    verbose=False
)

topic = 'AI'

# Creating a writer agent
writer = Agent(
  role='Writer',
  llm= llm ,
  goal=f'Narrate compelling tech stories around {topic}',
  verbose=False,
  backstory="""With a flair for simplifying complex topics, you craft
  engaging narratives that captivate and educate, bringing new
  discoveries to light in an accessible manner."""
)



# Install duckduckgo-search for this example:
# !pip install -U duckduckgo-search
search_tool = DuckDuckGoSearchRun()

# task = Task(
#   description='Find and summarize the latest AI news',
#     expected_output='A bullet list summary of the top 5 most important AI news',
#     agent=research_agent,
#   tools=[search_tool]
# )

list_ideas = Task(
    description="List of 5 interesting ideas to explore for na article about AI.",
    expected_output="Bullet point list of 5 ideas for an article.",
    agent=research_agent,
    async_execution=True # Will be executed asynchronously
)

list_important_history = Task(
    description="Research the history of AI and give me the 5 most important events.",
    expected_output="Bullet point list of 5 important events.",
    agent=research_agent,
    async_execution=True # Will be executed asynchronously
)

write_article = Task(
    description="Write an article about AI, it's history and interesting ideas.",
    expected_output="A 4 paragraph article about AI.",
    agent=writer,
    context=[list_ideas, list_important_history] # Will wait for the output of the two tasks to be completed
)

crew = Crew(
    agents=[research_agent,writer],
    tasks=[list_ideas,list_important_history,write_article],
    verbose=0
)

result = crew.kickoff()
print(result)

你可能感兴趣的:(LangChain,langchain)