TaskWeaver Documentation

repository·main·Indexed 27 days ago

https://github.com/microsoft/taskweaver

TaskWeaver is a code-first agent framework for planning and executing data analytics tasks. It uses LLMs to interpret requests into code snippets and coordinates plugins for stateful data processing. The framework includes an auto-evaluation system supporting DA-Bench and DS-1000 benchmarks, as well as specialized plugins like sql_pull_data, paper_summary, and klarna_search.

Tokens
35.3K
Snippets
104
Records
182
Agent score
91%

What's inside TaskWeaver

  1. Overview of available plugins

    main

    TaskWeaver supports several specialized plugins:

    • klarna_search: Calls the Klarna API to search for products.
    • paper_summary: Uses Langchain to load and summarize PDF files (requires langchain installation).
    • sql_pull_data: Uses Langchain and a GPT model to convert natural language queries into SQL to pull data from SQLite databases (requires langchain installation and configuration in sql_pull_data.yaml).
  2. Overview of TaskWeaver

    main

    TaskWeaver is a code-first agent framework designed for planning and executing data analytics tasks. It interprets user requests by generating and executing Python code snippets, coordinating various plugins (Python functions) to automate workflows or perform data analysis.

    Key capabilities include:

    • Rich Data Support: Works with Python structures like Lists, Dictionaries, and Pandas DataFrames.
    • Customizable Algorithms: Encapsulate custom logic into plugins.
    • Stateful Conversation: Maintains data in memory across multiple chat rounds.
    • Code Verification & Security: Verifies generated code before execution and supports sandboxed environments for security.
    • Observability: Uses OpenTelemetry for detailed logs, metrics, and traces to facilitate debugging.
  3. Understand the TaskWeaver plugin lifecycle

    main

    The plugin lifecycle follows these stages:

    1. Loading: When TaskWeaver starts, it reads all YAML configuration files in the plugins directory and creates entries in memory. The Python code is NOT loaded yet.
    2. Initialization: When the agent executes code that calls a plugin for the first time in a session, the plugin is loaded and initialized with the configurations specified in its YAML file.
    3. Execution: The plugin is called by the agent. Because plugins are stored in the Jupyter kernel memory, they can maintain state across different code cells and calls within the same session.
    4. Destruction: Plugin objects are destroyed when the session (and its associated Jupyter kernel) is closed.

    Note: All enabled plugins are loaded into memory at startup, regardless of whether they are used in the current conversation. You can control loading by setting enabled: false in the YAML file.

  4. Understand the Experience workflow

    main

    The Experience feature follows this lifecycle:

    1. Enable: Set planner.use_experience and code_generator.use_experience to true.
    2. Capture: Use /save in the chat interface to store a session as raw_exp_{session_id}.yaml.
    3. Summarize: On restart, TaskWeaver generates exp_{session_id}.yaml containing extracted tips and preferences.
    4. Retrieve: When a user sends a similar query, TaskWeaver retrieves relevant experiences and injects them into the system prompts for the Planner and CodeInterpreter to prevent repeating past mistakes.
  5. Understand the TaskWeaver project directory structure

    main

    A TaskWeaver project is a directory created by the user that stores configuration, plugins, logs, and workspace data. A TaskWeaverApp instance is associated with this folder.

    Key components include:

    • taskweaver_config.json: The primary configuration file for the project.
    • plugins/: Directory for storing custom plugins.
    • logs/: Directory for program logs (generated automatically).
    • examples/: Contains planner_examples and code_generator_examples.
    • workspace/: Stores session data, including the Code Execution Service (CES) folder and the Current Working Directory (CWD) folder (generated automatically).

    Important for Local Mode: When running in local mode, the workspace/<session_id>/cwd folder acts as the base directory for loading files from your local file system. Any files generated by code execution will be stored within this CWD folder.

    📦project
     ┣ 📜taskweaver_config.json # the project configuration file for TaskWeaver
     ┣ 📂plugins # the folder to store plugins
     ┣ 📂logs # the folder to store logs, will be generated after program starts
     ┣ 📂examples
        ┣ 📂planner_examples # the folder to store planner examples
        ┗ 📂code_generator_examples # the folder to store code generator examples
     ┗ 📂workspace # the directory stores session data, will be generated after program starts
        ┗ 📂 session_id 
          ┣ 📂ces # the folder used by the code execution service
          ┣ 📂cwd # the current working directory to run the generated code
          ┗ other session data
  6. Understand the TaskWeaver conversational evaluation method

    main

    TaskWeaver uses a conversational evaluation method that treats the LLM agent as a conversational partner rather than a simple function. This method involves two roles:

    1. Examiner: Receives the task description, asks questions to the agent, and supervises the conversation. The Examiner can only provide the task description and cannot provide hints or solutions.
    2. Judge: Receives the chat history and the final solution from the Examiner to evaluate the performance against ground truth.

    This approach allows for multi-turn interactions (e.g., an agent asking for clarification) and more nuanced scoring than simple keyword matching.

  7. Understand TaskWeaver Memory concepts

    main

    TaskWeaver's memory module manages conversation context through two primary mechanisms:

    1. Role-wise Conversation History: Each role (e.g., Planner, Code Interpreter) maintains its own independent history of Posts sent or received by itself. This allows roles to prepare LLM prompts based on their specific expertise without needing to know about other roles.
    2. Shared Memory: A mechanism to share information between roles (e.g., the Planner sharing a guide from a Data Scientist with a Code Interpreter) or to store control states (e.g., a task 'type') accessible to all roles.

    Key building blocks include Round and Post objects.

  8. Understand the Post data concept

    main

    In TaskWeaver, a Post is the fundamental data unit used for communication between roles (such as User, Planner, or others) within a conversation. Each Post represents a single message and contains a text message and an optional attachment_list for non-text data like code snippets or file paths.

    @dataclass
    class Post:
        id: str
        send_from: RoleName
        send_to: RoleName
        message: str
        attachment_list: List[Attachment]
  9. Understand the Conversation concept

    main

    In TaskWeaver, a Conversation represents the dialog between a user and the TaskWeaver app. Each session has a corresponding conversation. A conversation consists of:

    • Rounds: A collection of Round objects, where each round starts with user input and ends with a TaskWeaver response.
    • Plugins: A list of PluginEntry objects available during the conversation.
    • Roles: The specific roles associated with the conversation.
    • Examples: Conversations are used to store and load examples from the project folder. These examples are parsed into memory and injected into the prompts for the Planner or CodeInterpreter to improve performance.
  10. Understand the Round data concept

    main

    In TaskWeaver, a Round is the fundamental unit of conversation. It represents a single exchange between a user and the TaskWeaver application. A Round consists of the user's initial query, a collection of Post objects representing the dialogue, and a lifecycle state.

    Round Attributes

    • id: A unique identifier for the round.
    • user_query: The original query submitted by the user.
    • post_list: A list of Post objects contained within the round.
    • state: The current lifecycle status of the round.
    @dataclass
    class Round:
        id: str
        user_query: str
        state: RoundState
        post_list: List[Post]
  11. Understand TaskWeaver reasoning techniques

    main

    TaskWeaver utilizes several reasoning techniques to drive agent intelligence:

    1. Task Decomposition and Tracking: The agent breaks complex tasks into subtasks and tracks progress via init_plan, plan, and current_plan_step. This prevents the agent from losing track of complex, multi-step goals.
    2. ReAct-like Reasoning: TaskWeaver uses multiple roles, specifically a Planner and a CodeInterpreter, to solve problems. The Planner creates plans, and the CodeInterpreter executes code. The Planner can reflect on the CodeInterpreter's results to adjust future steps.
    3. Chain-of-Thought (CoT): While not implemented for the Planner by default to save prompt size and complexity, CoT is implemented within the CodeInterpreter (visible in the [thought] field) to guide code generation.