Home

Awesome

<h1 align="center"> <img src="./.asset/logo.color.svg" width="45" /> TaskWeaver </h1> <div align="center">

Discord Follow   Python Version  License: MIT  Welcome

</div>

TaskWeaver is A code-first agent framework for seamlessly planning and executing data analytics tasks. This innovative framework interprets user requests through code snippets and efficiently coordinates a variety of plugins in the form of functions to execute data analytics tasks in a stateful manner.

Unlike many agent frameworks that only track the chat history with LLMs in text, TaskWeaver preserves both the chat history and the code execution history, including the in-memory data. This feature enhances the expressiveness of the agent framework, making it ideal for processing complex data structures like high-dimensional tabular data.

<h1 align="center"> <img src="./.asset/taskweaver_arch.png"/> </h1>

πŸ†• News

<!-- - πŸ“…2024-02-01: TaskWeaver now has a plugin [document_retriever](https://github.com/microsoft/TaskWeaver/blob/main/project/plugins/README.md#document_retriever) for RAG based on a knowledge base.πŸ“š --> <!-- - πŸ“…2024-01-30: TaskWeaver introduces a new plugin-only mode that securely generates calls to specified plugins without producing extraneous code.πŸͺ‘ --> <!-- - πŸ“…2024-01-23: TaskWeaver can now be personalized by transforming your chat histories into enduring [experiences](https://microsoft.github.io/TaskWeaver/docs/customization/experience) πŸŽ‰ --> <!-- - πŸ“…2024-01-17: TaskWeaver now has a plugin [vision_web_explorer](https://github.com/microsoft/TaskWeaver/blob/main/project/plugins/README.md#vision_web_explorer) that can open a web browser and explore websites.🌐 --> <!-- - πŸ“…2024-01-15: TaskWeaver now supports Streamingβ™’ in both UI and command line.✌️ --> <!-- - πŸ“…2024-01-01: Welcome join TaskWeaver [Discord](https://discord.gg/Z56MXmZgMb). --> <!-- - πŸ“…2023-12-21: TaskWeaver now supports a number of LLMs, such as LiteLLM, Ollama, Gemini, and QWen🎈.) --> <!-- - πŸ“…2023-12-21: TaskWeaver Website is now [available]&#40;https://microsoft.github.io/TaskWeaver/&#41; with more documentations.) --> <!-- - πŸ“…2023-12-12: A simple UI demo is available in playground/UI folder, try it [here](https://microsoft.github.io/TaskWeaver/docs/usage/webui)! --> <!-- - πŸ“…2023-11-30: TaskWeaver is released on GitHub🎈. -->

πŸ’₯ Highlights

✨ Quick Start

πŸ› οΈ Step 1: Installation

TaskWeaver requires Python >= 3.10. It can be installed by running the following command:

# [optional to create conda environment]
# conda create -n taskweaver python=3.10
# conda activate taskweaver

# clone the repository
git clone https://github.com/microsoft/TaskWeaver.git
cd TaskWeaver
# install the requirements
pip install -r requirements.txt

If you want to install an earlier version of TaskWeaver, you may check the release page, find the tag (e.g., v0.0.1) and install it by

pip install git+https://github.com/microsoft/TaskWeaver@<TAG>

πŸ–ŠοΈ Step 2: Configure the LLMs

Before running TaskWeaver, you need to provide your LLM configurations. Taking OpenAI as an example, you can configure taskweaver_config.json file as follows.

OpenAI

{
  "llm.api_key": "the api key",
  "llm.model": "the model name, e.g., gpt-4"
}

πŸ’‘ TaskWeaver also supports other LLMs and advanced configurations, please check the documents for more details.

🚩 Step 3: Start TaskWeaver

πŸ’‘ TaskWeaver has switched to container mode by default for code execution, which means the code is run in a container. You may need to install Docker and take care of the dependencies in the container. Please check the code execution for more details.

⌨️ Command Line (CLI)

# assume you are in the cloned TaskWeaver folder
python -m taskweaver -p ./project/

This will start the TaskWeaver process and you can interact with it through the command line interface. If everything goes well, you will see the following prompt:

=========================================================
 _____         _     _       __
|_   _|_ _ ___| | _ | |     / /__  ____ __   _____  _____
  | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/
  | | (_| \__ \   < | |/ |/ /  __/ /_/ /| |/ /  __/ /
  |_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/
=========================================================
TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request?
Human: ___

or πŸ’» Web UI

TaskWeaver also supports WebUI for demo purpose, please refer to web UI docs for more details.

or πŸ“‹ Import as a Library

TaskWeaver can be imported as a library to integrate with your existing project, more information can be found in docs

πŸ“– Documentation

More documentations can be found on TaskWeaver Website.

❓Get help


🎬 Demo Examples

The demos were made based on the web UI, which is better for displaying the generated artifacts such as images. The demos could also be conducted in the command line interface.

1οΈβƒ£πŸ“‰ Example 1: Pull data from a database and apply an anomaly detection algorithm

In this example, we will show you how to use TaskWeaver to pull data from a database and apply an anomaly detection algorithm.

Anomaly Detection

If you want to follow this example, you need to configure the sql_pull_data plugin in the project/plugins/sql_pull_data.yaml file. You need to provide the following information:

api_type: azure or openai
api_base: ...
api_key: ...
api_version: ...
deployment_name: ...
sqlite_db_path: sqlite:///../../../sample_data/anomaly_detection.db

The sql_pull_data plugin is a plugin that pulls data from a database. It takes a natural language request as input and returns a DataFrame as output.

This plugin is implemented based on Langchain. If you want to follow this example, you need to install the Langchain package:

pip install langchain
pip install tabulate

2οΈβƒ£πŸ¦ Example 2: Forecast QQQ's price in the next 7 days

In this example, we will show you how to use TaskWeaver to forecast QQQ's price in the next 7 days.

Nasdaq 100 Index Price Forecasting

If you want to follow this example, you need to ensure you have these two requirements installed:

pip install yfinance
pip install statsmodels

For more examples, please refer to our paper.

πŸ’‘ The planning of TaskWeaver are based on the LLM model. Therefore, if you want to repeat the examples, the execution process may be different from what you see in the videos. For example, in the second demo, the assistant may ask the user which prediction algorithm should be used. Typically, more concrete prompts will help the model to generate better plans and code.

πŸ“š Citation

Our paper could be found here. If you use TaskWeaver in your research, please cite our paper:

@article{taskweaver,
  title={TaskWeaver: A Code-First Agent Framework},
  author={Bo Qiao, Liqun Li, Xu Zhang, Shilin He, Yu Kang, Chaoyun Zhang, Fangkai Yang, Hang Dong, Jue Zhang, Lu Wang, Minghua Ma, Pu Zhao, Si Qin, Xiaoting Qin, Chao Du, Yong Xu, Qingwei Lin, Saravan Rajmohan, Dongmei Zhang},
  journal={arXiv preprint arXiv:2311.17541},
  year={2023}
}

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Disclaimer

The recommended models in this Repo are just examples, used to explore the potential of agent systems with the paper at TaskWeaver: A Code-First Agent Framework. Users can replace the models in this Repo according to their needs. When using the recommended models in this Repo, you need to comply with the licenses of these models respectively. Microsoft shall not be held liable for any infringement of third-party rights resulting from your usage of this repo. Users agree to defend, indemnify and hold Microsoft harmless from and against all damages, costs, and attorneys' fees in connection with any claims arising from this Repo. If anyone believes that this Repo infringes on your rights, please notify the project owner email.