|
|
|
@@ -28,7 +28,7 @@ import datetime |
|
|
|
import json |
|
|
|
from concurrent.futures import ThreadPoolExecutor |
|
|
|
from dataclasses import dataclass |
|
|
|
from typing import Any, Mapping, Optional |
|
|
|
from typing import Any, Dict, Mapping, Optional |
|
|
|
|
|
|
|
from autogen_core import ( |
|
|
|
CancellationToken, |
|
|
|
@@ -50,11 +50,10 @@ from autogen_core.models import ( |
|
|
|
) |
|
|
|
from autogen_core.tools import BaseTool |
|
|
|
from pydantic import BaseModel, Field |
|
|
|
from utils import get_chat_completion_client_from_envs |
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
|
class TextMessage(BaseModel): |
|
|
|
class TextMessage: |
|
|
|
source: str |
|
|
|
content: str |
|
|
|
|
|
|
|
@@ -113,7 +112,7 @@ class SlowUserProxyAgent(RoutedAgent): |
|
|
|
|
|
|
|
async def save_state(self) -> Mapping[str, Any]: |
|
|
|
state_to_save = { |
|
|
|
"memory": self._model_context.save_state(), |
|
|
|
"memory": await self._model_context.save_state(), |
|
|
|
} |
|
|
|
return state_to_save |
|
|
|
|
|
|
|
@@ -251,7 +250,7 @@ class TerminationHandler(DefaultInterventionHandler): |
|
|
|
return self.terminateMessage.content |
|
|
|
|
|
|
|
|
|
|
|
async def main(latest_user_input: Optional[str] = None) -> None | str: |
|
|
|
async def main(model_config: Dict[str, Any], latest_user_input: Optional[str] = None) -> None | str: |
|
|
|
""" |
|
|
|
Asynchronous function that serves as the entry point of the program. |
|
|
|
This function initializes the necessary components for the program and registers the user and scheduling assistant agents. |
|
|
|
@@ -268,6 +267,8 @@ async def main(latest_user_input: Optional[str] = None) -> None | str: |
|
|
|
""" |
|
|
|
global state_persister |
|
|
|
|
|
|
|
model_client = ChatCompletionClient.load_component(model_config) |
|
|
|
|
|
|
|
termination_handler = TerminationHandler() |
|
|
|
needs_user_input_handler = NeedsUserInputHandler() |
|
|
|
runtime = SingleThreadedAgentRuntime(intervention_handlers=[needs_user_input_handler, termination_handler]) |
|
|
|
@@ -283,11 +284,12 @@ async def main(latest_user_input: Optional[str] = None) -> None | str: |
|
|
|
lambda: SchedulingAssistantAgent( |
|
|
|
"SchedulingAssistant", |
|
|
|
description="AI that helps you schedule meetings", |
|
|
|
model_client=get_chat_completion_client_from_envs(model="gpt-4o-mini"), |
|
|
|
model_client=model_client, |
|
|
|
initial_message=initial_schedule_assistant_message, |
|
|
|
), |
|
|
|
) |
|
|
|
|
|
|
|
runtime_initiation_message: UserTextMessage | AssistantTextMessage |
|
|
|
if latest_user_input is not None: |
|
|
|
runtime_initiation_message = UserTextMessage(content=latest_user_input, source="User") |
|
|
|
else: |
|
|
|
@@ -330,6 +332,9 @@ if __name__ == "__main__": |
|
|
|
# if os.path.exists("state.json"): |
|
|
|
# os.remove("state.json") |
|
|
|
|
|
|
|
with open("model_config.json") as f: |
|
|
|
model_config = json.load(f) |
|
|
|
|
|
|
|
def get_user_input(question_for_user: str): |
|
|
|
print("--------------------------QUESTION_FOR_USER--------------------------") |
|
|
|
print(question_for_user) |
|
|
|
@@ -342,7 +347,7 @@ if __name__ == "__main__": |
|
|
|
user_input = get_user_input(question_for_user) |
|
|
|
else: |
|
|
|
user_input = None |
|
|
|
user_input_needed = await main(user_input) |
|
|
|
user_input_needed = await main(model_config, user_input) |
|
|
|
if user_input_needed: |
|
|
|
await run_main(user_input_needed) |
|
|
|
|
|
|
|
|