2024-09-18 17:16:54 -07:00
|
|
|
"""This example demonstrates a human user interacting with a file surfer agent
|
|
|
|
to navigate the file system. The human user and the file surfer agent takes turn
|
|
|
|
to write input or perform actions, orchestrated by an round-robin orchestrator agent."""
|
|
|
|
|
2024-06-25 14:27:45 -07:00
|
|
|
import asyncio
|
2025-01-08 09:33:28 -05:00
|
|
|
import json
|
2024-07-09 13:51:05 -07:00
|
|
|
import logging
|
2025-01-08 09:33:28 -05:00
|
|
|
import os
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-12-06 01:59:28 -08:00
|
|
|
from autogen_core import EVENT_LOGGER_NAME, AgentId, AgentProxy, SingleThreadedAgentRuntime
|
2025-01-08 09:33:28 -05:00
|
|
|
from autogen_core.models._model_client import ChatCompletionClient
|
2024-10-01 15:59:03 -07:00
|
|
|
from autogen_magentic_one.agents.file_surfer import FileSurfer
|
|
|
|
from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
|
|
|
|
from autogen_magentic_one.agents.user_proxy import UserProxy
|
|
|
|
from autogen_magentic_one.messages import RequestReplyMessage
|
2025-01-08 09:33:28 -05:00
|
|
|
from autogen_magentic_one.utils import LogHandler
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def main() -> None:
|
|
|
|
# Create the runtime.
|
|
|
|
runtime = SingleThreadedAgentRuntime()
|
|
|
|
|
2024-07-09 13:51:05 -07:00
|
|
|
# Get an appropriate client
|
2025-01-08 09:33:28 -05:00
|
|
|
client = ChatCompletionClient.load_component(json.loads(os.environ["CHAT_COMPLETION_CLIENT_CONFIG"]))
|
2024-07-09 13:51:05 -07:00
|
|
|
|
2024-06-25 14:27:45 -07:00
|
|
|
# Register agents.
|
2024-09-19 14:10:41 -04:00
|
|
|
await FileSurfer.register(runtime, "file_surfer", lambda: FileSurfer(model_client=client))
|
2024-08-20 14:41:24 -04:00
|
|
|
file_surfer = AgentProxy(AgentId("file_surfer", "default"), runtime)
|
|
|
|
|
2024-09-19 14:10:41 -04:00
|
|
|
await UserProxy.register(runtime, "UserProxy", lambda: UserProxy())
|
2024-08-20 14:41:24 -04:00
|
|
|
user_proxy = AgentProxy(AgentId("UserProxy", "default"), runtime)
|
2024-07-01 11:53:45 -04:00
|
|
|
|
2024-09-19 14:10:41 -04:00
|
|
|
await RoundRobinOrchestrator.register(
|
|
|
|
runtime, "orchestrator", lambda: RoundRobinOrchestrator([file_surfer, user_proxy])
|
2024-08-27 12:03:21 -07:00
|
|
|
)
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-08-21 13:59:59 -07:00
|
|
|
runtime.start()
|
2024-07-09 13:51:05 -07:00
|
|
|
await runtime.send_message(RequestReplyMessage(), user_proxy.id)
|
2024-08-21 13:59:59 -07:00
|
|
|
await runtime.stop_when_idle()
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-07-09 13:51:05 -07:00
|
|
|
logger = logging.getLogger(EVENT_LOGGER_NAME)
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
log_handler = LogHandler()
|
|
|
|
logger.handlers = [log_handler]
|
2024-06-25 14:27:45 -07:00
|
|
|
asyncio.run(main())
|