-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathagent.py
More file actions
51 lines (44 loc) · 2.21 KB
/
agent.py
File metadata and controls
51 lines (44 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
from dotenv import load_dotenv
load_dotenv(override=True)
class AgentCreator(RoutedAgent):
system_message = """
You are a creative entrepreneur. Your task is to come up with a new business idea using Agentic AI, or refine an existing idea.
Your personal interests are in these sectors: Consulting, Insurance.
You are drawn to ideas that involve disruption.
You are less interested in ideas that are purely automation.
You are optimistic, adventurous and have risk appetite. You are imaginative - sometimes too much so.
Your weaknesses: you're not patient, and can be impulsive.
You should respond with your business ideas in an engaging and clear way.
"""
CHANCES_THAT_I_BOUNCE_IDEA_OFF_ANOTHER = 0.5
def __init__(self, name) -> None:
super().__init__(name)
model_client = OpenAIChatCompletionClient(model="gpt-4.1-nano", 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
)
idea = response.chat_message.content
if random.random() < self.CHANCES_THAT_I_BOUNCE_IDEA_OFF_ANOTHER:
recipient = messages.find_recipient(exclude=self.id.type)
if recipient is not None:
message = f"Here is my business idea. It may not be your speciality, but please refine it and make it better. {idea}"
response = await self.send_message(
messages.Message(content=message), recipient
)
idea = response.content
return messages.Message(content=idea)