update conversation pattern

This commit is contained in:
Qingyun Wu 2023-09-02 21:58:13 -04:00
parent 65c14e2332
commit 2a69be7fe3
5 changed files with 19 additions and 75 deletions

View File

@ -7,11 +7,10 @@ This project welcomes and encourages all forms of contributions, including but n
- Code review of pull requests.
- Documentation, examples and test cases.
- Readability improvement, e.g., improvement on docstr and comments.
- Community participation in [issues](https://github.com/microsoft/autogen/issues), [discussions](https://github.com/microsoft/autogen/discussions), and [discord](discord).
- Community participation in [issues](https://github.com/microsoft/autogen/issues), [discussions](https://github.com/microsoft/autogen/discussions), and discord.
- Tutorials, blog posts, talks that promote the project.
- Sharing application scenarios and/or related research.
You can take a look at the [Roadmap for Upcoming Features](https://github.com/microsoft/autogen/wiki/Roadmap-for-Upcoming-Features) to identify potential things to work on.
Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
@ -58,67 +57,8 @@ There is currently no formal reviewer solicitation process. Current reviewers id
## Developing
### Setup
```bash
git clone https://github.com/microsoft/autogen.git
pip install -e autogen
```
<!-- In case the `pip install` command fails, try escaping the brackets such as `pip install -e autogen`. -->
### Docker
We provide a simple [Dockerfile](https://github.com/microsoft/flaml/blob/main/Dockerfile).
```bash
docker build https://github.com/microsoft/autogen.git#main -t autogen-dev
docker run -it autogen-dev
```
### Develop in Remote Container
If you use vscode, you can open the autogen folder in a [Container](https://code.visualstudio.com/docs/remote/containers).
We have provided the configuration in [devcontainer](https://github.com/microsoft/flaml/blob/main/.devcontainer).
### Pre-commit
Run `pre-commit install` to install pre-commit into your git hooks. Before you commit, run
`pre-commit run` to check if you meet the pre-commit requirements. If you use Windows (without WSL) and can't commit after installing pre-commit, you can run `pre-commit uninstall` to uninstall the hook. In WSL or Linux this is supposed to work.
### Coverage
Any code you commit should not decrease coverage. To run all unit tests, install the [test] option under autogen/:
```bash
pip install -e."[test]"
coverage run -m pytest test
```
Then you can see the coverage report by
`coverage report -m` or `coverage html`.
### Documentation
To build and test documentation locally, install [Node.js](https://nodejs.org/en/download/). For example,
```bash
nvm install --lts
```
Then:
```console
npm install --global yarn # skip if you use the dev container we provided
pip install pydoc-markdown==4.5.0 # skip if you use the dev container we provided
cd website
yarn install --frozen-lockfile --ignore-engines
pydoc-markdown
yarn start
```
The last command starts a local development server and opens up a browser window.
Most changes are reflected live without having to restart the server.
Please find the a general developing guide for AutoGen in FLAML [here](https://microsoft.github.io/FLAML/docs/Contribute#developing).
Detailed guidence for developing with AutoGen will be added soon.
Note:
some tips in this guide are based off the contributor guide from [ray](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html), [scikit-learn](https://scikit-learn.org/stable/developers/contributing.html), [hummingbird](https://github.com/microsoft/hummingbird/blob/main/CONTRIBUTING.md), or [FLAML](https://microsoft.github.io/FLAML/docs/Contribute).

View File

@ -1,7 +1,7 @@
# AutoGen - Automated Multi Agent Chat
AutoGen offers conversable agents powered by LLM, tool or human, which can be used to perform tasks collectively via automated chat. This framwork allows tool use and human participance via multi-agent conversation.
Please find documentation about this feature [here](/docs/Use-Cases/Autogen#agents).
Please find documentation about this feature [here](/docs/Use-Cases/agent_chat).
Links to notebook examples:
* [Automated Task Solving with Code Generation, Execution & Debugging](https://github.com/microsoft/flaml/blob/main/notebook/autogen_agentchat_auto_feedback_from_code_execution.ipynb)

View File

@ -21,6 +21,7 @@ AutoGen is powered by collaborative [research studies](/docs/Research) from Micr
Install AutoGen from pip: `pip install "flaml[autogen]"`. Find more options in [Installation](/docs/Installation).
#### Multi-Agent Conversation Framework
Autogen enables the next-gen LLM applications with a generic multi-agent conversation framework. It offers customizable and conversable agents which integrate LLMs, tools and human.
By automating chat among multiple capable agents, one can easily make them collectively perform tasks autonomously or with human feedback, including tasks that require using tools via code. For example,
```python
@ -31,6 +32,8 @@ user_proxy.initiate_chat(assistant, message="Show me the YTD gain of 10 largest
# This initiates an automated chat between the two agents to solve the task
```
#### Enhanced LLM Inferences
Autogen also helps maximize the utility out of the expensive LLMs such as ChatGPT and GPT-4. It offers a drop-in replacement of `openai.Completion` or `openai.ChatCompletion` with powerful functionalites like tuning, caching, error handling, templating. For example, you can optimize generations by LLM with your own tuning data, success metrics and budgets.
```python
# perform tuning

View File

@ -22,9 +22,9 @@ The `ResponsiveAgent` by default can use LLMs, humans, and tools. The `Assistan
- The `AssistantAgent` is designed to act as an AI assistant, using LLMs by default but not requiring human input or code execution. It could write Python code (in a Python coding block) for a user to execute when a message (typically a description of a task that needs to be solved) is received. Under the hood, the Python code is written by LLM (e.g., GPT-4). It can also receive the execution results and suggest code with bug fix. Its behavior can be altered by passing a new system message. The LLM [inference](#enhanced-inference) configuration can be configured via `llm_config`.
- The `UserProxyAgent` is conceptually a proxy agent for humans, soliciting human input as the agent's reply at each interaction turn by default and also having the capability to execute code and call functions. The `UserProxyAgent` triggers code execution automatically when it detects an executable code block in the received message and no human user input is provided. Code execution can be disabled by setting `code_execution_config` to False. LLM-based response is disabled by default. It can be enabled by setting `llm_config` to a dict corresponding to the [inference](#enhanced-inference) configuration. When `llm_config` is set to a dict, `UserProxyAgent` can generate replies using an LLM when code execution is not performed. When `llm_config` is set to a dict, `UserProxyAgent` can generate replies using an LLM when code execution is not performed.
- The `UserProxyAgent` is conceptually a proxy agent for humans, soliciting human input as the agent's reply at each interaction turn by default and also having the capability to execute code and call functions. The `UserProxyAgent` triggers code execution automatically when it detects an executable code block in the received message and no human user input is provided. Code execution can be disabled by setting `code_execution_config` to False. LLM-based response is disabled by default. It can be enabled by setting `llm_config` to a dict corresponding to the [inference](/docs/Use-Cases/enhanced_inference) configuration. When `llm_config` is set to a dict, `UserProxyAgent` can generate replies using an LLM when code execution is not performed. When `llm_config` is set to a dict, `UserProxyAgent` can generate replies using an LLM when code execution is not performed.
In the following code, we construct two agents of the `AssistantAgent` and `UserProxyAgent` classes respectively. We will later employ these two agents to solve a task.
In the following code, we create an `AssistantAgent` named "assistant" to serve as the assistant and a `UserProxyAgent` named "user_proxy" to serve as a proxy for the human user. We will later employ these two agents to solve a task.
```python
from flaml.autogen import AssistantAgent, UserProxyAgent
@ -40,30 +40,31 @@ user_proxy = UserProxyAgent(name="user_proxy")
### A Basci Two-Agent Conversation Example
Example usage of the agents to solve a task with code:
Once the participating agents are constructed properly, one can start a multi-agent conversation session by an initialization step as shown in following code:
```python
# the assistant receives a message from the user, which contains the task description
user.initiate_chat(
user_proxy.initiate_chat(
assistant,
message="""What date is today? Which big tech stock has the largest year-to-date gain this year? How much is the gain?""",
)
```
In the example above, we create an AssistantAgent named "assistant" to serve as the assistant and a UserProxyAgent named "user_proxy" to serve as a proxy for the human user.
After the initialization step, the conversation could proceed automatically. Find a visual illustration of how the user_proxy and assistant collaboratively solve the above task autonmously below:
![Agent Chat Example](images/agent_example.png)
1. The assistant receives a message from the user_proxy, which contains the task description.
2. The assistant then tries to write Python code to solve the task and sends the response to the user_proxy.
3. Once the user_proxy receives a response from the assistant, it tries to reply by either soliciting human input or preparing an automatically generated reply. In this specific example, since `human_input_mode` is set to `"NEVER"`, the user_proxy will not solicit human input but send an automatically generated reply (auto reply). More specifically, the user_proxy executes the code and uses the result as the auto-reply.
3. Once the user_proxy receives a response from the assistant, it tries to reply by either soliciting human input or preparing an automatically generated reply. If no human input is provided, the user_proxy executes the code and uses the result as the auto-reply.
4. The assistant then generates a further response for the user_proxy. The user_proxy can then decide whether to terminate the conversation. If not, steps 3 and 4 are repeated.
Please find a visual illustration of how UserProxyAgent and AssistantAgent collaboratively solve the above task below:
![Agent Chat Example](images/agent_example.png)
### Supporting Diverse Conversation Patterns
#### Conversations with different autonomisity, and human involvement patterns
On the one hand, one can achieve fully autonomous conversations after an initialization step. On the other hand, AutoGen can be used to implement human-in-the-loop problem-solving by configuring human involvement levels and patterns (e.g., setting the `human_input_mode` to `ALWAYS`), as human involvement is expected and/or desired in many applications.
#### Static and dynamic conversations
Leveraging [function calling capability of OpenAI's Chat Completions API](https://openai.com/blog/function-calling-and-other-api-updates?ref=upstract.com), one can pass in a list of callable functions or class methods to `UserProxyAgent`, which corresponds to the description of functions passed to OpenAI's API.
By adopting the conversation-driven control with both programming language and natural language, AutoGen inherently allows dynamic conversation. Dynamic conversation allows the agent topology to change depending on the actual flow of conversation under different input problem instances, while the flow of a static conversation always follows a pre-defined topology. The dynamic conversation pattern is useful in complex applications where the patterns of interaction cannot be predetermined in advance. AutoGen provides two general approaches to achieving dynamic conversation:
- Registered auto-reply. With the pluggable auto-reply function, one can choose to invoke conversations with other agents depending on the content of the current message and context. A working system demonstrating this type of dynamic conversation can be found in this code example, demonstrating a [dynamic group chat](https://github.com/microsoft/flaml/blob/main/notebook/autogen_agentchat_groupchat.ipynb). In the system, we register an auto-reply function in the group chat manager, which lets LLM decide who will the next speaker be in a group chat setting.
- LLM-based function call. In this approach, LLM decides whether or not to call a particular function depending on the conversation status in each inference call.

View File

@ -111,7 +111,7 @@ The tuend config can be used to perform inference.
`autogen.Completion.create` is compatible with both `openai.Completion.create` and `openai.ChatCompletion.create`, and both OpenAI API and Azure OpenAI API. So models such as "text-davinci-003", "gpt-3.5-turbo" and "gpt-4" can share a common API.
When chat models are used and `prompt` is given as the input to `autogen.Completion.create`, the prompt will be automatically converted into `messages` to fit the chat completion API requirement. One advantage is that one can experiment with both chat and non-chat models for the same prompt in a unified API.
For local LLMs, one can spin up an endpoint using a package like [FastChat](https://github.com/lm-sys/FastChat), and then use the same API to send a request. See [here](/blog/2023/07/14/Local-LLMs) for examples on how to make inference with local LLMs.
For local LLMs, one can spin up an endpoint using a package like [FastChat](https://github.com/lm-sys/FastChat), and then use the same API to send a request. See [here](https://microsoft.github.io/FLAML/blog/2023/07/14/Local-LLMs) for examples on how to make inference with local LLMs.
When only working with the chat-based models, `autogen.ChatCompletion` can be used. It also does automatic conversion from prompt to messages, if prompt is provided instead of messages.