> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentops.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TaskWeaver

> First class support for Microsoft TaskWeaver

[TaskWeaver](https://microsoft.github.io/TaskWeaver/) is a code-first agent framework for seamlessly planning and executing data analytics tasks. Explore TaskWeaver's comprehensive [documentation](https://microsoft.github.io/TaskWeaver/docs/overview) for more information.

## Steps to integrate TaskWeaver with AgentOps

**1. Install the AgentOps SDK**

```bash pip  theme={null}
pip install agentops
```

```bash poetry theme={null}
poetry add agentops
```

**2. Install TaskWeaver and configure your project directory**

Follow the instructions on the TaskWeaver [Quick Start](https://microsoft.github.io/TaskWeaver/docs/quickstart) section in the documentation.

**3. Import the TaskWeaver handler from AgentOps and initialize the AgentOps client**

AgentOps uses the TaskWeaver handler to handle its events. Additionally, AgentOps tracks the LLM calls made by TaskWeaver via its inbuilt module. These are used together to observe everything in the TaskWeaver session.

> [!NOTE]
>
> TaskWeaver provides different [usage options](https://microsoft.github.io/TaskWeaver/docs/usage). By default, it's used as a CLI app via the `taskweaver` command but can also be used as a library.

```python python theme={null}
import agentops
from agentops.partners.taskweaver_event_handler import TaskWeaverEventHandler
from taskweaver.app.app import TaskWeaverApp

agentops.init(<INSERT YOUR API KEY HERE>)

# Your TaskWeaver code here

agentops.end_session("Success")
```

> [!TIP]
>
> Set your API key as an `.env` variable for easy access.

```python .env theme={null}
AGENTOPS_API_KEY=<YOUR API KEY>
```

Read more about environment variables in [Advanced Configuration](https://docs.agentops.ai/v1/usage/advanced-configuration.md)

**4. Run your Agent**

Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your TaskWeaver Agent! 🕵️

> [!TIP]
>
> After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard

![](https://github.com/AgentOps-AI/agentops/blob/main/docs/images/external/microsoft/taskweaver_session.png?raw=true)

Clickable link to session

## Full Examples

This is a basic example of how to use TaskWeaver as a library and observe it with AgentOps.

Ensure you have configured your project directory in the TaskWeaverApp by following the documentation mentioned in step 2.

> [!WARNING]
>
> When registering the TaskWeaverEventHandler, you should either use the `session.event_emitter.register` method or pass the handler object to the `event_handler` parameter in the `send_message` method. If you use both, the events will be recorded twice, resulting in a "stuttering" effect in the recorded messages.

```python python theme={null}
import agentops

from taskweaver.app.app import TaskWeaverApp
from agentops.partners.taskweaver_event_handler import TaskWeaverEventHandler

agentops.init(<INSERT YOUR API KEY HERE>)

app_dir = "<path to your configured project directory>"
app = TaskWeaverApp(app_dir=app_dir)
session = app.get_session()
handler = TaskWeaverEventHandler()
session.event_emitter.register(handler)

user_query = "Hello, what are the capabilities of TaskWeaver?"
response_round = session.send_message(user_query)

user_query = "Write me a simple calculator program in python"
response_round = session.send_message(user_query)

agentops.end_session("Success")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.