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/agni in apps/agni — a terminal coding agent built on this library: REPL, permission prompts, skills, memory, compaction.
  • apps/sarthi in apps/sarathi — a AI chat interface with pdf reader and web search built in.

License

Apache-2.0

Metadata

Release files for tantra-harness 0.2.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.2.0
File Size Uploaded
tantra_harness-0.2.0.tar.gz 158.2 kB Details

Built distribution (wheel)

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

Total release size: 235.4 kB

Release files / tantra_harness-0.2.0.tar.gz

Download URL tantra_harness-0.2.0.tar.gz
Size 158.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d9961f6544fd5e9b4a21be9248106e2d233bcbd526f61283cfbb40738447a6de
BLAKE2b-256 checksum
How to use checksums
c482987b16324c28ceacd2cac2396f2f253951b9dbecf39eabefc658d5760b6d
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 11, 2026.

Transparency log

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

Download URL tantra_harness-0.2.0-py3-none-any.whl
Size 77.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b439ee19a986ab72393560d0efeaae3101b8677929c6bb7ea7ea3a660f931ca
BLAKE2b-256 checksum
How to use checksums
1554d9e26ac1c54ea0d2777d0b482d2fb5ea60c7051d315e90d11fe0b51e4151
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 11, 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

This release

0.2.0 This release

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