2024-07-03 17:13:24 -07:00
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# from typing import Any, Dict, List, Tuple, Union
|
|
|
|
from agnext.application import SingleThreadedAgentRuntime
|
|
|
|
from agnext.application.logging import EVENT_LOGGER_NAME
|
2024-08-20 14:41:24 -04:00
|
|
|
from agnext.core import AgentId, AgentProxy
|
2024-07-03 17:13:24 -07:00
|
|
|
from team_one.agents.coder import Coder
|
|
|
|
from team_one.agents.orchestrator import RoundRobinOrchestrator
|
|
|
|
from team_one.agents.user_proxy import UserProxy
|
2024-07-09 13:51:05 -07:00
|
|
|
from team_one.messages import RequestReplyMessage
|
|
|
|
from team_one.utils import LogHandler, create_completion_client_from_env
|
2024-07-03 17:13:24 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def main() -> None:
|
|
|
|
# Create the runtime.
|
|
|
|
runtime = SingleThreadedAgentRuntime()
|
|
|
|
|
2024-07-09 10:46:55 -07:00
|
|
|
# Get an appropriate client
|
|
|
|
client = create_completion_client_from_env()
|
2024-07-03 17:13:24 -07:00
|
|
|
|
|
|
|
# Register agents.
|
2024-08-20 14:41:24 -04:00
|
|
|
await runtime.register(
|
2024-07-03 17:13:24 -07:00
|
|
|
"Coder",
|
|
|
|
lambda: Coder(model_client=client),
|
|
|
|
)
|
2024-08-20 14:41:24 -04:00
|
|
|
coder = AgentProxy(AgentId("Coder", "default"), runtime)
|
|
|
|
|
|
|
|
await runtime.register(
|
2024-07-03 17:13:24 -07:00
|
|
|
"UserProxy",
|
|
|
|
lambda: UserProxy(),
|
|
|
|
)
|
2024-08-20 14:41:24 -04:00
|
|
|
user_proxy = AgentProxy(AgentId("UserProxy", "default"), runtime)
|
2024-07-03 17:13:24 -07:00
|
|
|
|
2024-07-23 11:49:38 -07:00
|
|
|
await runtime.register("orchestrator", lambda: RoundRobinOrchestrator([coder, user_proxy]))
|
2024-07-03 17:13:24 -07:00
|
|
|
|
|
|
|
run_context = runtime.start()
|
|
|
|
await runtime.send_message(RequestReplyMessage(), user_proxy.id)
|
|
|
|
await run_context.stop_when_idle()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
logger = logging.getLogger(EVENT_LOGGER_NAME)
|
|
|
|
logger.setLevel(logging.INFO)
|
2024-07-09 13:51:05 -07:00
|
|
|
log_handler = LogHandler()
|
|
|
|
logger.handlers = [log_handler]
|
2024-07-03 17:13:24 -07:00
|
|
|
asyncio.run(main())
|