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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 import AgentId, AgentProxy, SingleThreadedAgentRuntime
  9. from autogen_core.application.logging import EVENT_LOGGER_NAME
  10. # from typing import Any, Dict, List, Tuple, Union
  11. from autogen_magentic_one.agents.coder import Coder
  12. from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
  13. from autogen_magentic_one.agents.user_proxy import UserProxy
  14. from autogen_magentic_one.messages import RequestReplyMessage
  15. from autogen_magentic_one.utils import LogHandler, create_completion_client_from_env
  16. async def main() -> None:
  17. # Create the runtime.
  18. runtime = SingleThreadedAgentRuntime()
  19. # Get an appropriate client
  20. client = create_completion_client_from_env()
  21. # Register agents.
  22. await Coder.register(runtime, "Coder", lambda: Coder(model_client=client))
  23. coder = AgentProxy(AgentId("Coder", "default"), runtime)
  24. await UserProxy.register(runtime, "UserProxy", lambda: UserProxy())
  25. user_proxy = AgentProxy(AgentId("UserProxy", "default"), runtime)
  26. await RoundRobinOrchestrator.register(runtime, "orchestrator", lambda: RoundRobinOrchestrator([coder, user_proxy]))
  27. runtime.start()
  28. await runtime.send_message(RequestReplyMessage(), user_proxy.id)
  29. await runtime.stop_when_idle()
  30. if __name__ == "__main__":
  31. logger = logging.getLogger(EVENT_LOGGER_NAME)
  32. logger.setLevel(logging.INFO)
  33. log_handler = LogHandler()
  34. logger.handlers = [log_handler]
  35. asyncio.run(main())