|
3 | 3 | import logging
|
4 | 4 |
|
5 | 5 | import openai
|
6 |
| -from agnext.agent_components.model_client import OpenAI |
7 | 6 | from agnext.application_components import (
|
8 | 7 | SingleThreadedAgentRuntime,
|
9 | 8 | )
|
10 | 9 | from agnext.chat.agents.oai_assistant import OpenAIAssistantAgent
|
11 | 10 | from agnext.chat.patterns.group_chat import GroupChat, GroupChatOutput
|
12 |
| -from agnext.chat.patterns.orchestrator import Orchestrator |
| 11 | +from agnext.chat.patterns.orchestrator_chat import OrchestratorChat |
13 | 12 | from agnext.chat.types import TextMessage
|
14 | 13 | from agnext.core._agent import Agent
|
15 | 14 | from agnext.core.intervention import DefaultInterventionHandler, DropMessage
|
@@ -38,20 +37,28 @@ def reset(self) -> None:
|
38 | 37 |
|
39 | 38 |
|
40 | 39 | class LoggingHandler(DefaultInterventionHandler):
|
| 40 | + send_color = "\033[31m" |
| 41 | + response_color = "\033[34m" |
| 42 | + reset_color = "\033[0m" |
| 43 | + |
41 | 44 | @override
|
42 | 45 | async def on_send(self, message: Any, *, sender: Agent | None, recipient: Agent) -> Any | type[DropMessage]:
|
43 | 46 | if sender is None:
|
44 |
| - print(f"Sending message to {recipient.name}: {message}") |
| 47 | + print(f"{self.send_color}Sending message to {recipient.name}:{self.reset_color} {message}") |
45 | 48 | else:
|
46 |
| - print(f"Sending message from {sender.name} to {recipient.name}: {message}") |
| 49 | + print( |
| 50 | + f"{self.send_color}Sending message from {sender.name} to {recipient.name}:{self.reset_color} {message}" |
| 51 | + ) |
47 | 52 | return message
|
48 | 53 |
|
49 | 54 | @override
|
50 | 55 | async def on_response(self, message: Any, *, sender: Agent, recipient: Agent | None) -> Any | type[DropMessage]:
|
51 | 56 | if recipient is None:
|
52 |
| - print(f"Received response from {sender.name}: {message}") |
| 57 | + print(f"{self.response_color}Received response from {sender.name}:{self.reset_color} {message}") |
53 | 58 | else:
|
54 |
| - print(f"Received response from {sender.name} to {recipient.name}: {message}") |
| 59 | + print( |
| 60 | + f"{self.response_color}Received response from {sender.name} to {recipient.name}:{self.reset_color} {message}" |
| 61 | + ) |
55 | 62 | return message
|
56 | 63 |
|
57 | 64 |
|
@@ -131,19 +138,47 @@ async def orchestrator(message: str) -> None:
|
131 | 138 | thread_id=product_manager_oai_thread.id,
|
132 | 139 | )
|
133 | 140 |
|
134 |
| - chat = Orchestrator( |
135 |
| - "Manager", |
136 |
| - "A software development team manager.", |
137 |
| - runtime, |
138 |
| - [developer, product_manager], |
139 |
| - model_client=OpenAI(model="gpt-3.5-turbo"), |
| 141 | + planner_oai_assistant = openai.beta.assistants.create( |
| 142 | + model="gpt-4-turbo", |
| 143 | + name="Planner", |
| 144 | + instructions="You are a planner of complex tasks.", |
| 145 | + ) |
| 146 | + planner_oai_thread = openai.beta.threads.create() |
| 147 | + planner = OpenAIAssistantAgent( |
| 148 | + name="Planner", |
| 149 | + description="A planner that organizes and schedules tasks.", |
| 150 | + runtime=runtime, |
| 151 | + client=openai.AsyncClient(), |
| 152 | + assistant_id=planner_oai_assistant.id, |
| 153 | + thread_id=planner_oai_thread.id, |
| 154 | + ) |
| 155 | + |
| 156 | + orchestrator_oai_assistant = openai.beta.assistants.create( |
| 157 | + model="gpt-4-turbo", |
| 158 | + name="Orchestrator", |
| 159 | + instructions="You are an orchestrator that coordinates the team to complete a complex task.", |
| 160 | + ) |
| 161 | + orchestrator_oai_thread = openai.beta.threads.create() |
| 162 | + orchestrator = OpenAIAssistantAgent( |
| 163 | + name="Orchestrator", |
| 164 | + description="An orchestrator that coordinates the team.", |
| 165 | + runtime=runtime, |
| 166 | + client=openai.AsyncClient(), |
| 167 | + assistant_id=orchestrator_oai_assistant.id, |
| 168 | + thread_id=orchestrator_oai_thread.id, |
140 | 169 | )
|
141 | 170 |
|
142 |
| - response = runtime.send_message( |
143 |
| - TextMessage(content=message, source="customer"), |
144 |
| - chat, |
| 171 | + chat = OrchestratorChat( |
| 172 | + "Orchestrator Chat", |
| 173 | + "A software development team.", |
| 174 | + runtime, |
| 175 | + orchestrator=orchestrator, |
| 176 | + planner=planner, |
| 177 | + specialists=[developer, product_manager], |
145 | 178 | )
|
146 | 179 |
|
| 180 | + response = runtime.send_message(TextMessage(content=message, source="Customer"), chat) |
| 181 | + |
147 | 182 | while not response.done():
|
148 | 183 | await runtime.process_next()
|
149 | 184 |
|
|
0 commit comments