TaskWeaver for Analytical AI Agents (Microsoft)
We integrate TaskWeaver agents for analytical automation. TaskWeaver is a framework from Microsoft Research. It converts plain-language task descriptions into executable Python code. The agent runs that code in a sandbox, inspects the result, and iterates. This makes TaskWeaver especially effective for data analysis, dataset operations, and numerical calculations. We deploy these agents turnkey: we connect your data sources, configure the sandbox, and calibrate the agent to your business rules. Contact us to get a demo session built for your specific use case.
Analysts often spend full days on reports that amount to a few queries and some formatting. Formulas get copied between spreadsheets. Errors accumulate. When the analyst leaves, their pipeline is lost. TaskWeaver addresses all three problems. It generates code instead of copying formulas — eliminating manual transcription errors. It preserves the full pipeline as executable code — reproducible at any time. It processes large datasets without a GUI — faster and without memory limitations of desktop tools.
Setting up TaskWeaver is straightforward. The framework connects to OpenAI, Claude, LLaMA 3, Mistral, or any OpenAI-compatible endpoint. We configure allowed Python modules based on your analytics stack. The sandbox runs in Docker with restricted permissions. Custom plugins connect the agent to your corporate databases, APIs, and file storage.
Setup and Configuration
# Install TaskWeaver from repository
git clone https://github.com/microsoft/TaskWeaver.git
cd TaskWeaver
pip install -r requirements.txt
// project/taskweaver_config.json
{
"llm.api_base": "https://api.openai.com/v1",
"llm.api_key": "sk-...",
"llm.model": "gpt-4o",
"planner.example_base_path": "${AppBaseDir}/examples",
"code_interpreter.use_local_uri": true,
"code_interpreter.allowed_modules": ["pandas", "numpy", "matplotlib", "sklearn", "scipy"]
}
Running an Analytical Session
from taskweaver.app.app import TaskWeaverApp
app = TaskWeaverApp(app_dir="./project")
session = app.get_session()
# Data analysis request
response = session.chat(
"Load sales_2024.csv and perform EDA: "
"basic statistics, distributions, anomaly detection. "
"Create visualizations of key patterns."
)
# TaskWeaver will:
# 1. Generate pandas/matplotlib code
# 2. Execute it
# 3. Return results and charts
print(response.post_list[-1].get_artifact()) # Artifacts (images, data)
print(response.post_list[-1].get_text()) # Text outputs
Custom Plugins for Corporate Data Sources
# project/plugins/db_query.py
from taskweaver.plugin import Plugin, register_plugin
import pandas as pd
@register_plugin
class DatabaseQueryPlugin(Plugin):
"""Plugin for corporate database queries"""
def execute(self, query: str, database: str = "analytics") -> pd.DataFrame:
"""
Runs a SQL query against corporate databases.
Args:
query (str): SQL query string
database (str): Target database (analytics, sales, hr)
Returns:
pd.DataFrame: Query result
"""
conn = get_db_connection(database)
return pd.read_sql(query, conn)
# project/plugins/db_query.yaml
name: db_query
enabled: true
required: false
description: Execute SQL queries against corporate databases
examples:
- "db_query('SELECT * FROM monthly_sales WHERE year=2024', 'sales')"
Multi-Step Analysis with Session Memory
# TaskWeaver supports multi-step analytical tasks with persistent session memory
# Step 1: Load and clean data
session.chat(
"Load sales data from the database for the past year. "
"Remove duplicates, fill missing values, normalize date formats."
)
# Step 2: Trend analysis — agent retains context from step 1
session.chat(
"On the cleaned data, run seasonality analysis: "
"time series decomposition using STL."
)
# Step 3: Forecast
session.chat(
"Build a forecast for next quarter using Prophet. "
"Evaluate accuracy on the last 3 months with backtesting."
)
# Step 4: Report
result = session.chat(
"Generate a markdown report with key findings, "
"embedded charts, and a forecast table."
)
Case Study from Our Practice: Financial Report Automation
Our client, a fintech company, had a financial analyst spending two full days each month preparing one report. The task involved loading data from three sources, calculating 15 KPIs, building 8 charts, and identifying anomalies. The work was done manually in Excel and repeated from scratch every month.
We implemented a TaskWeaver agent that handles the full cycle autonomously:
- Queries to PostgreSQL for revenue and cost data
- Loading Excel files for budget data
- KPI calculations via pandas
- Chart generation using matplotlib and plotly
- Generating a markdown report with written conclusions
Results after deployment:
| Metric | Before | After |
|---|---|---|
| Report preparation time | 2 days | 25 minutes |
| Calculation errors | 2-3 per quarter | 0 |
| Analyst hours per month | 40 hours | 5 hours |
The analyst shifted from data preparation to interpretation and decision-making.
Why TaskWeaver Is Better Than Code Interpreter
Standard code interpreter sessions break context on each run. TaskWeaver preserves session state across steps. You can run step 1, review the intermediate result, then instruct the agent to repeat only for region A. This gives far more control over multi-step analytical workflows.
LLM Model Selection
TaskWeaver supports any OpenAI-compatible model: GPT-4o, Claude, LLaMA 3, Mistral. We use GPT-4o by default for its high code generation accuracy. For latency-sensitive tasks, Mistral is faster. Models are swappable in the config without reinstalling the framework.
Implementation Process
- Audit of data sources and business logic. We identify required plugins, allowed modules, and run frequency.
- Agent design. We select the LLM, configure the sandbox, write custom plugins.
- Development and testing on real data. Three to ten iterations.
- Production deployment. Docker container, scheduler (cron or Airflow), monitoring.
- Team training. Two workshops and written documentation.
Project Timelines
- Basic setup and first analytical tasks: 2-3 days
- Custom plugins for corporate data sources: in 1 week
- Sandbox hardening and secure code execution: 3-5 days
- Production integration with a scheduler: in 1 week
The full cycle including plugins, tests, and deployment: 1-2 weeks. Estimate your project — contact us and we will send a demo session built on your data within two business days.







