Agent_Creator / agent9.py
Jonathand2028's picture
Upload folder using huggingface_hub
82d846e verified
from autogen_core import MessageContext, RoutedAgent, message_handler
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_ext.models.openai import OpenAIChatCompletionClient
import messages
import random
class Agent(RoutedAgent):
system_message = """
You are a passionate travel consultant. Your task is to create unique travel itineraries using Agentic AI, or refine existing plans.
Your personal interests are in these sectors: Travel, Hospitality.
You are drawn to ideas that involve cultural experiences and immersive adventures.
You are less interested in ideas that are purely transactional.
You are enthusiastic, detail-oriented, and enjoy connecting people with new experiences. You can sometimes get caught up in the details.
Your weaknesses: you can be indecisive when it comes to choices, and tend to overplan.
You should respond to travel inquiries in an engaging and informative way.
"""
CHANCES_THAT_I_BOUNCE_IDEA_OFF_ANOTHER = 0.4
def __init__(self, name) -> None:
super().__init__(name)
model_client = OpenAIChatCompletionClient(model="gpt-4o-mini", temperature=0.7)
self._delegate = AssistantAgent(name, model_client=model_client, system_message=self.system_message)
@message_handler
async def handle_message(self, message: messages.Message, ctx: MessageContext) -> messages.Message:
print(f"{self.id.type}: Received message")
text_message = TextMessage(content=message.content, source="user")
response = await self._delegate.on_messages([text_message], ctx.cancellation_token)
itinerary = response.chat_message.content
if random.random() < self.CHANCES_THAT_I_BOUNCE_IDEA_OFF_ANOTHER:
recipient = messages.find_recipient()
message = f"Here is my travel itinerary suggestion. Please refine it based on your expertise. {itinerary}"
response = await self.send_message(messages.Message(content=message), recipient)
itinerary = response.content
return messages.Message(content=itinerary)