Skip to main content

tantra logo

tantra

The agent turn loop as a library. Install name tantra-harness, import name tantra.

What it is

  • The harness owns the loop — sampling, tool dispatch, permissions, approval/suspend-resume, subagents, compaction, persistence. You supply an Agent (a declarative class of values and function references) and run turns against it.
  • Tools, hooks and skills plug in. An Agent declares tools; a Harness takes hooks and a Skills source.
  • Agents hold no live I/O. A resume can run in another process and look the agent up by name from the persisted session header.
  • Configuration is explicit construction: tools are built by factories (web_search(api_key=...)) in your own module, so keys are per-agent and a misconfiguration fails at construction, not mid-turn. The library never reads the environment.
  • Shipped tools live under tantra.extratools.* and their dependencies are extras, so the base install stays light — pydantic, httpx, openai only. The shell tools are stdlib and need no extra.

Install

Command Adds
pip install tantra-harness core + tantra.extratools.shell (bash, ShellGuard)
pip install "tantra-harness[web]" web_search (Brave) + web_fetch
pip install "tantra-harness[doc]" read_doc for PDF / docx
pip install "tantra-harness[postgres]" the psycopg driver that PostgresStore needs at use time; the class itself imports without it
pip install "tantra-harness[web,doc]" combine freely

Import-name collision. The unrelated PyPI project tantra also installs an import tantra. Installing both into one environment clobbers the import silently. Do not co-install them.

Basic usage

import asyncio

from tantra import Agent, Harness, OpenAICompatible, SQLiteStore
from tantra.extratools.doc import read_doc
from tantra.extratools.shell import ShellGuard, bash
from tantra.extratools.web import web_fetch, web_search
from tantra.providers.base import TextDelta


class Researcher(Agent):
    model = "gpt-5"
    prompt = "You answer questions using the web, local documents and the shell."
    tools = [bash(), web_search(api_key=BRAVE_API_KEY), web_fetch(), read_doc()]
    permissions = {"bash": "allow"}


async def main() -> None:
    store = SQLiteStore("sessions.db")
    await store.setup()
    harness = Harness(
        OpenAICompatible("https://api.openai.com/v1", OPENAI_API_KEY),
        store,
        [Researcher],
        hooks=[ShellGuard()],
    )
    session = await harness.create_session(Researcher)
    async for emitted in harness.run(session.id, "What changed in Python 3.13?"):
        if isinstance(emitted.event, TextDelta):
            print(emitted.event.text, end="", flush=True)


asyncio.run(main())

Notes on the snippet:

  • harness.run(...) is an async iterator of Emitted. The turn only advances while the stream is consumed; tantra.collect drains it into a list.
  • bash declares permission="ask", so a headless run must override it — hence permissions = {"bash": "allow"}. Globs work ("web_*": "allow").
  • ShellGuard() denies destructive commands with a reason the model sees. ShellGuard(on_trip="ask") escalates to the human approval flow instead. It is a guardrail, not a sandbox.

Docs

Reference apps

  • apps/sarthi in apps/sarathi — a fully usable Perplexity clone with multi tanancy, memoery, parallel agents, web search built in
  • apps/agni in apps/agni — a terminal coding agent built on this library: REPL, permission prompts, skills, memory, compaction.

License

Apache-2.0

Metadata

Release files for tantra-harness 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tantra-harness 0.3.0
File Size Uploaded
tantra_harness-0.3.0.tar.gz 159.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tantra-harness 0.3.0
File Interpreter ABI Platform
tantra_harness-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 237.1 kB

Release files / tantra_harness-0.3.0.tar.gz

Download URL tantra_harness-0.3.0.tar.gz
Size 159.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8653f7f4bff0156508ce8fb57b1ca37f621faff758ce783936382bda5c04cc7c
BLAKE2b-256 checksum
How to use checksums
6533d8f155a00a07acac993f2353f53b3baef6a95c41302393e955e437dba5f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / tantra_harness-0.3.0-py3-none-any.whl

Download URL tantra_harness-0.3.0-py3-none-any.whl
Size 77.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42bbbeadf252a5029c4ec33240ef95ba59314eeddf0c232f92c7aee67b536d44
BLAKE2b-256 checksum
How to use checksums
b3c3cec49d596feded57499915654459963973e968ed5e499852d57b266284f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page