TaskWeaver is a code-first agent framework for seamlessly planning and executing data analytics tasks. Explore TaskWeaver’s comprehensive documentation for more information.
Install TaskWeaver and configure your project directory
Follow the instructions on the TaskWeaver Quick Start 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.
TaskWeaver provides different usage options. By default, it’s used as a CLI app via the taskweaver command but can also be used as a library.
import agentopsfrom agentops.partners.taskweaver_event_handler import TaskWeaverEventHandlerfrom taskweaver.app.app import TaskWeaverAppagentops.init(<INSERT YOUR API KEY HERE>)# Your TaskWeaver code hereagentops.end_session("Success")
Set your API key as an .env variable for easy access.
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.
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.
import agentopsfrom taskweaver.app.app import TaskWeaverAppfrom agentops.partners.taskweaver_event_handler import TaskWeaverEventHandleragentops.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")