PreCET/agents.py

94 lines
3.4 KiB
Python

from crewai import Agent
from textwrap import dedent
from langchain_community.llms import ollama
from tools.search_tools import SearchTools
"""
Creating Agents Cheat Sheet:
- Think like a boss. Work backwards from the goal and think which employee
you need to hire to get the job done.
- Define the Captain of the crew who orient the other agents towards the goal.
- Define which experts the captain needs to communicate with and delegate tasks to.
Build a top down structure of the crew.
Goal:
- Create a 7-day travel itinerary with detailed per-day plans,
including budget, packing suggestions, and safety tips.
Captain:
- Master Networker
Employees/Experts to hire:
- Local Expert
- Sports Analyst
Notes:
- Agents should be results driven and have a clear goal in mind
- Role is their job title
- Goals should actionable
- Backstory should be their resume
"""
class TalkingAgents:
def __init__(self):
self.Ollama = ollama.Ollama(model="openhermes")
self.max_iterations = 15
def master_networker(self):
return Agent(
role="Master Networker",
backstory=dedent(
f"""Expert in determining what subjects are best for making small talk in a marketing environment.
I have decades of expereince coaching marketing professionals on how to use small talk to elevate the customer experience."""),
goal=dedent(f"""
Compile a multi-paragraph summary of interesting and recent topics to discuss with our clients.
These details should have dates pertaining to the events, and enough information to summarize the topic.
"""),
tools=[
SearchTools.search_internet
],
verbose=True,
llm=self.Ollama,
max_iter=self.max_iterations,
memory=True
)
def local_expert(self):
return Agent(
role="Local Expert",
backstory=dedent(
f"""Knowledgeable local resident who is up to date on local news, weather, and its customs."""),
goal=dedent(
f"""Provide the most interesting and most modernly relevant information about the city, keeping in mind the time of year and local customs."""),
tools=[
SearchTools.search_internet
],
verbose=True,
llm=self.Ollama,
max_iter=self.max_iterations,
allow_delegation=False,
memory=True
)
def sports_analyst(self):
return Agent(
role="Sports Analyst",
backstory=dedent(
f"""Avid sports fan who knows everything about sports and stays up to date on recent results in all sports."""),
goal=dedent(
f"""Provide information about the sports teams in the selected city, including season performances and most recent results.
Also keep in mind the current date and if local teams are in their off-season. If they are in their off-season,
be sure to note their projected performance in the upcoming 2024 season."""),
tools=[
SearchTools.search_internet
],
verbose=True,
llm=self.Ollama,
max_iter=self.max_iterations,
allow_delegation=False,
memory=True
)