You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_userproxy.py 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """This example demonstrates a human user interacting with a coder agent
  2. which uses a model to generate code snippets. The user and the coder agent
  3. takes turn to write input or generate code snippets, orchestrated by an
  4. round-robin orchestrator agent.
  5. The code snippets are not executed in this example."""
  6. import asyncio
  7. import logging
  8. from autogen_core.application import SingleThreadedAgentRuntime
  9. from autogen_core.application.logging import EVENT_LOGGER_NAME
  10. from autogen_core.base import AgentId, AgentProxy
  11. # from typing import Any, Dict, List, Tuple, Union
  12. from autogen_magentic_one.agents.coder import Coder
  13. from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
  14. from autogen_magentic_one.agents.user_proxy import UserProxy
  15. from autogen_magentic_one.messages import RequestReplyMessage
  16. from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env
  17. async def main() -> None:
  18. # Create the runtime.
  19. runtime = SingleThreadedAgentRuntime()
  20. # Get an appropriate client
  21. client = create_completion_client_from_env()
  22. # Register agents.
  23. await Coder.register(runtime, "Coder", lambda: Coder(model_client=client))
  24. coder = AgentProxy(AgentId("Coder", "default"), runtime)
  25. await UserProxy.register(runtime, "UserProxy", lambda: UserProxy())
  26. user_proxy = AgentProxy(AgentId("UserProxy", "default"), runtime)
  27. await RoundRobinOrchestrator.register(runtime, "orchestrator", lambda: RoundRobinOrchestrator([coder, user_proxy]))
  28. runtime.start()
  29. await runtime.send_message(RequestReplyMessage(), user_proxy.id)
  30. await runtime.stop_when_idle()
  31. if __name__ == "__main__":
  32. logger = logging.getLogger(EVENT_LOGGER_NAME)
  33. logger.setLevel(logging.INFO)
  34. log_handler = LogHandler()
  35. logger.handlers = [log_handler]
  36. asyncio.run(main())