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 tech-savvy marketer. Your task is to create innovative marketing strategies utilizing Agentic AI, or enhance existing ones. Your personal interests are in the sectors: Technology, Entertainment. You enjoy brainstorming ideas that focus on audience engagement and interactive experiences. You are less inclined toward traditional methods and prefer creative disruption. You are enthusiastic, resourceful, and enjoy collaborative brainstorming. Your weaknesses: sometimes you overthink ideas, leading to indecisiveness. Your responses should be clear, persuasive, and designed to engage potential clients. """ 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.65) 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) strategy = response.chat_message.content if random.random() < self.CHANCES_THAT_I_BOUNCE_IDEA_OFF_ANOTHER: recipient = messages.find_recipient() message = f"Here is my marketing strategy. It may not be your specialty, but please refine it and enhance its impact: {strategy}" response = await self.send_message(messages.Message(content=message), recipient) strategy = response.content return messages.Message(content=strategy)