### Install yfinance and statsmodels Source: https://github.com/microsoft/taskweaver/blob/main/README.md Install the yfinance and statsmodels packages for financial forecasting examples. ```bash pip install yfinance pip install statsmodels ``` -------------------------------- ### Install and Run TaskWeaver Web UI Source: https://context7.com/microsoft/taskweaver/llms.txt Instructions for installing the Chainlit library and starting the TaskWeaver web-based UI for interactive conversations and visualizations. ```bash # Install Chainlit pip install chainlit # Start the web UI cd TaskWeaver/playground/UI chainlit run app.py # The UI will be available at http://localhost:8000 ``` -------------------------------- ### Start vLLM Server with Guided Decoding Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/local_llm.md Use this command to start the vLLM OpenAI compatible API server with guided decoding enabled via lm-format-enforcer. This is crucial for enforcing output formats from the LLM. ```shell python -m vllm.entrypoints.openai.api_server --model meta-llama/Meta-Llama-3-8B-Instruct --guided-decoding-backend lm-format-enforcer ``` -------------------------------- ### Install Dependencies Source: https://github.com/microsoft/taskweaver/blob/main/website/README.md Run this command to install all required project dependencies. ```bash $ yarn ``` -------------------------------- ### Install Dashscope Package Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/qwen.md Install the required dashscope library to enable QWen support. ```bash pip install dashscope ``` -------------------------------- ### Install Groq package Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/groq.md Install the necessary Python package to enable Groq support. ```bash pip install groq ``` -------------------------------- ### Install TaskWeaver Source: https://github.com/microsoft/taskweaver/blob/main/README.md Commands to clone the repository and install required Python dependencies. ```bash # [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 ``` ```bash pip install git+https://github.com/microsoft/TaskWeaver@ ``` -------------------------------- ### Launch the Web UI service Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/webui.md Navigate to the UI directory and start the Chainlit application. ```bash # assume you are in the TaskWeaver folder cd playground/UI/ # make sure you are in playground/UI/ folder chainlit run app.py ``` -------------------------------- ### Start Local Development Server Source: https://github.com/microsoft/taskweaver/blob/main/website/README.md Launches a local development server with live reloading enabled. ```bash $ yarn start ``` -------------------------------- ### Install Ollama and Serve LLMs Locally Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/ollama.md Use these bash commands to install Ollama on Linux/WSL2 and start serving LLM models. Ensure you have Ollama installed and a model served before configuring TaskWeaver. ```bash ## Install ollama on Linux & WSL2 curl https://ollama.ai/install.sh | sh ## Run the serving ollama serve ``` ```bash ollama run llama2:13b ``` -------------------------------- ### Install Zhipu AI SDK Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/glm.md Install the required Python package to interface with Zhipu AI services. ```bash pip install zhipuai ``` -------------------------------- ### Install Azure Identity Dependencies Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/aoai.md Install the required package for Entra authentication. ```bash pip install azure-identity ``` -------------------------------- ### Install Langchain and Tabulate Source: https://github.com/microsoft/taskweaver/blob/main/README.md Install the Langchain and tabulate packages required for the SQL pull data plugin. ```bash pip install langchain pip install tabulate ``` -------------------------------- ### Example Usage of TaskWeaverApp Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/concepts/app.md Demonstrates creating a TaskWeaverApp instance, getting a session, sending a message, and stopping the app. Ensure to call app.stop() before exiting. ```python from taskweaver.app.app import TaskWeaverApp app = TaskWeaverApp(app_dir="path/to/project/") session = app.get_session() round = session.send_message("Hello, how can I help you?") print(round) app.stop() ``` -------------------------------- ### Planner Conversation Example with Attachments Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/example/example.md A complex example demonstrating how the Planner communicates with the CodeInterpreter using plan-related attachments. ```yaml enabled: True rounds: - User_query: count the rows of /home/data.csv state: created post_list: - message: count the rows of /home/data.csv send_from: User send_to: Planner attachment_list: - message: Please load the data file /home/data.csv and count the rows of the loaded data send_from: Planner send_to: CodeInterpreter attachment_list: - type: init_plan content: |- 1. load the data file 2. count the rows of the loaded data 3. report the result to the User - type: plan content: |- 1. instruct CodeInterpreter to load the data file and count the rows of the loaded data 2. report the result to the User - type: current_plan_step content: 1. instruct CodeInterpreter to load the data file and count the rows of the loaded data - message: Load the data file /home/data.csv successfully and there are 100 rows in the data file send_from: CodeInterpreter send_to: Planner attachment_list: - message: The data file /home/data.csv is loaded and there are 100 rows in the data file send_from: Planner send_to: User attachment_list: - type: init_plan content: |- 1. load the data file 2. count the rows of the loaded data 3. report the result to the User - type: plan content: |- 1. instruct CodeInterpreter to load the data file and count the rows of the loaded data 2. report the result to the User - type: current_plan_step content: 2. report the result to the User ``` -------------------------------- ### Planner Reasoning Output Example Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/reasoning.md Demonstrates the Planner's output format when incorporating reasoning steps before generating an initial plan. ```commandline Human ▶ predict msft's stock price in the next 7 days ╭───< Planner > ├─► [plan_reasoning] The user wants to predict Microsoft's stock price for the next 7 days. This task involves time series forecasting, which requires historical stock price data and a forecasting model. However, the user hasn't provided any data or specified a model to use. I need to ask the user for more information. ├─► [init_plan] │ 1. Request historical stock price data from the user │ 2. Ask the user to specify a forecasting model or confirm if a default model should be used │ 3. Load the historical stock price data │ 4. Train the forecasting model using the historical data ``` -------------------------------- ### Install Langchain Source: https://github.com/microsoft/taskweaver/blob/main/project/plugins/README.md Install the Langchain library using pip. This is a prerequisite for plugins like paper_summary and sql_pull_data. ```bash pip install langchain ``` -------------------------------- ### Plugin Execution Example Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/plugin/how_to_develop_a_new_plugin.md A sample conversation log demonstrating how the plugin is invoked and executed by the CodeInterpreter. ```bash ========================================================= _____ _ _ __ |_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____ | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/ | | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ / |_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/ ========================================================= TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request? Human: render ABC in ascii art >>> [INIT_PLAN] 1. Render the text 'ABC' into ASCII art >>> [PLAN] 1. Instruct CodeInterpreter to render the text 'ABC' into ASCII art >>> [CURRENT_PLAN_STEP] 1. Instruct CodeInterpreter to render the text 'ABC' into ASCII art >>> [SEND_TO] CodeInterpreter >>> [MESSAGE] Please render the text 'ABC' into ASCII art >>> [PLANNER->CODEINTERPRETER] Please render the text 'ABC' into ASCII art >>> [PYTHON] # Call the plugin function to render the text 'ABC' into ASCII art ascii_art_result = ascii_render("ABC") ascii_art_result >>> [VERIFICATION] NONE >>> [STATUS] SUCCESS >>> [RESULT] The execution of the generated python code above has succeeded The result of above Python code after execution is: ___ ___ ___ /\ \ /\ \ /\ \ /::\ \ /::\ \ /::\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \ /::\~\:\ \ /::\~\:\__\ /:/ \:\ \ /:/\:\ \:\__\ /:/\:\ \:|__| /:/__/ \:\__\ \/__\:\/:/ / \:\~\:\/:/ / \:\ \ \/__/ \::/ / \:\ \::/ / \:\ \ /:/ / \:\/:/ / \:\ \ /:/ / \::/__/ \:\__\ \/__/ ~~ \/__/ >>> [CODEINTERPRETER->PLANNER] The following python code has been executed: ``` -------------------------------- ### Start TaskWeaver CLI Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/quickstart.md Command to launch the TaskWeaver process and the expected CLI output. ```bash # assume you are in the TaskWeaver folder cloned from the repository python -m taskweaver -p ./project/ # -p is the path to the project directory ``` ```bash ========================================================= _____ _ _ __ |_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____ | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/ | | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ / |_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/ ========================================================= TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request? Human: ___ ``` -------------------------------- ### Initialize TaskWeaver Session Source: https://context7.com/microsoft/taskweaver/llms.txt Basic setup to initialize the TaskWeaver application and start a session with an event handler. ```python app = TaskWeaverApp(app_dir="./project/") session = app.get_session() # Pass event handler to send_message response = session.send_message( "Generate 10 random numbers", event_handler=DetailedEventHandler() ) ``` -------------------------------- ### Launch TaskWeaver Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/cmd.md Starts the TaskWeaver process using the specified project directory. ```bash # assume you are in the TaskWeaver folder python -m taskweaver -p ./project/ # -p is the path to the project directory ``` -------------------------------- ### Example Handcrafted Experience Content Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/experience/handcrafted_experience.md This is an example of the `experience_text` content, written in Markdown format, specifying rules for the agent. ```yaml exp_id: 1 experience_text: |- - Say "world" if you hear "hello". - Say "peace" if you hear "love". ``` -------------------------------- ### Basic Conversation Example Structure Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/example/example.md A minimal example showing the structure of a conversation round between a User and a Planner. ```yaml enabled: True rounds: - User_query: ping state: created post_list: - message: ping send_from: User send_to: Planner attachment_list: [] - message: pong send_from: Planner send_to: User attachment_list: [] ``` -------------------------------- ### Start Tracing Infrastructure Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/telemetry.md Use Docker Compose to launch the local OpenTelemetry collector, Jaeger, and Prometheus services. ```bash cd /TaskWeaver/tracing docker-compose up ``` -------------------------------- ### Start TaskWeaver CLI Source: https://github.com/microsoft/taskweaver/blob/main/README.md Command to launch the TaskWeaver process using a project directory. ```bash # assume you are in the cloned TaskWeaver folder python -m taskweaver -p ./project/ ``` -------------------------------- ### Add Custom Packages to Dockerfile Source: https://context7.com/microsoft/taskweaver/llms.txt Example Dockerfile snippet demonstrating how to install additional Python packages for use within the TaskWeaver execution container. ```dockerfile # docker/ces_container/Dockerfile - Add custom packages FROM python:3.10-slim # ... existing content ... # Install additional packages for your plugins RUN pip install --no-cache-dir --user sentence-transformers RUN pip install --no-cache-dir --user scikit-learn RUN pip install --no-cache-dir --user yfinance ``` -------------------------------- ### Install LiteLLM Proxy Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/liteLLM.md Install the LiteLLM package with proxy support. Ensure necessary environment variables for your chosen LLM are set, such as COHERE_API_KEY for Cohere. ```bash pip install litellm[proxy] ``` -------------------------------- ### Task Decomposition and Tracking Example Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/reasoning.md Displays the structure of a task plan, including initial plan steps, current plan, and the active step being executed. ```commandline ├─► [init_plan] │ 1. Request historical stock price data for MSFT from the user │ 2. Request the forecasting model or method to be used for prediction │ 3. Perform the prediction using the provided data and model │ 4. Report the prediction results to the user ├─► [plan] │ 1. Request historical stock price data for MSFT from the user │ 2. Request the forecasting model or method to be used for prediction │ 3. Perform the prediction using the provided data and model │ 4. Report the prediction results to the user ├─► [current_plan_step] 1. Request historical stock price data for MSFT from the user ``` -------------------------------- ### Update Code Interpreter Example Schema Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/local_llm.md Examples showing the transition from deprecated attachment types to the new schema format. ```yaml - type: python content: |- file_path = "/abc/def.txt" with open(file_path, "r") as file: file_contents = file.read() print(file_contents) ``` ```yaml - type: reply_type content: python # or 'text' if the old type is 'text' or 'sample' - type: reply_content content: |- file_path = "/abc/def.txt" with open(file_path, "r") as file: file_contents = file.read() print(file_contents) ``` -------------------------------- ### Install Chainlit dependency Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/webui.md Install the required version of Chainlit to ensure compatibility with the Web UI. ```bash pip install -U "chainlit<1.1.300" ``` -------------------------------- ### Verify Plugin Registration in Planner Prompt Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/FAQ.md Example of the plugin registration section found in the planner prompt logs to confirm if a plugin is correctly loaded. ```markdown CodeInterpreter has the following plugin functions and their required parameters need to be provided before the execution: - anomaly_detection: anomaly_detection function identifies anomalies from an input DataFrame of time series. It will add a new column "Is_Anomaly", where each entry will be marked with "True" if the value is an anomaly or "False" otherwise. Arguments required: df: DataFrame, time_col_name: str, value_col_name: str - ascii_render: This plugin renders the input text into ASCII art form. Arguments required: text: str - klarna_search: Search and compare prices from thousands of online shops. Only available in the US. This plugin only takes user requests when searching for merchandise. If not clear, confirm with the user if they want to search for merchandise from Klarna. Arguments required: query: str - tell_joke: Call this plugin to tell a joke. ``` -------------------------------- ### Run TaskWeaver Container Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/docker.md Execute this command to start a TaskWeaver container. Replace placeholders with your LLM API details. ```bash docker run -it -e LLM_API_BASE= \ -e LLM_API_KEY= \ -e LLM_API_TYPE= \ -e LLM_MODEL= \ taskweavercontainers/taskweaver-all-in-one:latest ``` -------------------------------- ### Install agentops package Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/observability.md Install the agentops package using pip. This is the first step to integrate AgentOps with your project. ```bash pip install agentops ``` -------------------------------- ### Start TaskWeaver CLI Source: https://context7.com/microsoft/taskweaver/llms.txt Initiates the TaskWeaver CLI with a specified project directory. Provides an overview of available commands for interactive sessions. ```bash # Start TaskWeaver CLI with default project directory python -m taskweaver -p ./project/ # Example CLI session output: # ========================================================= # _____ _ _ __ # |_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____ # | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/ # | | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ / # |_|\__,_|___/_|\_\|__/|__/ # ========================================================= # TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request? # Human: ___ ``` ```bash # Available CLI commands: # /help - Show help message # /load - Load a file by absolute path # /info - Show current session information # /reset - Reset session and start fresh # /clear - Clear console output # /save - Save chat history for experience extraction # /exit - Exit the application # Example: Load and analyze a CSV file # Human: /load /home/user/data/sales.csv # Human: Calculate the average sales per month and detect any anomalies ``` -------------------------------- ### SQL Query Generation Example Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/reasoning.md SQL query generated by the Planner during the task execution. ```sql SELECT EmployeeID, Department, ProjectCode, Role, Manager, Location FROM EmployeeRecords WHERE EmployeeID = 'E12345' AND Department = 'Development' AND ProjectCode = 'X987' AND Role = 'Software Engineer' AND Manager = 'J. Doe' AND Location = 'Remote' ORDER BY EmployeeID; ``` -------------------------------- ### TaskWeaver Recepta Reasoning Output Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/reasoning.md Example output showing the interaction between the Planner and the Recepta role during a multi-step task. ```commandline ╭───< Planner > ├─► [plan_reasoning] The user has provided a set of instructions to follow step by step. The task involves extracting employee data from a summary, validating the role, and constructing an SQL query. I will follow these steps sequentially. ├─► [init_plan] │ 1. Extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` │ 2. Validate the role │ 3. Construct and print the SQL query using the extracted details │ 4. Check the execution result and report the result to the user ├─► [plan] │ 1. Extract information from the employee summary │ 2. Validate the role │ 3. Construct SQL query using the extracted details │ 4. Report the result to the user ├─► [current_plan_step] 1. Extract information from the employee summary ├─► [stop] InProcess ├──● Thought: I can read and comprehend the employee summary to extract the required information. │ Result: the `Employee ID` is `E12345`, the `Department` is `Development`, the `Project Code` is `X987`, the `Role` is `Software Engineer`, the `Manager` is `J. Doe`, and the `Location` is `Remote`. ├─► [shared_memory_entry] Add the plan to the shared memory ╰──● sending message to Recepta ╭───< Recepta > ├──● Got it. Now, please go ahead! ╰──● sending message to Planner ╭───< Planner > ├─► [plan_reasoning] I have extracted the information from the employee summary. The next step is to verify if the role is one of the recognized roles. ├─► [init_plan] │ 1. Extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` │ 2. Validate the role │ 3. Construct and print the SQL query using the extracted details │ 4. Check the execution result and report the result to the user ├─► [plan] │ 1. Extract information from the employee summary │ 2. Validate the role │ 3. Construct SQL query using the extracted details │ 4. Report the result to the user ├─► [current_plan_step] 2. Validate the role ├─► [stop] InProcess ├──● Thought: I can verify if the role is one of the recognized roles with my pattern matching capability. │ Thought: The recognized roles are `Software Engineer, Data Analyst, Project Manager, DevOps Specialist, QA Tester`. │ Result: The role is `Software Engineer`, which is recognized. ├─► [shared_memory_entry] Add the plan to the shared memory ╰──● sending message to Recepta ╭───< Recepta > ├──● Got it. Now, please go ahead! ╰──● sending message to Planner ╭───< Planner > ├─► [plan_reasoning] I can prepare and print the SQL query using the extracted details to the User. ├─► [init_plan] │ 1. Extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` │ 2. Validate the role │ 3. Construct and print the SQL query using the extracted details │ 4. Check the execution result and report the result to the user ├─► [plan] │ 1. Extract information from the employee summary │ 2. Validate the role │ 3. Construct SQL query using the extracted details │ 4. Report the result to the user ├─► [current_plan_step] 3. Construct and print the SQL query using the extracted details and report the result to the user ├─► [stop] Completed ├──● The role is `Software Engineer`, which is recognized. │ │ Here is the SQL query using the extracted details: │ ```sql │ SELECT EmployeeID, Department, ProjectCode, Role, Manager, Location │ FROM EmployeeRecords │ WHERE EmployeeID = 'E12345' │ AND Department = 'Development' │ AND ProjectCode = 'X987' │ AND Role = 'Software Engineer' │ AND Manager = 'J. Doe' │ AND Location = 'Remote' │ ORDER BY EmployeeID; │ ``` ├─► [shared_memory_entry] Add the plan to the shared memory ╰──● sending message to User TaskWeaver ▶ The role is `Software Engineer`, which is recognized. ``` -------------------------------- ### Run TaskWeaver with Project Directory Mount Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/docker.md Mount your local project directory into the container to use custom configurations, plugins, and examples. ```bash docker run -it -e LLM_API_BASE= \ -e LLM_API_KEY= \ -e LLM_API_TYPE= \ -e LLM_MODEL= \ # -e TASKWEAVER_UID=$(id -u) \ # uncomment if your host OS is not Windows # -e TASKWEAVER_GID=$(id -g) \ # uncomment if your host OS is not Windows --mount type=bind,source=,target=/app/TaskWeaver/project/ \ taskweavercontainers/taskweaver-all-in-one:latest ``` -------------------------------- ### Run LiteLLM Proxy Server Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/liteLLM.md Start the LiteLLM proxy server. Use the `--drop_params` argument for API compatibility. The server will be accessible at http://0.0.0.0:8000. ```bash litellm --model MODEL_NAME --drop_params ``` -------------------------------- ### No-Planner Mode Execution Example Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/configurations/configurations_in_detail.md Demonstrates a direct interaction with the CodeInterpreter in no-planner mode, showing the input request and the resulting Python code execution output. ```bash ========================================================= _____ _ _ __ |_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____ | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/ | | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ / |_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/ ========================================================= TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request? Human: generate 10 random numbers >>> [PYTHON]Starting... import numpy as np random_numbers = np.random.rand(10) random_numbers >>> [VERIFICATION] NONE >>> [STATUS]Starting... SUCCESS >>> [RESULT] The execution of the generated python code above has succeeded The result of above Python code after execution is: array([0.09918602, 0.68732778, 0.44413814, 0.4756623 , 0.48302334, 0.8286594 , 0.80994359, 0.35677263, 0.45719317, 0.68240194]) >>> [CODEINTERPRETER->PLANNER] The following python code has been executed: ```python import numpy as np random_numbers = np.random.rand(10) random_numbers ``` The execution of the generated python code above has succeeded The result of above Python code after execution is: array([0.09918602, 0.68732778, 0.44413814, 0.4756623 , 0.48302334, 0.8286594 , 0.80994359, 0.35677263, 0.45719317, 0.68240194]) TaskWeaver: The following python code has been executed: ```python import numpy as np random_numbers = np.random.rand(10) random_numbers ``` The execution of the generated python code above has succeeded The result of above Python code after execution is: array([0.09918602, 0.68732778, 0.44413814, 0.4756623 , 0.48302334, 0.8286594 , 0.80994359, 0.35677263, 0.45719317, 0.68240194]) ``` -------------------------------- ### Docker Compose Infrastructure Setup Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/telemetry.md Defines the services for the OpenTelemetry collector, Jaeger, and Prometheus. ```yaml version: '3' services: optl-collector: image: otel/opentelemetry-collector:0.96.0 command: ["--config=/etc/collector-config.yaml"] volumes: - ./collector-config.yaml:/etc/collector-config.yaml ports: - "4317:4317" # Expose the gRPC receiver port for the collector depends_on: - jaeger jaeger: image: jaegertracing/all-in-one:1.54 ports: - "16686:16686" # Jaeger UI prometheus: image: prom/prometheus:latest ports: - "9090:9090" # Prometheus UI volumes: - ./prometheus-config.yml:/etc/prometheus/prometheus.yml command: ["--config.file=/etc/prometheus/prometheus.yml"] depends_on: - optl-collector ``` -------------------------------- ### Initialize TaskWeaverApp Source: https://context7.com/microsoft/taskweaver/llms.txt Initialize TaskWeaverApp with a project directory or inline configuration. Get a session, send a message, and stop the app when done. ```python from taskweaver.app.app import TaskWeaverApp # Initialize TaskWeaver with a project directory app_dir = "./project/" # Directory containing taskweaver_config.json app = TaskWeaverApp(app_dir=app_dir) # Alternative: Initialize with inline configuration app = TaskWeaverApp( app_dir="./project/", config={ "llm.api_key": "your-api-key", "llm.model": "gpt-4", "llm.api_type": "openai" } ) # Get a new session for conversation session = app.get_session() # Send a message and get response response_round = session.send_message("What can you do?") # Access the response print(response_round.to_dict()) # Output: { # "id": "round-20231201-043134-218a2681", # "user_query": "What can you do?", # "state": "finished", # "post_list": [...] # } # Stop the app when done (must be called before exit) session.stop() app.stop() ``` -------------------------------- ### Verify Plugin Availability via LLM Response Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/FAQ.md Example of the expected LLM response when querying TaskWeaver for available capabilities. ```markdown I can assist you with various tasks, including: - Detecting anomalies in time series data. - Rendering text into ASCII art. - Searching and comparing prices from thousands of online shops (US only). - Telling a joke. If you have a specific task in mind, please let me know, and I'll do my best to assist you. ``` -------------------------------- ### Load Local File in TaskWeaver CLI Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/docker.md Example of loading a local file (e.g., example.csv) into TaskWeaver using the `/load` command within the CLI. ```bash TaskWeaver ▶ I am TaskWeaver, an AI assistant. To get started, could you please enter your request? Human ▶ /load /app/TaskWeaver/local/example.csv Human ▶ display the column names of the loaded file ``` -------------------------------- ### Start TaskWeaver with Auto Plugin Selection Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/plugin_selection.md Initiates TaskWeaver with the auto plugin selection feature enabled. This is the initial step to observe the mechanism in action. ```bash ========================================================= _____ _ _ __ |_ _|_ _ ___| | _ | | / / | |/ _` / __| |/ /| | /| / / _ | | (_| |_| ========================================================= TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please enter your request? Human: ``` -------------------------------- ### Identify YAML loading errors Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/FAQ.md Example of the error message displayed in logs when a plugin's YAML configuration file fails to load. ```bash failed to loading component from .yaml, skipping: Yaml loading failed due to: ``` -------------------------------- ### Example Plugin Usage in TaskWeaver Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/plugin/plugin_intro.md This simplified code demonstrates how TaskWeaver might call two plugins: `sql_pull_data` to fetch data and `anomaly_detection` to process it. ```python df, data_description = sql_pull_data(query="pull data from time_series table") anomaly_df, anomaly_description = anomaly_detection(df, time_col_name="ts", value_col_name="val") ``` -------------------------------- ### Test LLM API Integration Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/llms/customized_llm_api.md After configuring `taskweaver_config.json`, navigate to the `./scripts` directory and run the test command to verify your LLM API setup. ```bash cd ./scripts ``` -------------------------------- ### Call a plugin in plugin-only mode Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/plugin_only.md Example of the restricted code format that only invokes a plugin. ```python r1=ascii_render(**{"text":"Hello"}) r1 ``` -------------------------------- ### Import agentops package Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/observability.md Import the agentops package into your Python project to start using its functionalities. ```python import agentops ``` -------------------------------- ### Configure Planner Experience Directory Source: https://github.com/microsoft/taskweaver/blob/main/website/blog/experience.md Use this JSON configuration to enable and set a custom experience directory for the Planner role. Ensure the `planner.use_experience` is set to true. ```json { "planner.use_experience": true, "planner.experience_dir": "planner_exp_dir" } ``` -------------------------------- ### Get Session Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/concepts/app.md Retrieves an existing session by its ID or creates a new one if no ID is provided. ```APIDOC ## Get Session ### Description Retrieves a session associated with the TaskWeaver app. If a `session_id` is provided, it returns the corresponding session. Otherwise, it creates and returns a new session. ### Method get_session ### Endpoint N/A (This is a method of the TaskWeaverApp class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **session_id** (Optional[str]) - The ID of the session to retrieve. If `None`, a new session is created. ### Request Example ```python # Assuming 'app' is an instance of TaskWeaverApp session = app.get_session(session_id="existing_session_123") # Or to create a new session: session = app.get_session() ``` ### Response #### Success Response (200) - **Session** (Session) - The retrieved or newly created session object. ``` -------------------------------- ### TaskWeaver Configuration with Custom Role Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/concepts/role.md Example of the taskweaver_config.json file enabling the 'echo' role alongside default roles. ```json { "session.roles": ["planner", "echo", "code_interpreter"] } ``` -------------------------------- ### Prepare DA-Bench Test Cases Source: https://github.com/microsoft/taskweaver/blob/main/auto_eval/dabench_scripts/README.md Use this script to generate test cases for the DA-Bench benchmark. Ensure you provide the correct paths for the questions file, label file, data folder, and the desired output directory. ```bash cd auto_eval/dabench_scripts python prepare_cases.py ``` -------------------------------- ### Example DA-Bench Test Case Prompt Source: https://github.com/microsoft/taskweaver/blob/main/auto_eval/dabench_scripts/README.md This markdown illustrates the structure of a test case prompt, including the task, question, constraints, and the expected output format. Adhere to this format when creating or interpreting test cases. ```markdown # Task Load the file test_ave.csv and answer the following questions. # Question Calculate the mean fare paid by the passengers. # Constraints Calculate the mean fare using Python's built-in statistics module or appropriate statistical method in pandas. Rounding off the answer to two decimal places. # Format @mean_fare[mean_fare_value] where "mean_fare_value" is a floating-point number rounded to two decimal places. ``` -------------------------------- ### Initialize TaskWeaverApp Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/concepts/app.md Initialize the TaskWeaver app with optional project directory, local URI preference, and configuration settings. ```python class TaskWeaverApp(object): def __init__( self, app_dir: Optional[str] = None, use_local_uri: Optional[bool] = None, config: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> None: """ Initialize the TaskWeaver app. :param app_dir: The project directory. :param use_local_uri: Whether to use local URI for artifacts. :param config: The configuration. :param kwargs: The additional arguments. """ ``` -------------------------------- ### Get Session from TaskWeaverApp Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/concepts/app.md Retrieve a session from the TaskWeaver app. A new session is created if no session ID is provided. ```python def get_session( self, session_id: Optional[str] = None, ) -> Session: """ Get the session. Return a new session if the session ID is not provided. :param session_id: The session ID. :return: The session. """ ``` -------------------------------- ### Example Docker network inspection output Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/code_execution.md Shows the expected JSON output when inspecting a Docker network to identify its subnet. ```json "Config": [ { "Subnet": "172.19.0.0/16", "Gateway": "172.19.0.1" } ] ``` -------------------------------- ### Run TaskWeaver with Local Directory Mount Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/docker.md Mount a local directory to access files within the container at `/app/TaskWeaver/local/`. Use the `/load` command to access them. ```bash docker run -it -e LLM_API_BASE= \ -e LLM_API_KEY= \ -e LLM_API_TYPE= \ -e LLM_MODEL= \ # -e TASKWEAVER_UID=$(id -u) \ # uncomment if your host OS is not Windows # -e TASKWEAVER_GID=$(id -g) \ # uncomment if your host OS is not Windows --mount type=bind,source=,target=/app/TaskWeaver/local/ \ taskweavercontainers/taskweaver-all-in-one:latest ``` -------------------------------- ### Initialize TaskWeaver and Send Messages Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/library.md Use TaskWeaverApp to create a session and send user queries. The app_dir must point to the directory containing taskweaver_config.json. ```python from taskweaver.app.app import TaskWeaverApp # This is the folder that contains the taskweaver_config.json file and not the repo root. Defaults to "./project/" app_dir = "./project/" app = TaskWeaverApp(app_dir=app_dir) session = app.get_session() user_query = "hello, what can you do?" response_round = session.send_message(user_query) print(response_round.to_dict()) ``` -------------------------------- ### Build Document Index via CLI Source: https://github.com/microsoft/taskweaver/blob/main/taskweaver/ext_role/document_retriever/README.md Execute the document indexer script to process documentation files into a searchable index. ```bash cd TaskWeaver python script/document_indexer.py \ --doc_paths website/docs website/blog \ --output_path project/sample_data/knowledge_base \ --extensions md ``` -------------------------------- ### Round Object Structure Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/usage/library.md Example of the JSON structure returned by a session round, containing the user query, state, and a list of posts. ```json { "id": "round-20231201-043134-218a2681", "user_query": "hello, what can you do?", "state": "finished", "post_list": [ { "id": "post-20231201-043134-10eedcca", "message": "hello, what can you do?", "send_from": "User", "send_to": "Planner", "attachment_list": [] }, { "id": "post-20231201-043141-86a2aaff", "message": "I can help you with various tasks, such as counting rows in a data file, detecting anomalies in a dataset, searching for products on Klarna, summarizing research papers, and pulling data from a SQL database. Please provide more information about the task you want to accomplish, and I'll guide you through the process.", "send_from": "Planner", "send_to": "User", "attachment_list": [ { "id": "atta-20231201-043141-6bc4da86", "type": "init_plan", "content": "1. list the available functions" }, { "id": "atta-20231201-043141-6f29f6c9", "type": "plan", "content": "1. list the available functions" }, { "id": "atta-20231201-043141-76186c7a", "type": "current_plan_step", "content": "1. list the available functions" } ] } ] } ``` -------------------------------- ### Example of Potentially Dangerous Generated Code Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/verification.md This snippet demonstrates code that reads and executes an external file, which is a target for verification rules. ```python import os file = open("abc.py", "r") code = file.read() exec(code) ``` -------------------------------- ### Build Static Content Source: https://github.com/microsoft/taskweaver/blob/main/website/README.md Compiles the website into static files located in the build directory. ```bash $ yarn build ``` -------------------------------- ### TaskWeaver Log Output - Plugin Initialization Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/advanced/plugin_selection.md Shows log entries indicating successful initialization of the Planner and the generation of plugin embeddings, confirming the auto plugin selector is ready. ```log 2023-12-18 14:23:44,197 - INFO - Planner initialized successfully 2023-12-18 14:24:10,488 - INFO - Plugin embeddings generated 2023-12-18 14:24:10,490 - INFO - CodeInterpreter initialized successfully. 2023-12-18 14:24:10,490 - INFO - Session 20231218-062343-c18494b1 is initialized ``` -------------------------------- ### Define an Anomaly Detection Plugin Schema Source: https://github.com/microsoft/taskweaver/blob/main/website/docs/customization/plugin/plugin_intro.md Example of a complete YAML schema for an anomaly detection plugin, including parameters and return values. ```yaml name: anomaly_detection enabled: true plugin_only: false required: false description: >- anomaly_detection function identifies anomalies from an input DataFrame of time series. It will add a new column "Is_Anomaly", where each entry will be marked with "True" if the value is an anomaly or "False" otherwise. parameters: - name: df type: DataFrame required: true description: >- the input data from which we can identify the anomalies with the 3-sigma algorithm. - name: time_col_name type: str required: true description: name of the column that contains the datetime - name: value_col_name type: str required: true description: name of the column that contains the numeric values. returns: - name: df type: DataFrame description: >- This DataFrame extends the input DataFrame with a newly-added column "Is_Anomaly" containing the anomaly detection result. - name: description type: str description: This is a string describing the anomaly detection results. ```