2024-06-25 14:27:45 -07:00
|
|
|
import asyncio
|
2024-07-09 13:51:05 -07:00
|
|
|
import logging
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-08-28 12:47:04 -04:00
|
|
|
from autogen_core.application import SingleThreadedAgentRuntime
|
|
|
|
from autogen_core.application.logging import EVENT_LOGGER_NAME
|
|
|
|
from autogen_core.base import AgentId, AgentProxy
|
|
|
|
from autogen_core.components import DefaultSubscription
|
2024-06-28 15:50:10 -07:00
|
|
|
from team_one.agents.coder import Coder, Executor
|
|
|
|
from team_one.agents.orchestrator import RoundRobinOrchestrator
|
2024-07-09 13:51:05 -07:00
|
|
|
from team_one.agents.user_proxy import UserProxy
|
|
|
|
from team_one.messages import RequestReplyMessage
|
|
|
|
from team_one.utils import LogHandler, create_completion_client_from_env
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def main() -> None:
|
|
|
|
# Create the runtime.
|
|
|
|
runtime = SingleThreadedAgentRuntime()
|
|
|
|
|
|
|
|
# Register agents.
|
2024-08-20 14:41:24 -04:00
|
|
|
await runtime.register(
|
2024-08-27 12:03:21 -07:00
|
|
|
"Coder", lambda: Coder(model_client=create_completion_client_from_env()), lambda: [DefaultSubscription()]
|
2024-06-25 14:27:45 -07:00
|
|
|
)
|
2024-08-20 14:41:24 -04:00
|
|
|
coder = AgentProxy(AgentId("Coder", "default"), runtime)
|
2024-07-09 13:51:05 -07:00
|
|
|
|
2024-08-27 12:03:21 -07:00
|
|
|
await runtime.register("Executor", lambda: Executor("A agent for executing code"), lambda: [DefaultSubscription()])
|
2024-08-20 14:41:24 -04:00
|
|
|
executor = AgentProxy(AgentId("Executor", "default"), runtime)
|
2024-06-28 15:50:10 -07:00
|
|
|
|
2024-08-20 14:41:24 -04:00
|
|
|
await runtime.register(
|
2024-07-09 13:51:05 -07:00
|
|
|
"UserProxy",
|
2024-08-20 14:41:24 -04:00
|
|
|
lambda: UserProxy(description="The current user interacting with you."),
|
2024-08-27 12:03:21 -07:00
|
|
|
lambda: [DefaultSubscription()],
|
2024-07-09 13:51:05 -07:00
|
|
|
)
|
2024-08-20 14:41:24 -04:00
|
|
|
user_proxy = AgentProxy(AgentId("UserProxy", "default"), runtime)
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-08-27 12:03:21 -07:00
|
|
|
await runtime.register(
|
|
|
|
"orchestrator", lambda: RoundRobinOrchestrator([coder, executor, user_proxy]), lambda: [DefaultSubscription()]
|
|
|
|
)
|
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())
|