Skip to main content

LLM-powered parallel multi-task execution via DAG-based planning — bring your own LLM.

Project description

LangTask

LLM-powered parallel multi-task execution — bring your own LLM.

LangTask takes a natural language request, uses an LLM to decompose it into a dependency-aware task graph (DAG), executes independent tasks in parallel using a Rust-backed scheduler, then synthesises the results into a final answer. Works with OpenAI, Anthropic, Google, Mistral, Cohere, Ollama, or any LangChain-compatible LLM.

User request ──► Planner (LLM) ──► DAG (rustworkx)
                                         │
                        ┌────────────────┼────────────────┐
                    Wave 1           Wave 2           Wave N
                  [t1][t2][t3]      [t4][t5]          [t6]   ← parallel
                        └────────────────┼────────────────┘
                                         │
                                  Aggregator (LLM) ──► Final answer

Installation

# Core only (runs with MockLLM for demos):
pip install langtask

# With your chosen LLM provider:
pip install langtask[openai]       # OpenAI / Azure
pip install langtask[anthropic]    # Anthropic Claude
pip install langtask[google]       # Google Gemini
pip install langtask[mistral]      # Mistral
pip install langtask[ollama]       # Ollama (local models)

# Everything:
pip install langtask[all]

Quick Start

from langtask import build_and_run

# No API key needed — uses MockLLM for demo:
state = build_and_run(
    "Give me a full analytics report: total users, Q3 revenue, and churn vs benchmarks.",
    show_telemetry=True,   # optional: print timing + token usage
)
print(state.final_response)

With a real LLM

# OpenAI
from langchain_openai import ChatOpenAI
from langtask import build_and_run

state = build_and_run(
    "Research the latest AI papers and compare with competitor products.",
    llm=ChatOpenAI(model="gpt-4o", temperature=0),
    show_telemetry=True,
)

# Anthropic
from langchain_anthropic import ChatAnthropic

state = build_and_run(
    "Analyse our Q3 revenue, active users, and churn rate.",
    llm=ChatAnthropic(model="claude-sonnet-4-20250514", temperature=0),
    show_telemetry=True,
)

# Google Gemini
from langchain_google_genai import ChatGoogleGenerativeAI

state = build_and_run(
    "Summarise findings from three research sources.",
    llm=ChatGoogleGenerativeAI(model="gemini-1.5-pro"),
    show_telemetry=True,
)

# Ollama (local)
from langchain_ollama import ChatOllama

state = build_and_run(
    "Fetch metrics and generate a report.",
    llm=ChatOllama(model="llama3"),
)

Custom Tools

from langtask import build_and_run, register_tool, ToolResult
import requests

def my_crm_tool(inputs: dict) -> ToolResult:
    """Fetch contacts from a CRM API."""
    org_id = inputs.get("org_id", "default")
    data   = requests.get(f"https://api.mycrm.com/contacts?org={org_id}").json()
    return ToolResult(
        output={"contacts": data["total"]},
        tokens_used=0,
    )

register_tool("crm_lookup", my_crm_tool)

state = build_and_run(
    "Look up contacts for org 123 and summarise the data.",
    llm=my_llm,
    show_telemetry=True,
)

The planner LLM will automatically know about crm_lookup because registered tools are passed in the system prompt.


Telemetry Output

When show_telemetry=True, LangTask prints:

────────────────────────────────────────────────────────
  TELEMETRY REPORT
────────────────────────────────────────────────────────
  Total time         :      312 ms
  ├─ Planner         :       48 ms
  ├─ Tool waves      :      238 ms
  │   Wave 1         :      103 ms
  │   Wave 2         :       81 ms
  │   Wave 3         :       54 ms
  └─ Aggregator      :       26 ms
  Total tokens       :      1,490
  ├─ Planner tokens  :        730
  ├─ Tool tokens     :         17
  └─ Aggregator toks :        760
  LLM calls          :          2
  Tool calls         :          7
  Cache hits         :          0
  Execution waves    :          3
────────────────────────────────────────────────────────

Telemetry is also available programmatically:

state = build_and_run("...", show_telemetry=False)
tel   = state.telemetry

print(tel.total_tokens)        # int
print(tel.total_elapsed_ms)    # float (ms)
print(tel.wave_elapsed_ms)     # list[float] — one entry per wave
print(tel.cache_hits)          # int
print(tel.display())           # formatted string

CLI

# Demo run:
langtask "Analyse our Q3 metrics" --telemetry

# With a provider:
langtask "Research AI trends" --provider anthropic --model claude-sonnet-4-20250514 --telemetry

# Quiet mode (only final answer):
langtask "Summarise our data" --provider openai --quiet

API Reference

build_and_run(user_request, llm=None, scenario="analytics", show_telemetry=False, verbose=True, max_workers=None) → GraphState

Parameter Type Default Description
user_request str required Natural language request
llm LangChain LLM or None None Uses MockLLM when None
scenario str "analytics" Demo scenario for MockLLM
show_telemetry bool False Print telemetry report after execution
verbose bool True Print progress logs
max_workers int | None None Thread pool size per wave (default = wave size)

register_tool(name, fn)

Register a custom tool. fn receives a dict and must return a ToolResult.

GraphState

Field Type Description
final_response str The aggregated LLM answer
tasks dict[str, Task] All tasks with results and metadata
total_tokens int Total tokens across all LLM calls
telemetry TelemetrySummary Full timing and token breakdown
errors list[str] Any task errors

Publishing to PyPI

pip install build twine
python -m build
twine upload dist/*

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langtask1-0.1.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langtask1-0.1.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file langtask1-0.1.0.tar.gz.

File metadata

  • Download URL: langtask1-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langtask1-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5d613659452ceb14b56daad83af4e5a3dd80e865213ea5f39b150888aa6a2077
MD5 2e697e87e5f15d10bd09a3f51ed4b525
BLAKE2b-256 c2c20bad16bc0831b9f08344f8e8b723b8bd96ec8483c070a8425ac3afeb22b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for langtask1-0.1.0.tar.gz:

Publisher: python-publish.yml on agentksimha/langtask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langtask1-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: langtask1-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langtask1-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd6efd36bffb7945d02dfad31d01f73cdc0cac96e524347bf6e2c9c03cbc620d
MD5 576c1a48d4436de60e51c36b94c317b9
BLAKE2b-256 eb312624e227da1879aeaf3ce492bdd39ed77d730987e4941c7e91833e63e1b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for langtask1-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on agentksimha/langtask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page