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.

README.md 5.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Examples
  2. This directory contains examples and demos of how to use AGNext.
  3. - `common`: Contains common implementations and utilities used by the examples.
  4. - `core`: Contains examples that illustrate the core concepts of AGNext.
  5. - `tool-use`: Contains examples that illustrate tool use in AGNext.
  6. - `patterns`: Contains examples that illustrate how multi-agent patterns can be implemented in AGNext.
  7. - `demos`: Contains interactive demos that showcase applications that can be built using AGNext.
  8. See [Running the examples](#running-the-examples) for instructions on how to run the examples.
  9. ## Core examples
  10. We provide examples to illustrate the core concepts of AGNext: agents, runtime, and message passing.
  11. - [`one_agent_direct.py`](core/one_agent_direct.py): A simple example of how to create a single agent powered by ChatCompletion model client. Communicate with the agent using direct communication.
  12. - [`inner_outer_direct.py`](core/inner_outer_direct.py): A simple example of how to create an agent that calls an inner agent using direct communication.
  13. - [`two_agents_pub_sub.py`](core/two_agents_pub_sub.py): An example of how to create two agents that communicate using broadcast communication (i.e., pub/sub).
  14. ## Tool use examples
  15. We provide examples to illustrate how to use tools in AGNext:
  16. - [`coding_direct.py`](tool-use/coding_direct.py): a code execution example with one agent that calls and executes tools to demonstrate tool use and reflection on tool use. This example uses direct communication.
  17. - [`coding_pub_sub.py`](tool-use/coding_pub_sub.py): a code execution example with two agents, one for calling tool and one for executing the tool, to demonstrate tool use and reflection on tool use. This example uses broadcast communication.
  18. - [`custom_tool_direct.py`](tool-use/custom_tool_direct.py): a custom function tool example with one agent that calls and executes tools to demonstrate tool use and reflection on tool use. This example uses direct communication.
  19. - [`coding_direct_with_intercept.py`](tool-use/coding_direct_with_intercept.py): an example showing human-in-the-loop for approving or denying tool execution.
  20. ## Pattern examples
  21. We provide examples to illustrate how multi-agent patterns can be implemented in AGNext:
  22. - [`coder_executor.py`](patterns/coder_executor.py): An example of how to create a coder-executor reflection pattern. This example creates a plot of stock prices using the Yahoo Finance API.
  23. - [`coder_reviewer.py`](patterns/coder_reviewer.py): An example of how to create a coder-reviewer reflection pattern.
  24. - [`group_chat.py`](patterns/group_chat.py): An example of how to create a round-robin group chat among three agents.
  25. - [`mixture_of_agents.py`](patterns/mixture_of_agents.py): An example of how to create a [mixture of agents](https://github.com/togethercomputer/moa).
  26. - [`multi_agent_debate.py`](patterns/multi_agent_debate.py): An example of how to create a [sparse multi-agent debate](https://arxiv.org/abs/2406.11776) pattern.
  27. ## Demos
  28. We provide interactive demos that showcase applications that can be built using AGNext:
  29. - [`assistant.py`](demos/assistant.py): a demonstration of how to use the OpenAI Assistant API to create
  30. a ChatGPT agent.
  31. - [`chat_room.py`](demos/chat_room.py): An example of how to create a chat room of custom agents without
  32. a centralized orchestrator.
  33. - [`illustrator_critics.py`](demos/illustrator_critics.py): a demo that uses an illustrator, critics and descriptor agent
  34. to implement the reflection pattern for image generation.
  35. - [`software_consultancy.py`](demos/software_consultancy.py): a demonstration of multi-agent interaction using
  36. the group chat pattern.
  37. - [`chest_game.py`](demos/chess_game.py): an example with two chess player agents that executes its own tools to demonstrate tool use and reflection on tool use.
  38. ## Bring Your Own Agent
  39. We provide examples on how to integrate other agents with the platform:
  40. - [`llamaindex_agent.py`](byoa/llamaindex_agent.py): An example that shows how to consume a LlamaIndex agent.
  41. - [`langgraph_agent.py`](byoa/langgraph_agent.py): An example that shows how to consume a LangGraph agent.
  42. ## Running the examples
  43. ### Prerequisites
  44. First, you need a shell with AGNext and required dependencies installed.
  45. To do this, in the samples directory, run:
  46. ```bash
  47. hatch shell
  48. ```
  49. ### Using Azure OpenAI API
  50. For Azure OpenAI API, you need to set the following environment variables:
  51. ```bash
  52. export OPENAI_API_TYPE=azure
  53. export AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
  54. export AZURE_OPENAI_API_VERSION=your_azure_openai_api_version
  55. ```
  56. By default, we use Azure Active Directory (AAD) for authentication.
  57. You need to run `az login` first to authenticate with Azure.
  58. You can also
  59. use API key authentication by setting the following environment variables:
  60. ```bash
  61. export AZURE_OPENAI_API_KEY=your_azure_openai_api_key
  62. ```
  63. ### Using OpenAI API
  64. For OpenAI API, you need to set the following environment variables.
  65. ```bash
  66. export OPENAI_API_TYPE=openai
  67. export OPENAI_API_KEY=your_openai_api_key
  68. ```
  69. ### Running
  70. To run an example, just run the corresponding Python script. For example:
  71. ```bash
  72. hatch shell
  73. python core/one_agent_direct.py
  74. ```
  75. Or simply:
  76. ```bash
  77. hatch run python core/one_agent_direct.py
  78. ```