Skip to main content

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 PostgresStore needs to run (it imports without the extra)
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 app

apps/agni in https://github.com/malayh/tantra — 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.1.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.1.0
File Size Uploaded
tantra_harness-0.1.0.tar.gz 152.0 kB Details

Built distribution (wheel)

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

Total release size: 225.2 kB

Release files / tantra_harness-0.1.0.tar.gz

Download URL tantra_harness-0.1.0.tar.gz
Size 152.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cbb5b0eb19e53a4991c0e04bf6220a266d20e5661d0d68056d5703d99e49ea6d
BLAKE2b-256 checksum
How to use checksums
8b885205230954ed3d7e52bc03ef85d12dfee1f3fe759f0ce7005245cfe018b5
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 9, 2026.

Transparency log

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

Download URL tantra_harness-0.1.0-py3-none-any.whl
Size 73.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2c6d493fa54a002c464f48a49d240742ef3471412cd922b068721016b3f498d
BLAKE2b-256 checksum
How to use checksums
b5cd76c30dab945211ca434d485fd5f72f4dac553cdb6940995dfc02218dc4cd
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 9, 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

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

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