Advertisement
Guest User

How to use CrewAI

a guest
Oct 10th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | Source Code | 0 0
  1. ##Step 1 Setup and imports
  2. from crewai import Agent, Task, Crew
  3. from langchain_openai import OpenAI
  4.  
  5. # Set up OpenAI API key
  6. OPENAI_API_KEY = "INSERT YOUR OPENAI API KEY HERE"
  7.  
  8. # Initialize language model
  9. llm = OpenAI(temperature=0.7)
  10.  
  11. ##Step 2 - Create agents
  12. # Create Travel Agent
  13. travel_agent = Agent(
  14. role='Travel Agent',
  15. goal='Create detailed travel itineraries with specific attractions and restaurants',
  16. backstory="""Experienced travel agent with extensive knowledge of
  17. global destinations and their attractions""",
  18. verbose=True,
  19. llm=llm
  20. )
  21.  
  22. # Create Local Expert
  23. local_expert = Agent(
  24. role='Local Expert',
  25. goal='Provide insider knowledge with specific local recommendations',
  26. backstory="""Long-time resident with deep knowledge of local culture,
  27. cuisine, and hidden gems""",
  28. verbose=True,
  29. llm=llm
  30. )
  31.  
  32. ## Step 3 - Create tasks
  33. # Task for creating initial itinerary
  34. create_itinerary_task = Task(
  35. description="""Create a detailed 3-day itinerary for Tokyo, Japan.
  36. For each day, include:
  37. - At least 3 specific attractions with their actual names and brief descriptions
  38. - 2 specific restaurant recommendations with cuisine types and signature dishes
  39. - Estimated times for each activity and meal
  40. - Brief travel instructions between locations
  41. Start your response with 'TOKYO ITINERARY:' """,
  42. agent=travel_agent,
  43. expected_output="A detailed 3-day Tokyo travel itinerary with specific locations and times."
  44. )
  45.  
  46. # Task for enhancing itinerary with local insights
  47. enhance_itinerary_task = Task(
  48. description="""Review the Tokyo itinerary and enhance it with local insights.
  49. For each day:
  50. - Add 1-2 off-the-beaten-path attractions with specific names and why they're special
  51. - Suggest a local dining experience or food tour with a specific name and what makes it unique
  52. - Provide a tip for navigating Tokyo or experiencing Japanese culture
  53. Start your response with 'ENHANCED TOKYO ITINERARY:' followed by the complete, enhanced itinerary.""",
  54. agent=local_expert,
  55. expected_output="An enhanced Tokyo travel itinerary with specific local insights and experiences."
  56. )
  57.  
  58. ## Step 4 - Assemble the Crew and Execute
  59. trip_planning_crew = Crew(
  60. agents=[travel_agent, local_expert],
  61. tasks=[create_itinerary_task, enhance_itinerary_task],
  62. verbose=2
  63. )
  64.  
  65. print("\nPlanning a trip to Tokyo, Japan")
  66.  
  67. result = trip_planning_crew.kickoff()
  68. print("\nFinal Tokyo Trip Itinerary:")
  69. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement